Friday, 22 March 2013

Core Java Interview Question - 1



Question: Is Java is a pure Object Oriented Language?
Answer: Java is a OOPS language and it is not a pure Object Based Programming Language.
Many languages are Object Oriented. There are six qualities to be satisfied for a programming language to be pure Object Oriented. They are:

1. Encapsulation/Data Hiding
2. Inheritance
3. Polymorphism
4. All predefined types are objects
5. All operations are performed by sending messages to objects
6. All user defined types are objects.

JAVA is not because it supports Primitive data type such as int, byte, long... etc, to be used, which are not objects and jvm does not treat these primitive data type as an object. We can convert primitive to object but we can also use primitive data types in our program....if java gives us restriction to write primitive data type that time we can say that java is a pure object oriented language.

Question: What do you mean by platform independence?
Answer: Platform independence means that we can write and compile the java code in one platform (e.g. Windows) and can execute the class in any other supported platform e.g. (Linux, Solaris, etc.).

Question: What is JVM?
Answer: A Java virtual machine (JVM), an implementation of the Java Virtual Machine Specification, interprets compiled 
Java binary code (called byte code) for a computer's processor (or "hardware platform") so that it can perform a Java program's instructions. Java was designed to allow application programs to be built that could be run on any platform without having to be rewritten or recompiled by the programmer for each separate platform. A Java virtual machine makes this possible because it is aware of the specific instruction lengths and other particularities of the platform.
The Java Virtual Machine Specification defines an abstract -- rather than a real -- machine or processor. The Specification specifies an instruction set, a set of 
registers, a stack, a "garbage heap," and a method area. Once a Java virtual machine has been implemented for a given platform, any Java program (which, after compilation, is called byte code) can run on that platform. A Java virtual machine can either interpret the byte code one instruction at a time (mapping it to a real processor instruction) or the byte code can be compiled further for the real processor using what is called a just-in-time compiler.

Question: What is JRE?
Answer: It is used to provide runtime environment. it is the implementation of JVM. It physically exists. It contains set of libraries plus other files that JVM uses at runtime. Implementations of JVMs are also actively released by other companies besides oracle.

Question: What is JDK?
Answer: JDK or the Java Development Kit is a set of a Java compiler, a Java interpreter, developer tools, Java API libraries, documentation which can be used by Java developers to develop Java-based applications.

Question: What is JIT Compiler?
Answer: A just-in-time (JIT) compiler is a program that turns Java 
byte code (a program that contains instructions that must be interpreted) into instructions that can be sent directly to the processor. After you've written a Java program, the source language statements are compiled by the Java compiler into byte code rather than into code that contains instructions that match a particular hardware platform's processor (for example, an Intel Pentium microprocessor or an IBM System/390 processor). The byte code is platform-independent code that can be sent to any platform and run on that platform.

Question: What gives Java its "write once and run anywhere" nature?
Answer: The byte code. Java is compiled to be a byte code which is the intermediate language between source code and machine code. This byte code is not platform specific and hence can be fed to any platform.

Question: What is the use of bin and lib in JDK?
Answer: Bin contains all tools such as javac, applet viewer, awt tool etc., whereas Lib contains all packages and variables.


1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete

Hi,

Thanks for coming here. I hope this information helps you for preparing Java Interview.

Br,
Sachin Singh