Textbook Notes (270,000)
CA (160,000)
Ryerson (10,000)
ITM (800)
ITM 200 (20)
Chapter 3

Chapter 3

Information Technology Management
Course Code
ITM 200
Vikraman Baskaran

This preview shows pages 1-2. to view the full 7 pages of the document.
Chapter 3 – Outputs and calculations
3.1 The structure of a Java program
Comments are pieces of text that are ignored by the compiler
They are usually included by the author of a program for 2 reasons
oProvide useful notes or explanations for a human reading the program
oPrevent statements from being executed – maybe during lazy debugging or
program development
Following are comments
o// Prints Hello on the screen in a dialog box
o// import class JOptionPane
Comments begin with ‘//, which tells the computer that all text from this point until the
end of the line is to be ignored when translating the Java program into byte code
You should always place a comment at the start of the program to state
oThe purpose of the program
oAn outline of how it carries out its task
oWho wrote the program and when
oA list of any changes to the program and when they were made
oAnything else which might help a reader to understand the program
Other kinds of Java comments
Another type of comment starts with ‘/*’ and ends with ‘*/
This kind of comment can spread over 2 or more lines for detailed notes
Importing (reusing) code from other files
The line “import javax.swing.JOptionPane; is an import statement

Only pages 1-2 are available for preview. Some parts have been intentionally blurred.

Every java program will contain at least 1 class defined by the programmer
The words public class are Java keywords which must be included and followed by the
name you give to the class
oThe methods which apply each algorithm in your program are placed within the
class definition
oClasses can have many methods (subprograms)
oFor example, pizza recipe book can be thought of as the class and its recipe as
oEvery Java program must contain a method called main()
This represents the main algorithm of the program
3.2 Output statements
Command line output
Program instructions are called statements
To make output move to a new line, you must include in the string the escape sequence
‘\n’ which represents the newline character
System.out is called the standard output object
oIt has methods print() and println()
oDifference is that println() will place the output cursor at the start of the next line
but print() will leave the cursor on the same line after printing the text
3.3 Subprograms
Name of the main method is always main() but you can implement other algorithms as
named methods
o2 additional methods are spling() and splong()
oBoth called from main()
oThe brackets () are required even though there is nothing between them
You're Reading a Preview

Unlock to view full version