Showing posts with label Questions. Show all posts
Showing posts with label Questions. Show all posts

06 August 2017

Basic Core Java Interview Questions


How Java is platform Independent Language?

Java code will be converted to byte code by Java compiler and it will be interpreted by JVM.
So JVM (Java virtual machine) makes Java, platform independent.
JVM converts the byte code to platform specific machine code.

This happens in 3 steps

1.ClassLoader is used to load the classes into main memory.

2.ByteCode Verifier is used to check the byte code validity.

3.JIT(Just in Time) compiler to convert the byte code to machine code of JVM installed machine.

Why Java?

Java is the object oriented programming language.

It is the open source software,which has wide range of editors available in market.It has support or multi threading and garbage collection.

Java is platform independent and supports to build web based,stand alone,distributed applications.

What are the advantages of Object oriented programming language?

OOP always deals with Objects,which represent the attributes and functions of real-time object(entity)
OOP language has the following powerful and useful features

1.Inheritance: Reusing the code

2.Polymorphism: Parent class reference is used to refer to a child class object

3.Encapsulation: Holding attributes and methods together.

What is NullPointerException. How to handle it?

Nullpointer exception is a runtime exception.It Occurs

1.When a method is called on null reference,null pointer exception will be thrown.

    Example:  
     Object a =null;
     a.hashCode() will give NPE.
     when Object A is declared,a reference will be created and it points to nothing(null).
     when we try to dereference the object with (.),it will throw null pointer exception.

2.   When a primitive is assigned to null
      int a = null;

     How to handle and fix:
     It is always recommended to check for null object unless that object can never be null.
     Stack trace will provide the class name with line number to fix the null pointer exception.
     How to prevent: Proper unit tests can avoid the occurrence of NPEs