<< Chapter < Page Chapter >> Page >
A traditional Hello World in Java provides interesting insights into the structure of a Java application.

Revised: Sun Mar 27 23:30:58 CDT 2016

This page is included in the following Books:

Table of contents


It is traditional in introductory programming courses to write and explain a simple program that prints the text "Hello World" on the computer screen.

This module continues that tradition.

Viewing tip

I recommend that you open another copy of this module in a separate browser window and use the following links to easily find and view the Figures and Listings while you are reading about them.


  • Figure 1 . How to compile and run a Java application.



This module introduces you to Java programming by presenting and discussing a traditional Hello World program.

Two approaches

Java programs can be written and executed in several different ways, including the following:

  • Stand-alone application from the command line.
  • Applet that runs under control of a Java-capable browser.

It is also possible in many cases to write applets, which can be run in a stand-alone mode from the command line, or can be run under control of aJava-capable browser. An example of such an applet will be presented in a future module.

Applets vs. applications

Programming an "application" in Java is significantly different from programming an "applet." Applets are designed to be downloaded and executed on-line under control of a browser.

Restrictions on applets

Their functionality of an applet is usually restricted in an attempt to prevent downloadedapplets from damaging your computer or your data. No such restrictions apply to the functionality of a Java application.

Class definitions

All Java programs consist of one or more class definitions. In this course, I will often refer to the primary class definition for a Java application as the controlling class .

The main method

A stand-alone Java application requires a method named main in its controlling class .

An Applet does not require a main method. The reason that a Java Applet does not require a main method will be explained in a future module.

Getting started

Figure 1 shows the steps for compiling and running a Java application.

Figure 1. How to compile and run a Java application.

Here are the steps for compiling and running a Java application, based on the assumption that you are running under Windows. If you are running under someother operating system, you will need to translate these instructions to that OS.

1. Download and install the JDK from Oracle. Also consider downloading and installing the documentation, which is a separate download.

2. Using any editor that can produce a plain text file (such as Notepad), create a source code file with the extension on the file name being .java Thisfile contains your actual Java instructions. (You can copy some sample programs from the early lessons in this collection to get started.)

3. Open a command-line window and change directory to the directory containing the source file. It doesn't really matter which directory the sourcefile is in, but I normally put my Java files in a directory all their own.

4. Assume that the name of the file is joe.java , just to have something definitive to refer to.

5. To compile the file, enter the following command at the prompt:

javac joe.java

6. Correct any compiler errors that show up. Once you have corrected all compiler errors, the javac program will execute and return immediately to the prompt with no output. At that point, the directory shouldalso contain a file named joe.class and possibly some other files with a .class extension as well. These are the compiled Java files.

7. To run the program, enter the following command:

java joe

8. If your program produces the correct output, congratulations. You have written, compiled, and executed a Java application. If not, you will need todetermine why not.

Questions & Answers

Application of nanotechnology in medicine
what is variations in raman spectra for nanomaterials
Jyoti Reply
I only see partial conversation and what's the question here!
Crow Reply
what about nanotechnology for water purification
RAW Reply
please someone correct me if I'm wrong but I think one can use nanoparticles, specially silver nanoparticles for water treatment.
yes that's correct
I think
what is the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
How we are making nano material?
what is a peer
What is meant by 'nano scale'?
What is STMs full form?
scanning tunneling microscope
how nano science is used for hydrophobicity
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
what is differents between GO and RGO?
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
analytical skills graphene is prepared to kill any type viruses .
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
The nanotechnology is as new science, to scale nanometric
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
what school?
biomolecules are e building blocks of every organics and inorganic materials.
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
sciencedirect big data base
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!

Source:  OpenStax, Object-oriented programming (oop) with java. OpenStax CNX. Jun 29, 2016 Download for free at https://legacy.cnx.org/content/col11441/1.201
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Object-oriented programming (oop) with java' conversation and receive update notifications?