how to write java first program following steps help you write java first program and run,If you are interested in learning coding, then Java is a great coding language to start with. It is widely used in every field. This language is also very good for learning new things and is used in many big companies. Also, this language will help you understand how to solve common problems and what to learn next.
1) Install Java Development Kit (JDK) :
To write and run Java programs, you need the JDK (Java Development Kit).
Choose a distribution: Oracle JDK or OpenJDK (Temurin/Adoptium) are popular. You can use any of the latest versions now.
Download both and install them on your system.
Install: Open a command prompt and run the following command in it:
java -version
javac -version
You will see the information about the installed version of your Java version. If you get “not recognized” errors, add the JDK bin folder to your system PATH and try again.
3) Understand the smallest Java program :
Create a folder for your code, e.g., java-first-steps/. Inside that, create a file named HelloWorld.java (the file name should match the public class name).
Create your own separate subfolders to write your own code. For example: Java programs Create a separate first program file named first.java The file name should be the name of the Java program’s class.
EX : 👉
What does each part mean :
public class HelloWorld — Defines a class named HelloWorld. In Java, all code lives inside classes.
public class first – This represents the class name of this program.
public static void main(String[] args) — Entry point. When you run a Java program, the JVM looks for this exact method signature.
public static void main (String [] args ) This is written in the initial default program, this code is converted to bytecode in the JVM
System.out.println(…) — Prints a newline to the console.
4) Compile and run from the command line :
From the folder containing first.java, run:
First compiles java to first.class (bytecode)
First run the compiled program
You should see this:
Hello, Java!
If it works, congratulations—you just coded and ran your first Java program!
5) Run the code using the IDE:
VS Code: Open the folder → open first.java → click “Run” above the main method.
IntelliJ IDEA: New Project → “Java” → Add a new class HelloWorld → Paste the code → Click the green run triangle.
IDEs handle compilation behind the scenes and display the output in the console panel.
6) Make a small change (learn by doing) :
Change the print line:
System.out.println(“Hello, ” + “World!”.toUpperCase());
Run again to see how Java appends strings and calls methods like toUpperCase().
Compile and run:
javac Greet.java
java Greet
You’ve now used a standard library class (Scanner) to read input!
7 ) Common errors and how to fix them :
If ‘javac’ cannot find your program or you get path errors: The JDK is not properly configured (i.e., it is not installed properly). Reinstall or correct the environment variables and restart your terminal.
The class First is public, must be in a file named First.java: The file name must match the public class name exactly (case-sensitive).
NoSuchMethodError: main: The main method must be public static void main(String[] args).
Missing semicolons or braces: Java is strict about syntax. Check the alignment of ;, {, and }.
Running in the wrong folder: Make sure you are in the same folder as your .java file when compiling/running (unless you are using packages).

