A.M which gives additional meaning to data, methods and classes, final cannot be modified at anypoint of time.
PrivatePublicProtectedNo modifier Same 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.0f Short-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 generator
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.