Java: Environment Setup

Installing JDK and NetBeans

Before delving into creating Java applications, it is important to first learn how to download and install JDK and NetBeans. Do note that they are both free to download.

What is JDK?

JDK is an acronym used to refer to Java Development Kit and is a free kit that Oracle provides. It comes with several tools that can help in creating Java applications. A few tools include the compiler used to compile the code devised into bytecode (javac.exe), the archiver that is used for packaging and distributing our Java files (jar.exe), as well as a documentation generator used for generating HTML documentation from our Java code (javadoc.exe).

Moreover, the Java Runtime Environment (JRE) comes in JDK as well. The JRE contains JVM that was previously mentioned, along with the resources required to run Java programs.

In case the objective is only to run Java programs, only JRE is required. However, in order to develop Java programs, JDK is also required.

Users can download JDK here: https://www.oracle.com/java/technologies/javase-jdk11-downloads.html. This page contains several download links, based on the operating system, download the compatible version. x86 and x64 are nothing but the 32-bit and 64-bit operating systems, respectively. When working with the 64-bit Windows operating system, the “Windows-x64 Installer” exe file is ideal.

After downloading, double click the JDK and follow the instructions to install it.

What is NetBeans?

NetBeans is essentially an Integrated Development Environment (IDE), which is used to facilitate the coding process. However, it is possible to create Java applications without installing NetBeans. After writing the code in Notepad, the tools within JDK help in compiling and executing them. 

While the creation of Java applications by merely using JDK is possible, the process can be quite tiresome. To ensure that the coding process becomes less challenging, use an IDE, a text editor with several innovative characteristics, to devise the code. The text editor also provides a graphical user interface that works in debugging, compiling, and running the applications. Soon, the importance of these features in coding will be discussed. In this lesson, NetBeans will be used as the IDE and is provided by Oracle.

NetBeans can be downloaded here: https://netbeans.apache.org/download/nb90/nb90.html. In the “Downloading” section, find the link for Binaries. Download the file and unzip it onto the desktop.

Now, it is time to work on the first Java Program.

The First Java Program

Let us now begin coding! 

Firstly, open the folder “netbeans\bin” in the unzipped NetBeans installation folder. For Windows users, the netbeans.exe (for 32-bit computers) or netbeans64.exe (for 64-bit computers) file must be selected, based on whether a 32-bit or 64-bit Windows computer is in use for launching NetBeans. If using a Macintosh, double-click on the NetBeans file to start the installation.

In case an error message stating “Cannot find Java 1.8 or higher” appears, inform NetBeans as to where the JDK was installed.

For Windows users, the JDK will be in C:\Program Files\Java\jdk-***.

On the other hand, Mac users will find it in /Library/Java/JavaVirtualMachines/jdk-***.jdk/Contents/Home. Note that *** represents the version in use. 

To inform NetBeans regarding the location wherein JDK is installed, open the folder titled “netbeans\etc” in the unzipped NetBeans installation folder. Use any text editor to open the netbeans.conf file and then leverage the “Find” function present in the text editor to find the line that contains netbeans_jdkhome. In case # is used before it, eliminate it to uncomment it. Then, tune the value of netbeans_jdkhome to align with the path of the JDK installation.

Let us say JDK is in C:\Program Files\Java\jdk-11.0.1. Then, users must change netbeans_jdkhome to netbeans_jdkhome=”C:\Program Files\Java\jdk-11.0.1

Then, save and close the netbeans.conf file. This time, launching NetBeans should not result in any errors. 

In case a notification appears directing the installation of the nb-javac library, install it. 

Now, on the top menu bar, click on File > New Project…., which will open up a New Project dialog box. Under categories, select Java and under Projects, choose Java Application. Then, click on Next.

Name the project as Welcome. Do note down where the project is stored, and then click on Finish to create the project.

NetBeans will present a default template. Use the code below to substitute the existing code. 

public class Welcome {
    public static void main(String[] args) {
     //Print Great Day
    System.out.println("Welcome to Java Programming!"); 
    }
}

While typing, NetBeans’ exciting characteristics will be displayed, such as the color-coded syntax (which is programming lingo for words). This way, the code becomes much easier to read. In this program, the purpose of different words is different, and hence, different colors demonstrate this difference. Let us look at this in detail a little later. 

Moreover, a box pops up near the cursor showcasing a few help messages, referred to as Intellisense. Put a period (.) following the term System. Subsequently, a dropdown list emerges, informing what can come after the period. Another box is present that provides more information.  

Lastly, when an opening bracket is typed, NetBeans will automatically close the bracket.

All of these characteristics ensure that coding becomes easier with the help of NetBeans.

Select File > Save to save the file. There is another feature on Netflix called “Compile on Save,” which compiles the code each time it is saved. The compiled program executes after clicking on the Run Button at the top menu is clicked.

In case the program does not run, an error message pops up. Click on the option Run Anyway. Then, the output window elaborately showcases the error. Place the cursor on the red line in the text editor window to learn about the code’s issues. Once the issue is resolved, re-run the program.

Upon successful running, the following message appears in the output window.

Welcome to Java Programming!

In this program, only “Welcome to Java Programming!” is displayed in the output window. The other statements that can be seen offer further information and are not the program’s output.

This section completes the coding of the first program. Great job!  

The file that was written has been named Welcome.java. This name can be seen at the top of the text editor window. 

Leave a Reply

%d bloggers like this: