1 / 34

Introduction & The Java Virtual Machine Small Java Chapter 1

Introduction & The Java Virtual Machine Small Java Chapter 1. 1. 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

ava-wynn
Download Presentation

Introduction & The Java Virtual Machine Small Java Chapter 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction & The Java Virtual Machine Small Java Chapter 1 1

  2. 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

  3. FORTRAN, COBOL, Pascal and Ada • FORTRAN • FORmula TRANslator • COBOL • COmmon Business Oriented Language • Pascal • Structured programming • Ada • Multitasking

  4. 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

  5. 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.)

  6. 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

  7. With C++ and most compiled languages Your Program If x = 5 then… Source Code Compiler For Mac Compiler For Windows PC 0011 1111 1011 0011 Mac PC with Windows

  8. Java Virtual Machine Your Program If x = 5 then… Source Code Java Compiler ByteCode Windows JVM Mac JVM 1011 0011 0011 1111 PC with Windows Mac

  9. 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…

  10. 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.

  11. 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!

  12. 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.

  13. 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.

  14. 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

  15. Fig. 1.1 | Typical Java development environment.

  16. 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.

  17. 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.

  18. 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.

  19. 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.

  20. 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.

  21. Test-Driving a Java Application Using Command Line Using the cd command to change directories File location of the ATM application Fig. 1.2 | Opening a Windows XP Command Prompt and changing directories.

  22. Fig. 1.3 | Using the java command to execute the ATM application.

  23. ATM welcome message Enter account number prompt Fig. 1.4 | Prompting the user for an account number.

  24. Enter valid PIN ATM main menu Fig. 1.5 | Entering a valid PIN number and displaying the ATM application's main menu.

  25. Account balance information Fig. 1.6 | ATM application displaying user account balance information.

  26. ATM withdrawal menu Fig. 1.7 | Withdrawing money from the account and returning to the main menu.

  27. Confirming updated account balance information after withdrawal transaction Fig. 1.8 | Checking new balance.

  28. Account number prompt for next user ATM goodbye message Fig. 1.9 | Ending an ATM transaction session.

  29. 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)

  30. 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

  31. 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.

  32. 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

  33. 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

  34. Software Engineering Case Study Player health armor Run (direction) Fire (coordinates) jump • UML • Graphical representation scheme • Enables developers to model object-oriented systems • Flexible and extensible

More Related