Step 1: Writing the Java Program
- Create a Folder for Your Java Programs
- Open File Explorer.
- Go to a location like Documents or Desktop.
- Right-click → Select New > Folder.
- Name it JavaProjects (or any name you like).
- Write Your Java Program
- Open Notepad (or any text editor like VS Code or Notepad++).
- Type the following Java code:
class MyFirstProgram {
public static void main(String args[]) {
System.out.println("Hello, Java!");
}
}
What’s happening in the code?
class MyFirstProgram {}
→ This defines a class namedMyFirstProgram
.public static void main(String args[]) {}
→ This is the starting point of every Java program. (Don’t worry about the details yet we will learn in future lessons)System.out.println("Hello, Java!");
→ This prints the text “Hello, Java!” on the screen. (We will talk about print statements in the next slide)
- Save the File in Your Folder
- Click File > Save As.
- In the JavaProjects folder, change “Save as type” to All Files.
- Name the file MyFirstProgram.java (Make sure the filename matches the class name!)
- Click Save.
The name of the file must be the same as the class name (MyFirstProgram
) inside the code. If the names don’t match, Java will give an error.
What is the correct file name for the following Java code?
class MyFirstProgram {
public static void main(String args[]) {
System.out.println("Hello, Java!");
}
}