ch02 - Blank lines and space characters Make programs...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Blank lines and space characters Make programs easier to read. Blank lines, spaces and tabs are known as white space (or whitespace). White space is 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
Class declaration public class  Welcome1  Every Java program consists of at least one class that you define. class keyword introduces a class declaration and is immediately followed by the class name . Keywords (Appendix C) are reserved for use by Java and are always spelled with all lowercase letters.
Background image of page 4
Class names By convention, begin with a capital letter and capitalize the first letter of each word they include (e.g., SampleClassName ). A class name is an identifier —a series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) that does not begin with a digit and does not contain spaces. Java is case sensitive —uppercase and lowercase letters are distinct—so a1 and A1 are different (but both valid) identifiers.
Background image of page 5

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

View Full DocumentRight Arrow Icon
Declaring the main Method public static void  main( String[]  args ) Starting point of every Java application. Parentheses after the identifier main indicate that it’s a program building block called a method . Java class declarations normally contain one or more methods. main must be defined as shown; otherwise, the JVM will not execute the application. Methods perform tasks and can return information when they complete their tasks. Keyword void indicates that this method will not return any information.
Background image of page 6
Body of the method declaration Enclosed in left and right braces. Statement System.out.println( "Welcome to Java Programming!" ); Instructs the computer to perform an action l Print the string of characters contained between the double quotation marks. A string is sometimes called a character string or a string literal . White-space characters in strings are not ignored by the compiler. Strings cannot span multiple lines of code.
Background image of page 7

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

View Full DocumentRight Arrow Icon
System.out object Standard output object . Allows Java applications to display strings in the command window from which the Java application executes. System.out.println method Displays (or prints) a line of text in the command window. The string in the parentheses the argument to the method. Positions the output cursor at the beginning of the next line in the command window. Most statements end with a semicolon.
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Class Welcome2 , shown in Fig. 2.3, uses two statements to produce the same output as that shown in Fig. 2.1. New and key features in each code listing are
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 42

ch02 - Blank lines and space characters Make programs...

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

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