Java Environment Setup

Setting up a Java environment is a crucial step in starting your next project, whether you're a novice or seasoned developer. This blog post will go over installation and configuration advice as well as everything else you need to know to set up your Java environment. So let's get started with Java development if you're ready to do so!

Compile and Run a Java Program

To compile and run your Java program, you have to first setup an environment for Java programming. You can set up an environment for Java without any software, just by using your computer's command prompt. But this is time taking environment. It means if you compile and run your Java program using the command prompt, this consumes your extra time for each and every Java program.

So you can easily use a Java compiler or IDE like Netbean or BlueJ to compile and run your Java program. These two Java compilers/IDEs are the most popular Java compilers/IDEs.

Let's see how to setup an environment using NetBean and BlueJ and also using the command prompt (cmd).

Java Environment Setup: BlueJ

To compile and run your Java program using BlueJ, follow the following steps:

1. Download the Java Development Kit (JDK) from the Internet and install it.

2. Now download BlueJ from the Internet and install it.

3. After installing BlueJ, open it.

4. The opened BlueJ window will look like this:

java environment setup

5. Now click on the Project menu, then New Project, which is present at the left top of the BlueJ window as shown in the following figure:

java bluej environment setup

6. Now type a project name like JavaProgram.java and click "create," or simply press enter as shown in the following figure:

compile and run java program

7. After performing this action, you will watch some changes in the BlueJ window as shown in the following figure:

bluej

8. Now click on the New Class menu and type a class name like "JavaProgram," then click the OK button as shown in the following figure:

run java program

9. After performing this action, you will again see some changes in the BlueJ window as shown in the following figure:

compile java program using bluej

10. Now press double-click on "JavaProgram" or make a right-click on "JavaProgram," and then click on "Open Editor." A new Editor window will come out that will look like this:

run java program using bluej

11. Now remove all the codes and texts that are already available in the window and start typing your own Java program, like:

public class JavaProgram
{
 public static void main(String args[])
 {
  
  System.out.println("Hello BlueJ, I am Java");
  
 }
}

as shown in the following figure:

bluej setup for java

12. Now press the "Compile" button. Now you will watch some messages at the bottom of the window, as shown in the following figure:

compile java program

13. If you will watch and there are no syntax errors, then close the window by pressing the "close" button.

14. Now you will come to the back window; if you want to run and check your Java program's output, then right-click on the class, i.e., "JavaProgram," and then click "void main(String[] args);" now a small window will come out like this:

environment setup for java

15. Now press the "OK" button to watch the output of your Java program, as shown in the following figure:

environment setup for java programming

Java Environment Setup: NetBean

To compile and run your Java program using NetBean, follow the following steps:

1. Download the Java Development Kit (JDK) from the Internet and install it.

2. Now download NetBean from the Internet and install it.

3. After installing NetBean, open it.

4. The opened NetBean window will look like this:

java netbean setup

5. Now click on the "File" menu, then "New Project," which is present at the top left of the window. A new window will come out, as shown in the following figure:

compile and run java program using netbean

6. Now click on the "Next" button, and a new window will come out as shown in the following figure:

run java program using netbean

7. Now, you can type your project name or simply leave it with its default name, like JavaApplication1, and press the "Finish" button. After pressing the "Finish" button, your project is created, and a new window (i.e., the editor window) will come out, as shown in the following figure:

netbean

8. Now you can type your Java programming code after the main() function, i.e. below the // TODO code application logic here. You can also delete all the pre-written codes and texts and write fresh code after removing unusable texts, as shown in the following figure:

java netbean

9. Now type your Java program like this:

public class JavaApplication1
{
 public static void main(String[] args)
 {
  
  System.out.println("Hello Netbean!, I am Java");
  
 }  
}

as shown in the following figure:

java program using netbean

10. After typing your Java program, you can compile it by pressing the "F9" button and run it by pressing the "F6" button, or you can compile it by clicking on the "run" menu present at the top of the Netbean window. After compiling and running the above Java programming code, you will see the output as shown in the following figure:

netbean java

Java Environment Setup: Command Prompt

Compile and Run the Hello World Java Program using Command Prompt

public class JavaProgram 
{
 public static void main(String args[])
 {

   System.out.println("Hello World");

 }
}

Let's see how to compile and run the above Java program using the command prompt. Let's explain how to save the file, compile, and then run the program using the text editor (Notepad):

Here is the output produced by the above Java program after typing the first two lines:

C : > javac JavaProgram.java
C : > java JavaProgram 
Hello World

Java Online Test


« Previous Tutorial Next Tutorial »


Liked this post? Share it!