Sponsored Links

Ad by Google
In this post, We are going to list down few very basic core java interview questions. The answer of these questions are designed for fresher level only, so we are not going to dig into the deep of the answers. But yes questions are not only for fresher, even though question are listed here can also asked in experience level.

1. What is difference between Java and C++
Here we have listed only few differences.
  1. Java does not support pointers whereas C++ Support pointers.
  2. Java does not support destructors, it has automatic garbage collector, whereas C++ supports destructors.
  3. Java codes run in a JVM(Java Vertual Machine) whereas C++ codes runs on native executable machine.
  4. Java does not support operator overloading whereas C++ does.
  5. Java provides built in support for Thread whereas C++ does not provide built in support for Thread.
2. What is the difference between JDK and JRE
  1. JDK(Java Development Kit) includes the JRE, Compilers, JavaDoc, Java Debugger etc. The JDK is required to create and compile java programs if you want to develop java programs/applications than you need JDK to be installed in your machine.
  2. JRE(Java Runtime Environment) includes libraries, Java Virtual Machine and other components to run Java programs/application and applets. If your concern is just to run java application then you don't need to installed JDK you just need to install JRE only.
3. What is class in Java
A class is the blueprint from which individual objects are created, for example You have a blueprint(architecture) for making a two story dream house and that blueprint can also be used by your friends to make their dream house also.

4. Can you write down the syntax of simple Java program? or How to write a Hello World Program in Java?
Here is a simple HelloWorld.java program.
public class HelloWorld {

    public static void main(String...args) {
        System.out.println("Hello World !!!");

5. What are the access modifiers in Java can you list down?
There are four numbers of access specifiers in Java.
  1. default (no specifier)
  2. private
  3. protected
  4. public
6. What is difference between public, protected and private?
  1. public access modifier, mean that class is visible to all classes everywhere. Top level of accessibility is provided by using public modifier.
  2. If a member is declared with protected modifier, mean that class can be accessed within its own package and, in addition, by subclass of its class in another package.
  3. If a member is declared with private modifier, mean that member can only be accessed in its own class.
7. What happens, If main() method is declared as private?
The class will compile successfully and at runtime it will gives a message as main method is not public. If you are using IDE most of the IDE will not allows to run without main method so in IDE you can't see the message.

8. What happens, If we remove static modifier from the signature of the main() method?
The class will compile successfully and at runtime it will gives an error as NoSuchMethodError.

9. How to create Object in Java?
Syntax to create object in java
HelloWorld hello = new HelloWorld();
You can read more from here How many ways to create object in java

10. Which class is known as parent class of all the classes in Java
Object class is known as parent of all the classes in java, available in java.lang package.
Sponsored Links


Post a Comment