Presentation is loading. Please wait.

Presentation is loading. Please wait.

 2005 Pearson Education, Inc. All rights reserved. 1 Introduction & The Java Virtual Machine Small Java Chapter 1 1.

Similar presentations


Presentation on theme: " 2005 Pearson Education, Inc. All rights reserved. 1 Introduction & The Java Virtual Machine Small Java Chapter 1 1."— Presentation transcript:

1  2005 Pearson Education, Inc. All rights reserved. 1 Introduction & The Java Virtual Machine Small Java Chapter 1 1

2  2005 Pearson Education, Inc. All rights reserved. Machine Languages, Assembly Languages and High-Level Languages Machine language – 1’s and 0’s – Machine dependent Assembly language – English-like abbreviations represent computer operations – Translator programs convert to machine language – ADD 12,14 High-level language – Allows for writing more “English-like” instructions – Contains commonly used mathematical operations – Compiler converts to machine language – If X < 12 THEN … Interpreter – Execute high-level language programs without compilation 2

3  2005 Pearson Education, Inc. All rights reserved. FORTRAN, COBOL, Pascal and Ada FORTRAN – FORmula TRANslator COBOL – COmmon Business Oriented Language Pascal – Structured programming Ada – Multitasking 3

4  2005 Pearson Education, Inc. All rights reserved. BASIC, Visual Basic, Visual C++, C# and.NET BASIC – Beginner’s All-Purpose Symbolic Instruction Code.NET –.NET platform Visual Basic.NET – Based on BASIC Visual C++ – Based on C++ C# – Based on C++ and Java 4

5  2005 Pearson Education, Inc. All rights reserved. History of Java – Originally for intelligent consumer-electronic devices – Then used for creating Web pages with dynamic content – Now also used to: Develop large-scale enterprise applications Provide applications for consumer devices (cell phones, etc.) 5

6  2005 Pearson Education, Inc. All rights reserved. Java Is Not JavaScript! Java is a programming language. You write programs in it and compile them. Javascript is imbedded in a web page and run by Internet Explorer or Firefox Java applets are programs that run in a web browser We will only get to Java applications 6

7  2005 Pearson Education, Inc. All rights reserved. With C++ and most compiled languages 7 Compiler For Windows PC Your Program If x = 5 then… 1011 0011 PC with Windows Compiler For Mac 0011 1111 Mac Source Code

8  2005 Pearson Education, Inc. All rights reserved. Java Virtual Machine 8 Java Compiler Your Program If x = 5 then… 1011 0011 PC with Windows ByteCode Windows JVMMac JVM 0011 1111 Mac Source Code

9  2005 Pearson Education, Inc. All rights reserved. Java Virtual Machine Why and how is this different? Write once, run anywhere – Bytecode is a ‘universal language’ Why isn’t all software written like this? – Xbox 360 games would work on PS 3… 9

10  2005 Pearson Education, Inc. All rights reserved. Software Engineering Observation Use a building-block approach to create programs. Avoid reinventing the wheel—use existing pieces wherever possible. Called software reuse, this practice is central to object-oriented programming. 10

11  2005 Pearson Education, Inc. All rights reserved. Java Class Libraries Classes – Include methods (functions) that perform tasks Return information after task completion – Used to build Java programs Java provides class libraries (of functions or methods) – Known as Java APIs (Application Programming Interfaces) – The stuff built-in to Java – Don’t re-invent the wheel! 11

12  2005 Pearson Education, Inc. All rights reserved. Software Engineering Observation When programming in Java, you will typically use the following building blocks: Classes and methods from class libraries, Classes and methods you create yourself Classes and methods that others create and make available to you. 12

13  2005 Pearson Education, Inc. All rights reserved. Performance Tip Using Java API classes and methods instead of writing your own versions can improve program performance, because they are carefully written to perform efficiently. This technique also shortens program development time. 13

14  2005 Pearson Education, Inc. All rights reserved. Typical Java Development 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 Bytecode Verifier confirms bytecodes do not violate security restrictions – Execute JVM translates bytecodes into machine language 14

15  2005 Pearson Education, Inc. All rights reserved. 15 Fig. 1.1 | Typical Java development environment.

16  2005 Pearson Education, Inc. All rights reserved. Common Programming Error Errors like division by zero occur as a program runs, so they are called runtime errors or execution-time errors. Fatal runtime errors cause programs to terminate immediately without having successfully performed their jobs. Nonfatal runtime errors allow programs to run to completion, often producing incorrect results. 16

17  2005 Pearson Education, Inc. All rights reserved. Good Programming Practice Your computer and compiler are good teachers. Study each error or warning message you get when you compile your programs (called compile-time errors or compilation errors), and correct the programs to eliminate these messages. 17

18  2005 Pearson Education, Inc. All rights reserved. Portability Tip It is easier to write portable programs in Java than in other programming languages Portable to other platforms (from X-box to PS3) However, differences between compilers, JVMs and computers can make portability difficult to achieve. Simply writing programs in Java does not guarantee portability. 18

19  2005 Pearson Education, Inc. All rights reserved. Error-Prevention Tip Always test your Java programs on all systems on which you intend to run them, to ensure that they will work correctly for their intended audiences. 19

20  2005 Pearson Education, Inc. All rights reserved. Software Engineering Observation The Java Development Kit comes with source code for the Java API classes to determine how the classes work and to learn additional programming techniques. 20

21  2005 Pearson Education, Inc. All rights reserved. 21 Fig. 1.2 | Opening a Windows XP Command Prompt and changing directories. Using the cd command to change directories File location of the ATM application Test-Driving a Java Application Using Command Line

22  2005 Pearson Education, Inc. All rights reserved. 22 Fig. 1.3 | Using the java command to execute the ATM application.

23  2005 Pearson Education, Inc. All rights reserved. 23 Fig. 1.4 | Prompting the user for an account number. ATM welcome messageEnter account number prompt

24  2005 Pearson Education, Inc. All rights reserved. 24 Fig. 1.5 | Entering a valid PIN number and displaying the ATM application's main menu. Enter valid PINATM main menu

25  2005 Pearson Education, Inc. All rights reserved. 25 Fig. 1.6 | ATM application displaying user account balance information. Account balance information

26  2005 Pearson Education, Inc. All rights reserved. 26 Fig. 1.7 | Withdrawing money from the account and returning to the main menu. ATM withdrawal menu

27  2005 Pearson Education, Inc. All rights reserved. 27 Fig. 1.8 | Checking new balance. Confirming updated account balance information after withdrawal transaction

28  2005 Pearson Education, Inc. All rights reserved. 28 Fig. 1.9 | Ending an ATM transaction session. ATM goodbye message Account number prompt for next user

29  2005 Pearson Education, Inc. All rights reserved. Programming Paradigms Traditional Programming vs. Object Oriented Programming Software objects attempt to model the real world Objects have data (attributes) and behaviors (methods or functions) 29

30  2005 Pearson Education, Inc. All rights reserved. Software Engineering Case Study: Introduction to Object Technology and the UML Object orientation Unified Modeling Language (UML) – Graphical language that uses common notation – Allows developers to represent object-oriented designs 30

31  2005 Pearson Education, Inc. All rights reserved. Software Engineering Case Study (Cont.) Objects – Reusable software components that model real-world items – People, animals, plants, cars, etc. – Attributes Size, shape, color, weight, etc. – Behaviors Babies cry, crawl, sleep, etc. 31

32  2005 Pearson Education, Inc. All rights reserved. Software Engineering Case Study 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 32

33  2005 Pearson Education, Inc. All rights reserved. Software Engineering Case Study Object-Oriented Analysis and Design (OOA/D) – Essential for large programs – Analyze program requirements, then develop solution – UML Unified Modeling Language 33

34  2005 Pearson Education, Inc. All rights reserved. Software Engineering Case Study UML – Graphical representation scheme – Enables developers to model object-oriented systems – Flexible and extensible 34 Player health armor Run (direction) Fire (coordinates) jump


Download ppt " 2005 Pearson Education, Inc. All rights reserved. 1 Introduction & The Java Virtual Machine Small Java Chapter 1 1."

Similar presentations


Ads by Google