<< 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

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.
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
characteristics of micro business
for teaching engĺish at school how nano technology help us
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
what is the actual application of fullerenes nowadays?
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
what is the Synthesis, properties,and applications of carbon nano chemistry
Abhijith Reply
Mostly, they use nano carbon for electronics and for materials to be strengthened.
is Bucky paper clear?
carbon nanotubes has various application in fuel cells membrane, current research on cancer drug,and in electronics MEMS and NEMS etc
so some one know about replacing silicon atom with phosphorous in semiconductors device?
s. Reply
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Do you know which machine is used to that process?
how to fabricate graphene ink ?
for screen printed electrodes ?
What is lattice structure?
s. Reply
of graphene you mean?
or in general
in general
Graphene has a hexagonal structure
On having this app for quite a bit time, Haven't realised there's a chat room in it.
what is biological synthesis of nanoparticles
Sanket Reply
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?