Chapter2PPTa

Chapter2PPTa - Chapter 2 JAVA FUNDAMENTALS 1 THE PARTS OF A...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Chapter 2 JAVA FUNDAMENTALS
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 THE PARTS OF A JAVA PROGRAM // DisplayMessage.java Created using: jGRASP // By L. Thompson // A simple Java program that displays the message // Have a good semester! on a line on the computer screen public class DisplayMessage { public static void main(String[ ] args) { System.out.println("Have a good semester!"); System.exit(0); } }
Background image of page 2
3 THE PARTS OF A JAVA PROGRAM Comments // DisplayMessage.java Created using: jGRASP // By L. Thompson // A simple Java program that displays the message // Have a good semester! on a line on the computer screen public class DisplayMessage { public static void main(String[ ] args) { System.out.println("Have a good semester!"); System.exit(0); } } These are comments. They are ignored by the compiler.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 THE PARTS OF A JAVA PROGRAM Comments Comments are notes of explanation used to document programs, sections of programs, or program statements for the humans who must read programs. Every program should start with a comment that supplies the name of the file containing the source code, the name of the author of the program, and a description of the program. DisplayMessage.java begins with the following comment: // DisplayMessage.java Created using: jGRASP // By L. Thompson // A simple Java program that displays the message // Have a good semester! on a line on the computer screen
Background image of page 4
5 THE PARTS OF A JAVA PROGRAM Comments The compiler, the program that translates Java programs to byte code, ignores everything from the two forward slashes to the end of the line. Comments do not end with a semicolon.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 THE PARTS OF A JAVA PROGRAM // DisplayMessage.java Created using: jGRASP // By L. Thompson // A simple Java program that displays the message // Have a good semester! on a line on the computer screen public class DisplayMessage { public static void main(String[ ] args) { System.out.println("Have a good semester!"); System.exit(0); } } The compiler ignores blank lines. It is a good idea to use blank lines to make your program easier to read.
Background image of page 6
7 THE PARTS OF A JAVA PROGRAM Class Definition // DisplayMessage.java Created using: jGRASP // By L. Thompson // A simple Java program that displays the message // Have a good semester! on a line on the computer screen public class DisplayMessage { public static void main(String[ ] args) { System.out.println("Have a good semester!"); System.exit(0); } } This is the class header for the class named DisplayMessage . This is a class definition.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
THE PARTS OF A JAVA PROGRAM Class Definition Every Java program must have at least one class definition. We will use a class as a container for the statements that comprise our program. In the example, the class named DisplayMessage contains the statements that make up our program. public class DisplayMessage
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 87

Chapter2PPTa - Chapter 2 JAVA FUNDAMENTALS 1 THE PARTS OF A...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online