Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop.

Similar presentations


Presentation on theme: "1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop."— Presentation transcript:

1 1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop large-scale enterprise applications Enhance WWW server functionality Provide applications for consumer devices (cell phones, etc.)

2 2 Thinking About Objects Objects –Reusable software components that model real-world items –Look all around you People, animals, plants, cars, etc. –Attributes Size, shape, color, weight, etc. –Behaviors Babies cry, crawl, sleep, etc.

3 3 Java Class Libraries Classes –Include methods that perform tasks Return information after task completion –Used to build Java programs Java contains class libraries –Known as Java APIs (Application Programming Interfaces)

4 4 Basics of a Typical Java Environment Java programs normally undergo five phases –Edit Programmer writes program (and stores program on disk) –Compile Compiler creates bytecodes from program –Load Class loader stores bytecodes in memory –Verify Verifier ensures bytecodes do not violate security requirements –Execute Interpreter translates bytecodes into machine language

5 5 Typical Java environment. Primary Memory............ Disk Editor Compiler Class Loader Program is created in an editor and stored on disk in a file ending with.java. Compiler creates bytecodes and stores them on disk in a file ending with.class. Class loader reads.class files containing bytecodes from disk and puts those bytecodes in memory. Phase 1 Phase 2 Phase 3 Primary Memory............ Bytecode Verifier Bytecode verifier confirms that all bytecodes are valid and do not violate Java’s security restrictions. Phase 4 Primary Memory............ Interpreter Interpreter reads bytecodes and translates them into a language that the computer can understand, possibly storing data values as the program executes. Phase 5

6 6 Thinking About Objects Object-oriented design (OOD) –Models real-world objects –Models communication among objects –Encapsulates attributes and operations (behaviors) Information hiding Communication through well-defined interfaces Object-oriented language –Programming in object oriented languages is called object-oriented programming (OOP) –Java

7 7 Thinking About Objects Object-Oriented Analysis and Design (OOA/D) –Essential for large programs –Analyze program requirements, then develop solution –UML Unified Modeling Language

8 8 Chapter 2 Programs A First Program in Java: Printing a Line of Text Modifying Our First Java Program Displaying Text in a Dialog Box Another Java Application: Adding Integers Memory Concepts Arithmetic Decision Making: Equality and Relational Operators

9 9 Discuss four small Java programs Welcome1.java Welcome2.java Welcome3.java Welcome4.java

10 10 Escape characters –Backslash ( \ ) –Indicates special characters be output

11 11 Another Java Application: Adding Integers Addition.java

12 12 Memory Concepts Visual Representation –Sum = 0; number1 = 1; number2 = 2; –Sum = number1 + number2; after execution of statement sum0 3

13 13 Arithmetic Arithmetic calculations used in most rograms –Usage * for multiplication / for division +, - No operator for exponentiation (more in Chapter 5) –Integer division truncates remainder 7 / 5 evaluates to 1 –Remainder operator % returns the remainder 7 % 5 evaluates to 2

14 14 Arithmetic Operator precedence –Some arithmetic operators act before others (i.e., multiplication before addition) Use parenthesis when needed –Example: Find the average of three variables a, b and c Do not use: a + b + c / 3 Use: ( a + b + c ) / 3 –Follows PEMDAS Parentheses, Exponents, Multiplication, Division, Addition, Subtraction

15 15 Arithmetic

16 16 Decision Making: Equality and Relational Operators

17 17 Precedence of operators


Download ppt "1 Chapter 1 Java –Originally for intelligent consumer-electronic devices –Then used for creating Web pages with dynamic content –Now also used for: Develop."

Similar presentations


Ads by Google