Java first program
Create the project directory.
~
➜ mkdir java-project
~
➜ mkdir java-project
Move into the project directory.
~
➜ cd java-project
~
➜ cd java-project
Create a .java
.java
file.
~/java-project
➜ touch Program.java
~/java-project
➜ touch Program.java
Open VS Code.
~/java-project
➜ code .
~/java-project took 8s
➜
~/java-project
➜ code .
~/java-project took 8s
➜
Wright the following code:
public class Program {
public static void main(String[] args) {
System.out.println("Hello, world!")
}
}
public class Program {
public static void main(String[] args) {
System.out.println("Hello, world!")
}
}
Compile the code.
~/java-project
➜ javac Program.java
Program.java:4: error: ';' expected
System.out.println("Hello, world!")
^
1 error
~/java-project
➜ javac Program.java
Program.java:4: error: ';' expected
System.out.println("Hello, world!")
^
1 error
Add the semicolon and run again.
~/java-project took 2s
➜ javac Program.java
~/java-project took 2s
➜ javac Program.java
Start the Java application.
~/java-project
➜ java Program
Hello, world!
~/java-project
➜ java Program
Hello, world!