1.2. Create your First Java Program


  • Write Your Java Program
    1. Open Notepad (or any text editor like VS Code or Notepad++).
    2. Type the following Java code:

class MyFirstProgram {
    public static void main(String args[]) {
        System.out.println("Hello, Java!");
    }
}
    
  • class MyFirstProgram {} → This defines a class named MyFirstProgram.
  • 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
    1. Click File > Save As.
    2. In the JavaProjects folder, change “Save as type” to All Files.
    3. Name the file MyFirstProgram.java (Make sure the filename matches the class name!)
    4. Click Save.

What is the correct file name for the following Java code?

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

Pages: 1 2 3