Core java interview questions and answers from first Java program

How to prepare a java environment in your machine to write a Java program In this tutorial, I will discuss steps to setup and install Java and start writing the first java program and some basic Core java interview questions and answers.

  • How to set an environment for developing java program.
  • What is JDK and how to install JDK?
  • How to set the path for javac and java.
  • How to write the first program in Java.
  • Java Interview Questions and answer from your first java program.

Core java interview questions and answers

Q) What are the Basic Requirements to write a java program.

  1. JDK (Java Development Kit).
  2. An IDE or editor to write the code.

Q) What is Java development tools(JDK).

JDK is a Kit of programs that helps to compile and run our Java code in the system. It comes according to the operating system. We can download the latest version of JDK from “Download JDK “.

Q) How to install JDK.

Download JDK from the official website of Oracle and install it in your machine. to check the installation steps please follow the below video to get a clear picture of JDK installation and verification.

Q) Where I can write Java code.

An editor like notepad, notepad++, etc. and you can use any Ide. There are lots of IDE tools available in the market like Eclipse, Netbeans, STS tools, etc.

Q) Why we need to set a path of Javac Globally.

To compile our java code we need access to a file “Javac” Which is a part of JDK and its available in the Installation directory of JDK. So to compile the java code we have two way

  1. Navigate to the installation directory of JDK and access the Javac.
  2. Set the path of Javac globally in your machine and access it from anywhere.

Q) How to set path in Java check the step by step video.

Q) How to write the first program in Java.

public class Main {
  
  public static void main(String[] args) {
    System.out.println("Hello Java");
  }

}

Core java interview questions and answers from the first Java program

Q) Can we keep a java class name as “main” or the same as the main method name.

A) No, Java is case sensitive so we can keep the class name as “Main” but it will not as “main”.

Q) Should the main class name the same as a file name?

Yes, the file name should we the same as the main class name. If a class is public than it’s necessary to save with the same name otherwise there will be a compile-time error.

If class is not public and you save the file with another name then it compiles successfully but it will give you a runtime error “Error: Could not find or load main class Main”

Q) Can we change the position of public static void main?

Yes, there is some different way to write the main method for details please watch the video.

Q) Why the main method is static.

The main method is static because according to the static properties. “we can call a method directly by name without object creation” so the main method is directly called by JVM.

Q) Can we write multiple public classes in the single file.

No. we can’t write because In a single file we can write only one public class.

Q) What is System.out.println in java.

The System is a class. Out is a  static variable in this system class. and print() is a method. The System class belongs to java.lang package

class System {
  public static final PrintStream out;
  //...
}

The Prinstream class belongs to java.io package

class PrintStream{
public void println();
//...
}

Q) What is String[] args.

It is an array of type String and its name is args. you can change its name. example String[] x.

Java oops interview questions and answers >>>>

You May Also Like These Posts:

Leave a Reply

Your email address will not be published.

seventeen − six =