wiki:ControlSystems/SoftwareTeam/Training/GettingStarted/HelloWorld

Version 2 (modified by David Albert, 6 years ago) (diff)

--

Java is a programming language. It consists of a small, concise set of words that let you describe to the computer exactly what you want it to do. A Java program consists of one or more files. We use a Microsoft program called VSCode to write and run Java programs. Each program must have its own folder. To write your first Java program, you need to create a new folder for it. First create a folder to hold all of your Java projects in your Documents folder named Java Projects. Then in the Java Projects folder, create another new folder named Hello World that will hold your first program.

In VSCode:

  1. Select File->Open Folder and choose the JavaProjects\Hello World folder you just created.
  2. Select File->New which will open the editor for you to enter a new program
  3. Cut and paste the following program into the editor:
    public class Hello {
        public static void main(String args[]) {
            System.out.println("Hello world");
        }
    }
    
  4. Select File->Save and name the file Hello.java the name is important; it must be Hello.java with a capital H (case matters to Java). The name of the file must be the same as the name of the class (more on classes later)
  5. In the left navigation window, you'll now see Hello.java with a red J icon next to it; right click on the Hello.java and select Run
  6. A terminal window will open, the program will be compiled and then run; you'll see the output: Hello world!

Attachments (2)

Download all attachments as: .zip