<< Chapter < Page Chapter >> Page >
java Prob01

Again, it is often necessary to specify the path to various library files on the command line when executing the application. In that case, the simplest form is not sufficient.

Compilation and execution on my machine

This application can be compiled and executed on my machine by entering the two commands shown in Figure 3 at the command prompt. (Note that artificial line breaks were inserted into Figure 3 to force the long commands to fit this narrow format.)

Figure 3 . Commands to compile and execute the application.
javac -cp .;M:\Baldwin\AA-School\Itse2321IntroOOP\ MediaCompBookMaterial\bookClasses Prob01.javajava -cp .;M:\Baldwin\AA-School\Itse2321IntroOOP\ MediaCompBookMaterial\bookClasses Prob01

The compiler and the virtual machine

The javac portion of the first command causes the Java compiler to run.

The java portion of the second command causes the Java virtual machine to run.

The input files

The Prob01.java and Prob01 at the ends of the two commands specify the files being operated on by the compiler and the virtual machine respectively.

A classpath

In both cases, the -cp indicates that a classpath follows.

A classpath consists of one or more path specifications separated by semicolon characters.

The purpose of the classpath is to tell the compiler and the virtual machine where to look for previously compiled class files that the application needs in order to successfully compile and execute.

The current folder

The period ahead of the semicolon says to search the current folder first.

The path to the Ericson library

The material following the semicolon is the absolute path to the folder containing the class files that make up Ericson's library on my machine. The location of that folder will probably be different on your machine.

The main method

Now that we have the preliminaries out of the way, let's go back and examine the body of the main method in Listing 1 .

The first statement in the body of the main method in Listing 1 instantiates a new object of the class named Prob01Runner .

The statement saves a reference to that object in a reference variable named obj . Note that the type of the variable is the same as the name of the class in this case. In general, the type of the variable must be:

  • The name of the class, or
  • The name of a superclass of the class, or
  • The name of an interface implemented by the class.

Accessing the object

You must save a reference to an object in order to gain access to the object later. In this case, the reference is stored in the variable named obj .

Call the method named run

The second statement in the body of the main method in Listing 1 uses that reference to call the method named run encapsulated in the object. As you will see later, most of the work in this application is performed in the method named run .

Get and display information about the object

When the run method returns control to the main method, the last three statements in the body of the main method in Listing 1 use the object's reference to call the following three methods belonging to the object:

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