Inside Collection (Course): Object-Oriented Programming (OOP) with Java
Summary: The purpose of this module is to present the first complete Java program of the collection that previews the most common forms of the three pillars of procedural programming: sequence, selection, and loop. The program also previews calling a method, passing a parameter to the method, and receiving a returned value from the method.
The purpose of this module is to present the first complete Java program of the collection that previews the most common forms of the three pillars of procedural programming:
The program also illustrates
As mentioned above, this is simply a preview. Detailed discussions of these topics will be presented in future modules.
Assuming that the Java Development Kit (JDK) is properly installed on your computer (see Jb0110: Java OOP: Programming Fundamentals, Getting Started ), do the following to compile and run this program.
1. Copy the text from Listing 1 into a text file named FirstProgram.java and store the file in a folder on your disk.
2. Open a command-line window in the folder containing the file.
3. Type the following command at the prompt to compile the program:
javac FirstProgram.java
4. Type the following command at the prompt to run the program:
java FirstProgram
Any text in the program code that begins with // is a comment. The compiler will ignore everything from the // to the end of the line.
Comments were inserted into the program code to explain the code.
The compiler also ignores blank lines.
Note that this program was designed to illustrate the concepts while being as non-cryptic as possible.
The program should display the text shown in Image 1 on the screen except that the time will be different each time you run the program.
| Image 1: Program output. | |
|---|---|
|
I encourage you to copy the code from Listing 1 . Compile the code and execute it. Experiment with the code, making changes, and observing the results of your changes. Make certain that you can explain why your changes behave as they do.
This section contains a variety of miscellaneous information.
Financial : Although the Connexions site makes it possible for you to download a PDF file for this module at no charge, and also makes it possible for you to purchase a pre-printed version of the PDF file, you should be aware that some of the HTML elements in this module may not translate well into PDF.
I also want you to know that, I receive no financial compensation from the Connexions website even if you purchase the PDF version of the module.
In the past, unknown individuals have copied my modules from cnx.org, converted them to Kindle books, and placed them for sale on Amazon.com showing me as the author. I neither receive compensation for those sales nor do I know who does receive compensation. If you purchase such a book, please be aware that it is a copy of a module that is freely available on cnx.org and that it was made and published without my prior knowledge.
Affiliation : I am a professor of Computer Information Technology at Austin Community College in Austin, TX.
A complete listing of the program follows.
| Listing 1: Source code for FirstProgram. |
|---|
|
-end-