DEV Community

Full Stack Tutorials
Full Stack Tutorials

Posted on • Edited on

Core Java Interview Questions

Q:- What is Java?

  1. Java is a general-purpose, high level, object-oriented programming language, and java is also platform independent.
  2. Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995.

Q:- What is the most important features of Java?

1. Simple

Java is very popular general-purpose programming language.

2. Object-Oriented

  1. Java is a pure Object oriented
  2. Every thing in java is object
  3. All programs and data reside inside objects and classes

3. Distributed

  1. Java facilitates it's users to create distributed applications in Java
  2. RMI and EJB are used for creating distributed applications

4. Robust

Java gives importance to memory management by using the technique called Garbage Collection and Exception handling etc.

5. Secure

Java is secure becasue of

  1. Byte code concept
  2. Java is secured because it doesn't use explicit pointers
  3. Exception handling concept
  4. Garbage collection mechanism
  5. Type-safe reference casting in JVM

6. Platform Independent

Java compiler generates a platform-independent code called bytecode.

7. Portable

The Bytecode generated by java can be used on any machine. So it can be portable.

8. Compiled and Interpreted

Generally, computer languages are either compiled or interpreted. but java combines both compilers and interpreters.

9. Performance

The use of a bytecode makes the performance high. the speed is also high with comparing c, c++.

10. Multi-Threading

Multithreading means handling more than one job at a time. Java supports Multithreading.

Q:- How to write very first simple program in Java?

/* This is a very first simple Java program.
   FileName : "FirstProgram.java". 
*/

public class FirstProgram
{
    // Your program begins with a call to main().
    // Prints "Java Interview Questions" to the terminal window.
    
    public static void main(String args[])
    {
        System.out.println("Core Java Interview Questions and Answers for Experienced");
    }
}

//Output: Core Java Interview Questions and Answers for Experienced

Q:- Print "Java Interview Questions" even before main() is executed. How will you achieve that?

You can print the message inside the static block. It will execute when the class gets loaded into the memory and even before the creation of an object.

Hence it will be executed before the main()method. And it will be executed only once.

public class PrintMessage {
    static {
        System.out.println("Core Java Interview Questions");
        System.exit(0);
    } 
}

//Note - 
//1. The System.exit(0) exits the program before the JVM starts to look for main()
//2. This will not work with JDK7 - Because, In JDK7 the code would not execute 
     as it looks for the main method before any other thing.

//Output: Core Java Interview Questions

Q:- What is a Java package and how is it used?

A java package encapsulates a group of similar types of classes, interfaces, and sub-packages.

Use of Packages:

A Package is used to create a separate namespace for groups of classes and interfaces.
A Package are also used to manage and control related classes and interfaces into a single API unit.

Type of Package:

  1. Built-in package: javax, lang, awt, swing, io, util, sql, etc
  2. User-defined package

Q:-Which package is imported by default?

java.lang package

Q:- What is the base class of all classes?

java.lang.Object

Read the complete Article - Core Java Interview Questions and Answers for Experienced

Top comments (0)