Getting Started with Java

Java is one of the most widely used programming languages in the world, known for its platform independence and robust features. In this tutorial, we’ll guide you through the process of installing Java on your computer.

Step 1: Download Java

To start, download the Java Development Kit (JDK) from the official Oracle website:

  1. Visit the Java SE Downloads page.
  2. Select the latest version of the JDK.
  3. Choose the installer that matches your operating system (Windows, macOS, or Linux).

Step 2: Install Java

Follow the steps below to install the JDK:

  • Windows:
    1. Run the downloaded installer.
    2. Follow the setup wizard and accept the license agreement.
    3. Choose an installation folder or use the default path.
    4. Complete the installation.
  • macOS:
    1. Run the .dmg file and follow the on-screen instructions.
    2. Move the JDK to your Applications folder.
  • Linux:
    1. Use your package manager (e.g., sudo apt install openjdk-17-jdk on Ubuntu).
    2. Alternatively, download the tarball and extract it to your desired directory.

Step 3: Verify the Installation

To ensure Java is installed correctly, open your terminal or command prompt and type:

java -version

You should see output showing the installed version of Java.

Step 4: Set Up Environment Variables (Optional)

If you want to run Java from any directory, you may need to set the JAVA_HOME environment variable:

  • Windows:
    1. Search for Environment Variables in the Start menu.
    2. Under System Variables, click New and set JAVA_HOME to the JDK installation path.
    3. Add %JAVA_HOME%\bin to the Path variable.
  • macOS/Linux:
    1. Edit your shell configuration file (e.g., .bashrc or .zshrc).
    2. Add the following lines:
      export JAVA_HOME=/path/to/jdk
          export PATH=$JAVA_HOME/bin:$PATH
    3. Save and reload your shell configuration with source ~/.bashrc.

Step 5: Write Your First Java Program

Create a file named HelloWorld.java with the following code:

public class HelloWorld {
        public static void main(String[] args) {
            System.out.println("Hello, World!");
        }
    }

Step 6: Compile and Run Your Program

Use the following commands to compile and run your program:

javac HelloWorld.java
    java HelloWorld

Output:

Hello, World!

Next Steps

Now that Java is installed, explore its features by writing and running more programs. Understanding Java is key to building robust, cross-platform applications. Happy coding! Now you can learn about variables!