-->

Java Basic Interview Question

Posted by Admin on
Q:-What is difference between C, C++ and Java.

Ans:- 
C:-
1. It is a structured programming language.
2. It main focus on function and procedure.
3.Its main feature are pointer and pre-processor.
4.It follows top down approach. For eg:- it mainly focus on function and then      combining them to make the complete program.


C++:-
1.It is a object oriented programming.
2.Follows an bottom to top approach.
3.Entire problem is divided as objects.
4.It is improved version of c language.
5.Main features are pointers,class.

Java:-
1.It is a object orienter programming but not 100%.
2.It is a platform independent language.
3.It will not support for pointers.
4.Main features are multi threading,interfaces.


Q:- What are the important properties of Java ? or Why Java is so important ?
Ans:-   
1.Java is very Secure language 
2.It is a platform independent language which mean it is write once and run anywhere. 
3.It is very Robust language which  mean it automatically manage garbage value and exception handling.
4.Main features are multi threading,interfaces.

Q:- Why is Java  so Secure and Platform independent language ?
Ans:-  
Answer is byte code . Java is first compiled into byte code which is                 intermediate language between machine code and source code .
This byte code can be fitted into any platform and hence can be run               anywhere we just need JVM to be implemented on that system. 
Hence translating into byte code make java secure because it is not               executable file and difficult to understand.

Java also provide firewall between network application and your                     computer so we can freely download any applet from internet . 

Q:- Explain JVM , JRE , JIT , JDK in detail .
Ans:-  
JDK (Java Development Kit) :- IT contains Java Compiler , Debugger , libraries , bundling and deployment tools. It contains all the tools that you will need to compile a program ,to develop an Applet program and then compile them it will provide the AppletViewer,all such things are the parts of JDK, so to develop the java program  you can use any Editor(notepad) but to compile them you  need to have the JDK installed in your system.


JVM (Java Virtual Machine) :- JVM is the heart of java programming language. When we run a program, JVM is responsible to converting Byte code to the machine specific code. JVM is also platform dependent and provides core java functions like memory management, garbage collection, security etc. JVM is customizable and we can use java options to customize it, for example allocating minimum and maximum memory to JVM. JVM is called virtual because it provides an interface that does not depend on the underlying operating system and machine hardware. This independence from hardware and operating system is what makes java program write-once run-anywhere. 

JRE (Java Runtime Enviroment):- Java Runtime Environment contains JVM, class libraries, and other supporting files.It does not contain any development tools such as compiler, debugger, etc.Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE.
JRE = JVM + Java Packages Classes(like util, math, lang, awt,swing etc)+runtime libraries.       
If you want to run any java program, you need to have JRE installed in the system. 
JRE is the box and JVM is the content of the box. 
In simple words JRE=JVM+ rt.jar. 
where rt.jar contains lang,util,awt swing,math etc Libraries or compiled .class files used to run our program.

JIT (Just In Time ):- JIT is the part of the Java Virtual Machine (JVM) that is used to speed up the execution time. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.
















Q:- Explain the JVM internal architecture .

Ans:- Image of JVM internal Architecture :-




JVM provides four main task:-

1)Load code 

2)Verify code 

3)Execute code 

4)Provides runtime environment .



Classloader :-Classloader is a subsystem of JVm that is used to load class file.



Method Area :- method area stores per class structure such as field of class , method of class and code for method.



Heap :- It is the runtime data in which objects are allocated. 

Stack:- Java stack stores local variable , partial result and plays a  part in method invocation and return . Each thread has a private JVM stack created at the same time as thread.

Program counter :- contain the address of the instruction currently being executed 

Native Method Stack :- It contain all the native method used in the stack .

Execution Engine :- It contain :-
1)Virtual processor 
2)Interpreter:- Read byte code stream then execute the instruction.
3)JIT compiler   

Q:-What is a platform and difference between Java platform and other ?
Ans:-A platform is basically a hardware or software environment in which a program runs. There are two types of platforms software based and hardware based. Java provides software based platform .
Java platforms differ from most of the other platform in the sense that it’s a software based platform that run on the top of other hardware based platforms. It has two component :-
1.Runtime Enviroment.
2.API(application programming interface ).

Q:-What is Unicode System. ?
Ans:-Unciode is universal international standard character encoding that is capable of representing most of the world written languages.

Q:- Explain what happen at compile time and run time in java .

What happen at compile time :-
At compile time java file is compiled by java compiler (It does not interact with OS ) and convert the Java code into Byte code .

What happen at the run time:-
Class loader :- is the subsystem of java that is used to load the class .
Byte code verifier :-checks the code fragment for the illegal code that can violate access right to objects .
Interpreter :-read byte code stream then execute the instructions.



Q:- Is delete , next, main ,exit or null keyword in java ?
Ans  NO.

Q:- What is significance of each word in System.out.pritnln?

System is a built-in class present in java.lang package. This class has a final modifier, which means that, it cannot be inherited by other classes. It contains pre-defined methods and fields, which provides facilities like standard input, output, etc.
out is a static final field (ie, variable)in System class which is of the type PrintStream (a built-in class, contains methods to print the different data values). static fields and methods must be accessed by using the class name, so ( System.out ).
out here denotes the reference variable of the type PrintStream class.
println() is a public method in PrintStream class to print the data values. Hence to access a method in PrintStream class, we use out.println() (as non static methods and fields can only be accessed by using the refrence varialble)

Q:-What are the three different kind of stream in java.?

System.in
System.in is an InputStream which is typically connected to keyboard input of console programs. System.in is not used as often since data is commonly passed to a command line Java application via command line arguments, or configuration files. In applications with GUI the input to the application is given via the GUI. This is a separate input mechanism from Java IO.

System.out
System.out is a PrintStream. System.out normally outputs the data you write to it to the console. This is often used from console-only programs like command line tools. This is also often used to print debug statements of from a program (though it may arguably not be the best way to get debug info out of a program).

System.err
System.err is a PrintStream. System.err works like System.out except it is normally only used to output error texts. Some programs (like Eclipse) will show the output to System.err in red text, to make it more obvious that it is error text.

Q:-If I do not provide any argument on the command line then the string array of main method will be empty or null .
Ans:-It is empty . But not null.

Q:-What if I write static public void main(String args[]) instead of public static void main(String args[]) ?
Ans :-Program compiles and run properly.

Q:-What is the significance of public, static, void keywords we use before main function ?
•public :- means it is visible to all.
•Static :- means we don’t need any object to call the main function.
•Void :- return type. 

Q:- What if I write private instead of public .?
The program compiled successfully, but main class was not found.
Error:-Main class should contain method: public static void main (String[] args).

Q:- What if I don’t write String args[] in main function ?
Ans: The program compiled successfully, but main class was not found.
Error:-Main class should contain method: public static void main (String[] args).

Q:- What if I write public static int main() and return 0 in the instead of public static void main() ?
Ans:- The program compiled successfully, but main class was not found.
Error:-Main class should contain method: public static void main (String[]     args).










1 comment:

  1. Congratulations guys, quality information you have given!!!..Its really useful blog. Thanks for sharing this useful information..

    J2EE Training in Chennai

    ReplyDelete