Tag Archives: java

Java || Hello World!

This page will consist of creating the typical “hello world!” application. First, you will need to create a new project in whichever IDE you are using. I am using a simple text editor and the terminal, but any compiler will do.

When you have everything loaded up, you will start your code off by entering the headers like so into your HelloWorld.java file.


The most basic form of a class definition is shown above. The keyword “class” begins the class definition for the class named “HelloWorld.”

Next, you are going to add the main function. This will generally look something like this:


Every program in Java must contain a main method declaration as shown above. The declaration “public” and “static” can be written in any order (public static or static public), but the custom is to use “public static.”

We are halfway finished, now all we have to do is say hello to the world! You will do that by adding this line of code to your program, which basically outputs data to the screen


The above code uses the “System” class from the core library to print the “Hello World!” message to standard output.

So when you add everything together, your full code will look something like this

===== HOW TO COMPILE CODE USING THE TERMINAL =====

Once you have loaded the terminal, if you have your java source file saved in any directory other than the home folder, you will need to change directories to that specific folder where your source file resides. Many typically save their source files to the desktop.

*** If your files are located on the desktop, in the terminal, type this command:

@ubuntu:~$ cd Desktop

*** Next we will compile the java source file, and this can be achieved by typing the following command:
(Notice the .java source file is named exactly the same as the class header)

@ubuntu:~/Desktop$ javac HelloWorld.java

*** To run the compiled program, simply type this command:

@ubuntu:~/Desktop$ java HelloWorld

And there you have it! After you compile the above code, you should get this as your output

Hello World!

Java || Which Compiler To Use?

A common question one may wonder is, which compiler should I use? There are a few choices, and your choice should probably be based on what you intend to write with it.

If you intend to program on Windows, a common choice is to download one of the many (free) Integrated Development Environment’s (IDE) which are currently available on the internet. The IDE’s I recommend are:

* NetBeans
* Eclipse

Netbeans and Eclipse are the equivalent of Visual Studios and CodeBlocks for C++. (NOTE: Netbeans and Eclipse is also available for download on Linux).

You will also need to have Java installed on your computer in order to develop Java applications. If you are using Windows, then visit the Oracle website. and download and install either JDK7 or JDK7 with Netbeans. Don’t bother with JRE, as it merely runs Java programs, but does not compile them.

==== LINUX USERS ====

To install Java, open the terminal window and enter the command:

sudo apt-get install openjdk-7-jdk

If you want to add Netbeans to your computer, then use the same terminal window and enter the command below:

sudo apt-get install netbeans

Alternatively, if you want to add Eclipse to your computer, then use the same terminal window and enter the command below:

sudo apt-get install eclipse-platform

Personally, I use a simple text editor (gedit) and the terminal window in Ubuntu to program in Java, and all the source code which is presented on this site was created using that development environment.