DEV Community

Ayush Shrivastava for Mastering Backend

Posted on Edited on Originally published at masteringbackend.com

Setting Up a Development Environment for Java: A Beginner's Guide

Java is one of the most popular programming languages in the world. Whether you're a student, a professional, or someone stepping into the world of programming, setting up the right development environment is the first step. Here’s a step-by-step guide to help you get started with Java development.

Step 1: Install the Java Development Kit (JDK)

The Java Development Kit (JDK) contains everything you need to write, compile, and run Java programs.

Steps to Install JDK:

  1. Download the JDK
    • Go to the official Oracle Java Downloads page. Alternatively, you can use OpenJDK (an open-source version of JDK).
    • Choose the latest version of JDK for your operating system (Windows, macOS, or Linux).
  2. Install the JDK
    • Run the downloaded installer.
    • Follow the instructions on the screen to complete the installation.
  3. Set the Environment Variable

    • On Windows:
      • Search for Environment Variables in the Start menu.
      • Under “System Variables,” find Path and add the bin folder of the JDK installation (e.g., C:\Program Files\Java\jdk-XX\bin).
    • On macOS/Linux:

      • Open the terminal and edit the .bashrc, .zshrc, or .bash_profile file, adding the following:

        export JAVA_HOME=/path/to/jdk
        export PATH=$JAVA_HOME/bin:$PATH
        
- Restart your terminal or system to apply the changes.
Enter fullscreen mode Exit fullscreen mode
  1. Verify Installation

    • Open your terminal or command prompt and type:

      java -version
      
  • If Java is installed correctly, you’ll see the version number displayed.

Step 2: Install an Integrated Development Environment (IDE)

An IDE makes writing, debugging, and managing Java projects much easier.

Popular IDEs for Java:

  • Eclipse: Free, beginner-friendly, and highly customizable.
  • IntelliJ IDEA: A powerful IDE with a free Community edition and a paid Ultimate edition.
  • NetBeans: Another free IDE, good for developing Java applications.

Installing an IDE:

  1. Download the IDE from its official website. For example:
  2. Run the installer and follow the setup instructions.
  3. Launch the IDE and configure it for Java development (most IDEs will automatically detect the JDK installed on your system).

Step 3: Write and Run Your First Java Program

Let’s create a simple Java program to test your setup.

Using an IDE:

  1. Open your IDE and create a new Java Project.
  2. Create a new Java Class file (e.g., HelloAyush).
  3. Write the following code:

    public class HelloAyush {
        public static void main(String[] args) {
            System.out.println("Hello, Ayush!");
        }
    }
    
  4. Click Run or Execute in the IDE toolbar. You should see Hello, Ayush! printed on the console.

How to Install IntelliJ IDEA

IntelliJ IDEA is a powerful and user-friendly IDE widely used for Java development. It offers a free Community edition and a paid Ultimate edition.

Steps to Install IntelliJ IDEA:

  1. Download IntelliJ IDEA
    • Visit the official website: IntelliJ IDEA Downloads.
    • Choose the Community edition (free) or the Ultimate edition (paid).
  2. Install IntelliJ IDEA
    • Run the downloaded installer.
    • Follow the on-screen instructions to complete the installation.
  3. Configure IntelliJ IDEA
    • Launch IntelliJ IDEA and choose the default settings during the initial setup.
    • Ensure that the IDE detects the JDK installed on your system. If not, manually add the JDK path under File > Project Structure > SDKs.
  4. Install Plugins (Optional)
    • IntelliJ IDEA supports various plugins to enhance your productivity. You can install them via File > Settings > Plugins.

Write and Run Your First Java Program Using IntelliJ IDEA

Let’s create a simple Java program to test your setup.

Using IntelliJ IDEA:

  1. Open IntelliJ IDEA and create a new Java Project.
    • Select File > New > Project.
    • Choose Java and set the JDK.
  2. Create a new Java Class file (e.g., HelloWorld).
    • Right-click on the src folder, select New > Java Class, and name it HelloWorld.
  3. Write the following code:

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

    • Click the green Run button in the toolbar or right-click the file and select Run HelloWorld.main().
    • You should see Hello, World! printed on the console.

Conclusion

You have successfully set up your Java development environment with IntelliJ IDEA. With the JDK, IntelliJ IDEA, , you are ready to start building Java applications. Practice regularly to improve your skills and create amazing projects!

Top comments (1)

Collapse
 
kamalhinduja profile image
Kamal Hinduja •

Great information for setting up Java development environment with IntelliJ IDEA.