What is a Computer?public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } animation print a message to the console Anatomy of a Java Program oComments oReserved words oModifiers oStatements oBlocks oClasses oMethods oThe main method 18 Comments Line comment: A line comment is preceded by two slashes (//) in a line. Paragraph comment: A paragraph comment is enclosed between /* and */ in one or multiple lines. 19 Three types of comments in Java. Reserved Words Reserved words or keywords are words that have a specific meaning to the compiler and cannot be used for other purposes in the program. For example, when the compiler sees the word class, it understands that the word after class is the name for the class. Other reserved words in Listing 1.1 are public, static, and void. Their use will be introduced later in the book. 20 Modifiers Java uses certain reserved words called modifiers that specify the properties of the data, methods, and classes and how they can be used. Examples of modifiers are public and static. Other modifiers are private, final, abstract, and protected. A public datum, method, or class can be accessed by other programs. A private datum or method cannot be accessed by other programs. 21 Statements o A statement represents an action or a sequence of actions. o The statement System.out.println("Welcome to Java!") in the program in Listing 1.1 is a statement to display the greeting "Welcome to Java!"For example, the following is a high-level language statement that computes the area of a circle with radius 5: area = 5 * 5 * 3.1415; Popular High-Level Languages oCOBOL (COmmon Business Oriented Language) oFORTRAN (FORmula TRANslation) oBASIC (Beginner All-purpose Symbolic Instructional Code) oPascal (named for Blaise Pascal) oAda (named for Ada Lovelace) oC (whose developer designed B first) oVisual Basic (Basic-like visual language developed by Microsoft) oDelphi (Pascal-like visual language developed by Borland) oC++ (an object-oriented language, based on C) oC# (a Java-like language developed by Microsoft) oJava (We use it in the book) 9 Operating Systems Operating systems are software systems that make using computers more convenient for users, application developers and system administrators.01001010 01100001 01110110 01100001 00000011 Memory content Memory address Encoding for character 'J' Encoding for character 'a' Encoding for character 'v' Encoding for character 'a' Encoding for number 3 Storage Devices CPU e.g., Disk, CD, and Tape Input Devices e.g., Keyboard, Mouse e.g., Monitor, Printer Communication Devices e.g., Modem, and NIC Storage Devices Memory Output Devices Bus 4 Memory is volatile, because information is lost when the power is off.CPU e.g., Disk, CD, and Tape Input Devices e.g., Keyboard, Mouse e.g., Monitor, Printer Communication Devices e.g., Modem, and NIC Storage Devices Memory Output Devices Bus How Data is Stored?The main method looks like this: public static void main(String[] args) { // Statements; } 27 The showMessageDialog Method JOptionPane.showMessageDialog(null, "Welcome to Java!", "Display Message", JOptionPane.INFORMATION_MESSAGE);10 Linux Windows Mac OS Android BlackBerry OS Apple's iOS x86 Architecture CPU Memory NIC Card Hard Disk Why Java?11 The answer is that Java enables users to develop and deploy applications on the Internet for servers, desktop computers, and small hand-held devices.public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Enter main method Trace a Program Execution 16 //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } Execute statement animation Trace a Program Execution 17 //This program prints Welcome to Java!2 A computer consists of a CPU, memory, hard disk, floppy disk, monitor, printer, and communication devices.For example, to add two numbers, you might write an instruction in assembly code like this: ADDF3 R1, R2, R3 ... ADDF3 R1, R2, R3 ... Assembly Source File Assembler ... 1101101010011010 ... Machine Code File Programming Languages Machine Language Assembly Language High-Level Language 8 The high-level languages are English-like and easy to learn and program.Data of various kinds, such as numbers, characters, and strings, are encoded as a series of bits (zeros and ones).Computers use zeros and ones because digital devices have two stable states, which are referred to as zero and one by convention.The programmers need not to be concerned about the encoding and decoding of data, which is performed automatically by the system based on the encoding scheme.There are three main types of storage devices:Disk drives (hard disks and floppy disks), CD drives (CD-R and CD-RW), and Tape drives.For example, to add two numbers, you might write an instruction in binary like this: 1101101010011010 Programming Languages Machine Language Assembly Language High-Level Language 7 Assembly languages were developed to make programming easy.Operating systems provide services that allow each application to execute safely, efficiently and concurrently (i.e., in parallel) with other applications.The software that contains the core components of the operating system is called the kernel.Popular Java IDEs oNetBeans Open Source by Sun oEclipse Open Source by IBM 12 A Simple Java Program 13 Listing 1.1 Compiling Java Source Code You can port a source program to any machine with appropriate compilers.Programs and data are permanently stored on storage devices and are moved to memory when the computer actually uses them.Java Virtual Machine is a software that interprets Java bytecode.Programs are written using programming languages.3 ...2000 2001 2002 2003 2004 ...