<< Chapter < Page Chapter >> Page >

The Java version of Hello World

The class file

Compiled Java programs are stored in "bytecode" form in a file with an extension of .class where the name of the file is the same as the name of the controlling class (or other class) in the program.

The main method is static

The main method in the controlling class of an application must be static , which results in main being a class method.

Class methods can be called without a requirement to instantiate an object of the class.

When a Java application is started, the Java Virtual Machine or JVM (an executable file named java.exe) finds and calls the main method in the class whose name matches the name of the class file specified on the command line.

Running an application

For example, to start the JVM and run a Java application named hello1 , a command such as the following must be executed at the operating system prompt:

null

This command instructs the operating system to start the JVM, and then instructs the JVM to find and execute the java application stored in the file named hello1.class . (Note that the .class extension is not included in the command .)

This sample program is a Java application named hello1.java .

When compiled, it produces a class file named hello1.class .

When the program is run, the JVM calls the main method defined in the controlling class .

The main method is a class method.

Class methods can be called without a requirement to instantiatean object of the class.

The program displays the following words on the screen:

Hello World

Interesting code fragments

I will explain this program code in fragments. A complete listing of the program is provided in Listing 5 .

The code fragment in Listing 1 shows the first line of the class definition for the controlling class named hello1 . (I will discuss class definitions in detail in a future module.)

Listing 1 . Beginning of the class named hello1.
class hello1 { //define the controlling class

The code fragment in Listing 2 begins the definition of the main method. I will also discuss method definitions in detail in a future module.

Listing 2 . Beginning of the main method.
public static void main(String[] args){

The fragment in Listing 3 causes the string Hello World to be displayed on the command-line screen.

The statement in Listing 3 is an extremely powerful statement from an object-oriented programming viewpoint. When you understand how itworks, you will be well on your way to understanding the Java version of Object-Oriented Programming (OOP).

I will discuss this statement in more detail later in a future module.

Listing 3 . Display the string Hello World.
System.out.println("Hello World");

Listing 4 ends the main method and also ends the class definition for the class named hello1 .

Listing 4 . End of the class named hello1.
}//end main }//End hello1 class

The complete program listing

As mentioned earlier, a complete listing of the program is provided in Listing 5 near the end of the module.

General information

This program illustrates several general aspects of Java programming.

Overall skeleton of java program

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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?

Ask