Java Get Started
Setting up Java development environment and writing your first program
🚀 Getting Started with Java
To start Java programming, you need to install Java Development Kit (JDK) and set up your development environment. Then you can write, compile, and run Java programs easily.
// Your first Java program
public class FirstProgram {
public static void main(String[] args) {
System.out.println("Java programming starts here!");
}
}
Output:
Java programming starts here!
Java Installation
Download JDK
Get Java Development Kit from Oracle
Install JDK
Run installer and follow instructions
Set PATH
Configure environment variables
Verify
Test installation in command prompt
🔹 Verify Java Installation
Check if Java is properly installed:
Command Prompt/Terminal Commands:
# Check Java Runtime Environment
java -version
# Check Java Compiler
javac -version
# Expected output example:
# java version "17.0.1" 2021-10-19 LTS
# javac 17.0.1
Sample Output:
java version "17.0.1" 2021-10-19 LTS
Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39)
javac 17.0.1
🔹 Choose a Code Editor
Select an editor for writing Java code:
🔸 Recommended IDEs
🔷 IntelliJ IDEA
Professional Java IDE
- Smart code completion
- Built-in debugger
- Project management
🌟 Eclipse
Free and open-source
- Extensive plugin support
- Integrated development
- Version control
💻 VS Code
Lightweight with Java extensions
- Java Extension Pack
- Syntax highlighting
- Debugging support
🔹 Write Your First Program
Create a simple "Hello World" program:
Steps:
-
Create a file named
HelloWorld.java - Write the Java code
- Compile the program
- Run the program
// File: HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
System.out.println("Welcome to Java programming!");
}
}
Output:
Hello, World!
Welcome to Java programming!
🔹 Compile and Run
Use command line to compile and execute:
# Step 1: Compile Java source code
javac HelloWorld.java
# Step 2: Run the compiled program
java HelloWorld
# Note: Don't include .class extension when running
What happens:
- javac compiles .java file to .class (bytecode)
- java command runs the bytecode on JVM
- Class name must match filename
- main() method is the entry point
🔹 Common Beginner Mistakes
Avoid these common errors:
❌ Wrong:
// Filename: hello.java (lowercase)
public class Hello { // Class name doesn't match file
public static void main(String[] args) {
system.out.println("Hello"); // Wrong case
}
}
✅ Correct:
// Filename: Hello.java (matches class name)
public class Hello {
public static void main(String[] args) {
System.out.println("Hello"); // Correct case
}
}