<< Chapter < Page Chapter >> Page >

Writing, compiling, and running Java programs

One of the reasons that I chose Java as the main programming language for this course is that while Java is a very powerful object-oriented programminglanguage, the mechanics of writing, compiling, and running Java programs are very simple.

Confirm your Java installation

First you need to confirm that the Java development kit (jdk) version 1.7 or later is installed on the computer. (The jdk is already installed in the CIT computer labs at the NRG campus of ACC, and perhaps in thelabs on other ACC campuses as well.) If you are working at home, see Oracle's JDK 7 and JRE 7 Installation Guide .

Creating your source code

Next, you need to use any text editor to create your Java source code files as text files with an extension of .java. (I prefer the free JCreator editor because it produces color-coded text and includes some other simple IDE features as well.JCreator is normally installed in the CIT computer labs at the NRG campus of ACC.)

Compiling your source code

The name of each source code file should match the name of the Java class defined in the file.

Assume that your source code file is named MyProg.java . You can compile the program by opening a command prompt window in the foldercontaining the source code file and executing the following command at the prompt:

Command to compile the source code: javac MyProg.java

Running your Java program

Once the program is compiled, you can execute it by opening a command prompt window in the folder containing the compiled source code files (files with an extension of .class) and executing the following command at the prompt:

Command to execute the program: java MyProg

Using a batch file

If you are running under Windows, the easiest approach is to create and use a batch file to compile and run your program. (A batch file is simply a text file with an extension of .bat instead of .txt.)

Create a text file named CompileAndRun.bat containing the text shown in the note-box below.

Contents of batch file are shown below: del *.class javac MyProg.javajava MyProg pause

Place this file in the same folder as your source code files. Then double-click on the batch file to cause your program to be compiled andexecuted.

That's all there is to it.

The program named PointLine01

Before we go any further, let's take a look at a simple Java program that illustrates one of the ways that points and lines are represented in Java code. (See Figure 1 .)

The Point2D.Double class

This program illustrates one implementation of the concepts of point and line segment in Java code.

Four points (locations in space) are defined by passing the coordinates of the four points as the x and y parameters to the constructor for the Point2D.Double class. This results in four objects of the Point2D.Double class.

( Point2D.Double is a class in the standard Java library.)

The Line2D.Double class

Two line segments are defined by passing pairs of points as parameters to the constructor for the Line2D.Double class. This results in two objects of the Line2D.Double class.

Questions & Answers

what is phylogeny
Odigie Reply
evolutionary history and relationship of an organism or group of organisms
AI-Robot
ok
Deng
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
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, Game 2302 - mathematical applications for game development. OpenStax CNX. Jan 09, 2016 Download for free at https://legacy.cnx.org/content/col11450/1.33
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Game 2302 - mathematical applications for game development' conversation and receive update notifications?

Ask