Download presentation
Presentation is loading. Please wait.
Published byElvin Booth Modified over 9 years ago
1
1 Computer Systems -- Introduction Chapter 1 focuses on: the structure of a Java application basic program elements preparing and executing a program basic object-oriented programming concepts helpful support for writing software Java applets
2
2 Focus of the Course Object-Oriented Software Development problem solving program design and implementation object-oriented concepts objects classes interfaces inheritance polymorphism graphics and Graphical User Interfaces the Java programming language
3
3 Programming Languages A programming language specifies the words and symbols that we can use to write a program There are four basic programming language levels: machine language assembly language high-level language fourth-generation language
4
4 Machine Languages Each CPU has its own specific machine language machine-dependent code Pentium processor has its own machine language SPARC process has its own machine language hard to read, write, understand 1101 0000 0000 0111 1011 1111 1110 1000 1101 0010 0000 0111
5
5 Assembly language Symbolic code for machine language Machine-dependent Easier to read, write, and understand than machine language ld [%fp-20], %o0 ld [%fp-24], %o1 add %o0, %o1, %o0 Still, assembly programming is a difficult job Assembler assembly code machine code assembler
6
6 High-level Languages Machine-independent language Fortran, COBOL, C, C++, Java, … easy to program a + b Program execution compilation(translation) interpretation mixture of the two
7
7 Compiler A program must be translated into machine language a software tool which translate source code into target code source code target code compiler Fortran C, C++ Assembly code Machine code
8
8 Interpreter A software tool which read a program and interpret(excute) it Basic, Prolog, ML, …. input output interpreter program
9
9 The Java Programming Language Java was created by Sun Microsystems, Inc. It was introduced in 1995 and has become quite popular It is an object-oriented language It is an Internet programming language
10
10 Problem Solving The purpose of writing a program is to solve a problem The general steps in problem solving are: Understand the problem Dissect the problem into manageable pieces Design a solution Consider alternatives to the solution and refine it Implement the solution Test the solution and fix any problems that exist
11
11 Java Program Structure See Lincoln.java A program is made up of one or more classes A class contains one or more methods A method contains program statements A Java application always executes the main method
12
12 Java Program Structure public class MyProgram {}{} // comments about the class class header class body Comments can be added almost anywhere
13
13 Java Program Structure public class MyProgram {}{} public static void main (String[] args) {}{} // comments about the class // comments about the method method header method body
14
14 Lincoln.java class Lincoln { public static void main (String[] args) { System.out.println ("Whatever you are, be a good one."); } // method main } // class Lincoln
15
15 White Space Spaces, blank lines, and tabs to separate words and symbols in a program Extra white space is ignored A valid Java program can be formatted in many different ways See Lincoln2.java and Lincoln3.java Programs should be formatted to enhance readability, using consistent indentation
16
16 Lincoln2.java class Lincoln2 { public static void main (String[] args) { System.out.println ("Whatever you are, be a good one."); } }
17
17 Lincoln3.java class Lincoln3 { public static void main ( String [] args ) { System.out.println ( "Whatever you are, be a good one." ) ; }
18
18 Comments Comments in a program are also called inline documentation They should explain the purpose of the program and describe processing steps Java comments can take two forms: // comment runs to the end of the line /* comment runs to terminating symbol, even across line breaks */
19
19 Identifiers The words a programmer uses in a program Most identifiers have no predefined meaning An identifier can be made up of letters, digits, _, and $ they cannot begin with a digit Java is case sensitive, Total and total are different identifiers
20
20 Reserved Words Some identifiers, called reserved words, have predefined meanings. abstract boolean break byte byvalue case cast catch char class const continue default do double else extends false final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while
21
21 Literals A literal is an explicit data value used in a program Integer literals: 25 69 -4288 Floating point literals: 3.14159 42.075 -0.5 String literals: "The result is: " "To thine own self be true."
22
22 Java Translation and Execution The Java compiler translates Java source code into a special representation called bytecode Java bytecode a virtual machine code is not the machine language for any traditional CPU Interpreter interpret Java bytecode Java compiler is not tied to any particular machine Java is considered to be architecture-neutral
23
23 Java Translation and Execution Java source code Machine code Java bytecode Java interpreter Bytecode compiler Java compiler
24
24 Java Translation and Execution Compiling a Java program > javac Lincoln.java This creates a file called Lincoln.class Interpret the class file > java Lincoln The.java extension is used at compile time, but the.class extension is not used with the interpreter
25
25 Three types of program errors Compile-time errors The compiler will find problems with syntax and semantics If compile-time errors exist, an executable version of the program is not created Run-time errors A problem can occur during program execution, divide by zero Logical errors A program may run, but produce incorrect results
26
26 Command Line Arguments The main method accepts extra information on the command line when a program is executed > java Name_Tag John Each extra value is called command line argument In Java, command line arguments are always read as a list of character strings
27
27 Java Applets A Java applet a Java program that is intended to be sent across a network and executed using a Web browser A Java application is a stand alone program Applications have a main method, but applets do not Applets are derived from the java.applet.Applet class
28
28 Java Applets See No_Parking.java Links to applets can be embedded in HTML documents Appletviewer in JDK appletviewer xxx.html Web browser Netscape navigator Internet explorer
29
29 No_Parking.java import java.applet.Applet; import java.awt.*; public class No_Parking extends Applet { public void paint (Graphics page) { page.drawString ("Parking", 50, 50); page.drawOval (45, 24, 43, 43); page.drawLine (82, 30, 51, 61); } // method paint } // class No_Parking
30
30 Execution of Java Applets Java source code Java source code Java bytecode Java bytecode Java compiler Java compiler Java interpreter Java interpreter Web browser local computer remote computer remote computer
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.