Getting Started with Java
💻 JavaInstall a JDK, compile your first class and understand how Java runs.
Java source is compiled to bytecode, which runs on the Java Virtual Machine. That is why the same program runs on Windows, macOS and Linux.
- Explain the JDK, JVM and bytecode.
- Compile and run a class.
- Read a simple Java program.
Install a JDK
Install a Java Development Kit such as Temurin or Oracle JDK. The JDK includes the compiler javac and the runtime java.
javac -version
java -versionYour First Program
The file name must match the public class name. Every Java program starts from main.
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}Compile and Run
Compile to a .class file, then run the class name without the extension.
javac Hello.java
java HelloPractice
- Print your name and school on separate lines.
- Explain the difference between javac and java.
- Compile and run a program from the command line.
Hands-on exercise
Write a class called AboutMe that prints:
1. Your name.
2. Your favourite subject.
3. One sentence about why you are learning Java.
Compile and run it.
Recap
Java compiles to bytecode, the JVM runs it and main is the entry point.
Example
javac -version
java -version
Exercises
1. Your name.
2. Your favourite subject.
3. One sentence about why you are learning Java.
Compile and run it.
Expected Output
Three lines printed in order.
Lesson Nav
Java Course
0/9 lessons completed
- 1 Getting Started with Java Tutorial
- 2 Variables and Data Types Tutorial
- 3 Conditions and Loops Tutorial
- 4 Methods and Parameters Tutorial
- 5 Arrays and ArrayLists Tutorial
- 6 Classes and Objects Tutorial
- 7 Inheritance, Interfaces and Polymorphism Tutorial
- 8 Exceptions and Files Tutorial
- 9 Project: A Console Grade Book Project