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

I'm interested in biological psychology and cognitive psychology
Tanya Reply
what does preconceived mean
sammie Reply
physiological Psychology
Nwosu Reply
How can I develope my cognitive domain
Amanyire Reply
why is communication effective
Dakolo Reply
Communication is effective because it allows individuals to share ideas, thoughts, and information with others.
effective communication can lead to improved outcomes in various settings, including personal relationships, business environments, and educational settings. By communicating effectively, individuals can negotiate effectively, solve problems collaboratively, and work towards common goals.
it starts up serve and return practice/assessments.it helps find voice talking therapy also assessments through relaxed conversation.
miss
Every time someone flushes a toilet in the apartment building, the person begins to jumb back automatically after hearing the flush, before the water temperature changes. Identify the types of learning, if it is classical conditioning identify the NS, UCS, CS and CR. If it is operant conditioning, identify the type of consequence positive reinforcement, negative reinforcement or punishment
Wekolamo Reply
please i need answer
Wekolamo
because it helps many people around the world to understand how to interact with other people and understand them well, for example at work (job).
Manix Reply
Agreed 👍 There are many parts of our brains and behaviors, we really need to get to know. Blessings for everyone and happy Sunday!
ARC
A child is a member of community not society elucidate ?
JESSY Reply
Isn't practices worldwide, be it psychology, be it science. isn't much just a false belief of control over something the mind cannot truly comprehend?
Simon Reply
compare and contrast skinner's perspective on personality development on freud
namakula Reply
Skinner skipped the whole unconscious phenomenon and rather emphasized on classical conditioning
war
explain how nature and nurture affect the development and later the productivity of an individual.
Amesalu Reply
nature is an hereditary factor while nurture is an environmental factor which constitute an individual personality. so if an individual's parent has a deviant behavior and was also brought up in an deviant environment, observation of the behavior and the inborn trait we make the individual deviant.
Samuel
I am taking this course because I am hoping that I could somehow learn more about my chosen field of interest and due to the fact that being a PsyD really ignites my passion as an individual the more I hope to learn about developing and literally explore the complexity of my critical thinking skills
Zyryn Reply
good👍
Jonathan
and having a good philosophy of the world is like a sandwich and a peanut butter 👍
Jonathan
generally amnesi how long yrs memory loss
Kelu Reply
interpersonal relationships
Abdulfatai Reply
What would be the best educational aid(s) for gifted kids/savants?
Heidi Reply
treat them normal, if they want help then give them. that will make everyone happy
Saurabh
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