Q) Access
Specifiers & Access modifiers?
Access Specifiers à
A.S gives access privileges to outside of application
(or) others, they are Public, Protected, Private, Defaults. Access Modifiers à A.M which gives additional meaning to
data, methods and classes, final cannot be modified at any point of time.
|
Private
|
Public
|
Protected
|
No modifier
|
Same class
|
No
|
Yes
|
Yes
|
Yes
|
Same package Subclass
|
No
|
Yes
|
Yes
|
Yes
|
Same package non-subclass
|
No
|
Yes
|
Yes
|
Yes
|
Different package subclass
|
No
|
Yes
|
Yes
|
No
|
Different package non-subclass
|
No
|
Yes
|
No
|
No
|
Q) Default Values
long
|
-2^63 to 2^63 –1 à
0L
|
double
|
0.0d
|
Int
|
-2^31 to 2^31 –1 à
0
|
float
|
0.0f
|
Short
|
-2^15 to 2^15 –1 à
0
|
Boolean
|
false
|
Byte
|
-2^7 to 2^7 –1 à 0
|
char
|
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 into byte 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 the performance 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 passed to 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 “Private”?
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 Main
method only in the class whose name you have mentioned. Hence there is not
conflict amongst the multiple classes having main method.
No comments:
Post a Comment