Getting Started
1. A Brief History of Java
- Created by Sun Microsystems (1995): Java was developed by James Gosling and his team as a versatile, platform-independent language.
- Core Principle - "Write Once, Run Anywhere": Java programs can run on any system with a Java Virtual Machine (JVM), making it highly portable.
- Ownership: Oracle acquired Sun Microsystems in 2010 and now maintains Java.
- Uses Today: Java powers Android apps, web applications, enterprise systems, IoT devices, and more.
2. Setting Up the JDK and Apache NetBeans IDE
Step 1: Install the Java Development Kit (JDK)
- Download the latest JDK from Oracle's official website.
- Run the installer and follow the prompts.
- Verify the installation:
- Open your terminal/command prompt.
- Type:
java -version
- You should see the installed Java version.
Step 2: Install Apache NetBeans IDE
- Download NetBeans from NetBeans Downloads.
- Install it and select the JDK directory during setup.
- Open NetBeans and verify the setup:
- Go to Tools > Java Platforms to ensure the JDK is linked.
3. Writing Your First Java Program in NetBeans
Step 1: Create a New Java Project
- Open NetBeans.
- Navigate to File > New Project.
- Select Java > Java Application and click Next.
- Name your project
HelloWorld
, and click Finish.
Step 2: Write Your Code
- In the
HelloWorld
project, locate theHelloWorld.java
file in the Projects tab. - Replace the existing code with:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!"); // Print a message to the console
}
}
Step 3: Run the Program
- Click the green Run Project button in the toolbar or press
Shift + F6
. - View the output in the Output Window:
Hello, World!
Common Errors to Watch For
- Missing Semicolons: Ensure every statement ends with
;
. - Mismatched Braces: Each
{
must have a corresponding}
. - Class Name Mismatch: The class name must match the file name (e.g.,
HelloWorld
).