Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1


Ratings: (0)|Views: 17 |Likes:
Published by Veeru Ram

More info:

Published by: Veeru Ram on Jun 18, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Core Java
Q) What is difference between Java and C++?
 A) (i) Java does not support pointers. Pointers are inherently insecure and troublesome. Since pointers do not exist inJava. (ii) Java does not support operator overloading. (iii) Java does not perform any automatic type conversions thatresult in a loss of precision (iv) All the code in a Java program is encapsulated within one or more classes. Therefore, Javadoes not have global variables or global functions. (v) Java does not support multiple inheritance. Java does not supportdestructors, but rather, add the finalize() function. (vi) Java does not have the delete operator. (vii) The << and >> are notoverloaded for I/O operations
Q) oops conceptsPolymorphism
 Ability to take more than one form, in java we achieve this using Method Overloading (compile time polymorphism),Method overriding (runtime polymorphism)
Is the process by which one object acquires the properties of another object. The advantages of inheritance are reusabilityof code and accessibility of variables and methods of the super class by subclasses.
Wrapping of data and function into a single unit called encapsulation. Ex:- all java programs.
Nothing but data hiding, like the variables declared under private of a particular class are accessed only in that class andcannot access in any other the class. Or Hiding the information from others is called as Encapsulation. Or Encapsulation isthe mechanism that binds together code and data it manipulates and keeps both safe from outside interference andmisuse.
Nothing but representing the essential futures without including background details.
Code associated with a given procedural call is not known until the time of the call at runtime. Dynamic binding is nothingbut late binding.
Q) class & object?class
class is a blue print of an object 
instance of class.
Q) Object creation?
Object is constructed either on a memory heap or on a stack.
Generally the objects are created using the new keyword. Some heap memory is allocated to thisnewly created object. This memory remains allocated throughout the life cycle of the object. When the object is nomore referred, the memory allocated to the object is eligible to be back on the heap.
During method calls, objects are created for method arguments and method variables. These objects arecreated on stack.
Q) System.out.println() 
println() is a methd of java.io.printWriter. 
“out” is an instance variable of java.lang.System class.
Q) Transient & volatile
Transient --> The transient modifier applies to variables only, the object are variable will not persist. Transient variablesare not serialized.Volatile --> value will be changed unexpectedly by the other part of the program,
"it tells the compiler a variable may change asynchronously due to threads" 
Access Specifies & Access modifiers?
 Access Specifiers
 A.S gives access privileges to outside of application
they are
Public, Protected, Private,Defaults.
Page 1
 Access Modifiers
A.M which gives additional meaning to data, methods and classes, final cannot be modified at anypoint of time.
PrivatePublicProtectedNo modifieSame class
Same package Subclass
Same package non-subclass
Different package subclass
Different package non-subclass
Q) Default Values
long-2^63 to 2^63 –1
0LDouble0.0dInt-2^31 to 2^31 –1
0Float0.0Short-2^15 to 2^15 –1
0BooleanFalseByte-2^7 to 2^7 –1
0Char 0 to 2^7 –1
null character (or) ‘\u 0000’
 Q) Byte code & JIT compiler & JVM & JRE & JDK
Byte code is a highly optimized set of instructions. JVM is an interpreter for byte code. Translating a java program intobyte code helps makes it much easier to run a program in a wide variety of environment.
JVM is an interpreter for byte code
JIT (Just In Time) is a part of JVM, it compiles byte code into executable code in real time, will increase theperformance of the interpretations.
JRE is an implementation of the Java Virtual Machine, which actually executes Java programs.
JDK is bundle of software that you can use to develop Java based software, Tools provided by JDK is(i) javac – compiler(ii) java – interpretor(iii) jdb – debugger(iv) javap - Disassembles(v) appletviewer – Applets(vi) javadoc - documentation generator(vii) javah - 'C' header file generato
Q) Wrapper classes
Primitive data types can be converted into objects by using wrapper classes. These are java.lang.package.
Q) Does Java pass method arguments by value or by reference?
Java passes all arguments by value, not by reference
Q) Arguments & Parameters
While defining method, variable passed in the method are called parameters. While using those methods, values passedto those variables are called arguments.
Q) Public static void main (String [] args)
We can overLoad the main() method.
What if the main method is declared as “
”?The program compiles properly but at runtime it will give "Main method not public." Message
What if the static modifier is removed from the signature of the main method?Program compiles. But at runtime throws an error "NoSuchMethodError".
We can write “
static public void
” instead of “
public static void
” but not “
public void static
Protected static void main(), static void main(), private static void main()
are also valid.
If I do not provide the String array as the argument to the method?Program compiles but throws a runtime error "NoSuchMethodError".
If no arguments on the command line, String array of Main method will be empty or null?
It is empty. But not null.
Variables can have the same name as a method or a class
Q) Can an application have multiple classes having main () method?
 A) Yes it is possible. While starting the application we mention the class name to be run. The JVM will look for the Mainmethod only in the class whose name you have mentioned. Hence there is not conflict amongst the multiple classeshaving main method.
Q) Can I have multiple main methods in the same class?
 A) No the program fails to compile. The compiler says that the main method is already defined in the class.
Page 2
Q) Constructor 
The automatic initialization is performed through the constructor, constructor has same name has class name.Constructor has no return type not even void. We can pass the parameters to the constructor. this() is used to invoke aconstructor of the same class. Super() is used to invoke a super class constructor. Constructor is called immediately after the object is created before the new operator completes.
can use
the access modifiers
public, protected, private
have no access modifier 
can not
use the modifiers
abstract, static, final, native, synchronized
can be
, we
cannot override
You cannot use
in the same constructor.Class A( A(){System.out.println(“hello”);}}Class B extends A {B () {System.out.println (“friend”);}}Class print {Public static void main (String args []) {B b = new B ();}o/p:- hello friend
Q) Diff Constructor & MethodConstructorMethodUse to instance of a classGrouping java statementNo return typeVoid (or) valid return typeSame name as class nameAs a name except the class method name, beginwith lower case.“This” refer to another constructor in the sameclassRefers to instance of class“Super” to invoke the super class constructorExecute an overridden method in the super classInheritancecannot be inheritedCan be inheritedWe can “overload” but we cannot “overriddenCan be inheritedWill automatically invoke when an object iscreatedMethod has called explicitlyQ) Garbage collection
 G.C is also called automatic memory management as JVM automatically removes the unused variables/objects(value is null) from the memory. User program cann't directly free the object from memory, instead it is the job of thegarbage collector to automatically free the objects that are no longer referenced by a program. Every class inherits
method from
, the finalize() method is called by garbage collector when it determines no morereferences to the object exists. In Java, it is good idea to explicitly assign
into a variable when no more in use, calling
JVM tries to recycle the unused objects, but there is no guarantee when all the objectswill garbage collected. Garbage collection is a low-priority thread.G.C is a low priority thread in java, G.C cannot be forced explicitly. JVM may do garbage collection if it is running short of memory. The call System.gc() does NOT force the garbage collection but only suggests that the JVM may make an effortto do garbage collection.
Q) How an object becomes eligible for Garbage Collection?
Page 3

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->