JAVA_2 - Introduction to Java Applications Fig. 2.1:...

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

View Full Document Right Arrow Icon
1 // Fig. 2.1: Welcome1.java 2 // Text-printing program . 3 4 public class Welcome1 5 } 6 // main method begins execution of Java application 7 public static void main( String args ( [] 8 } 9 System.out.println( "Welcome to Java Programming ;( "! 10 11 // { end method main 12 13 // { end class Welcome1 Welcome to Java Programming ! OBJECTIVES In this chapter you will learn : To write simple Java applications . To use input and output statements . Java's primitive types . Basic memory concepts .
Background image of page 1

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

View Full DocumentRight Arrow Icon
To use arithmetic operators . The precedence of arithmetic operators . To write decision-making statements . To use relational and equality operators . 2.1 . Introduction We now introduce Java application programming which facilitates a disciplined approach to program design. Most of the Java programs you will study in this book process information and display results. We present six examples that demonstrate how your programs can display messages and how they can obtain information from the user for processing. We begin with several examples that simply display messages on the screen. We then demonstrate a program that obtains two numbers from a user, calculates their sum and displays the result. You will learn how to perform various arithmetic calculations and save their results for later use. Many programs contain logic that requires the program to make decisions. The last example in this chapter demonstrates decision-making fundamentals by showing you how to compare numbers then display messages based on the comparison results. For example, the program displays a message indicating that two numbers are equal only if they have the same value. We analyze each example one line at a time to help you ease your way into Java programming. To help you apply the skills you learn here, we provide many fun and challenging problems in the chapter's exercises . 2.2 . First Program in Java: Printing a Line of Text Figure 2.1. Text-printing program .
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Figure 2.2. Executing Welcome1 in a Microsoft Windows XP Command Prompt window . Compiling and Executing Your First Java Application
Background image of page 4
Figure 2.4. Printing multiple lines of text with a single statement . 1 // Fig. 2.4: Welcome3.java 2 // Printing multiple lines of text with a single statement . 3 4 public class Welcome3 5 } 6 // main method begins execution of Java application 7 public static void main( String args ( [] 8 } 9 System.out.println( "Welcome\nto\nJava\nProgramming ;( "! 10 11 // { end method main 12 13 // { end class Welcome3 Welcome to Java Programming ! Figure 2.5. Some common escape sequences . Escape sequence Description \ n Newline. Position the screen cursor at the beginning of the next line . \ t
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

JAVA_2 - Introduction to Java Applications Fig. 2.1:...

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

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