In this section we will learn how to write and execute a simple Java program.
To write a Java program you can use any text editor like Notepad, Notepad++ (Windows) or gedit (Linux).
You can also use popular IDEs such as BlueJ, NetBeans, or Eclipse to write and execute Java programs.
To compile your Java source code, you need a Java Compiler, and to run it, you need a Java Interpreter. Both are included in the JDK. Ensure JDK is installed and configured in your system.
Write your program using a text editor and save it with the extension .java.
Example: HelloWorld.java
Use the command:
javac HelloWorld.java
After successful compilation, a HelloWorld.class file (bytecode) will be generated.
Run the program using:
java HelloWorld
Note: Do not include .class in the execution command.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
.java extension.
package declaration;
import statements;
class ClassName {
// class members
}
HelloWorld.class
Topic: Writing_executing_java | Language: Java