1 / 36

Chapter 1

Chapter 1. Introduction to Computers and Java. Chapter 1. 1.1 Computer Basics 1.2 A Sip of Java 1.3 Programming Basics 1.4 Graphics Supplement. 1.1 Computer Basics. The CPU is the brain. Memory is the storage. RAM is volatile. Secondary memory is permanent.

Download Presentation

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. Chapter 1 Introduction to Computers and Java

  2. Chapter 1 1.1 Computer Basics 1.2 A Sip of Java 1.3 Programming Basics 1.4 Graphics Supplement

  3. 1.1Computer Basics

  4. The CPU is the brain

  5. Memory is the storage

  6. RAM is volatile

  7. Secondary memory is permanent

  8. Memory is byte addressable 4 byte memory location at address 8 bits = 1 byte

  9. Programmers writeprograms

  10. Computers executeprograms

  11. Programs must betranslated Java code Machine code

  12. Using a Compiler<Compile once – run many> Assembly codeLow level Source codeHigh level Compiler Binary codeMachine level

  13. Using an Interpreter<Compile-run cycle> Assembly codeLow level Binary codeMachine level Programexecution Source codeHigh level Interpreter

  14. The Java way usesboth techniques Java Virtual Machine<Interpreter>

  15. A class loader combinesall the bytecode files

  16. 1.2A Sip of Java

  17. Text Application Deconstructed<FirstProgram.java> Program uses the scanner class import java.util.Scanner; public class FirstProgram { public static void main(String[] args) { Inform the user System.out.println("Please enter two numbers and"); System.out.println("I will compute their sum."); Declare variables int n1; int n2; Read from the keyboard Scanner keyboard = new Scanner(System.in); n1 = keyboard.nextInt(); n2 = keyboard.nextInt(); Give user an answer System.out.println("Their sum is"); System.out.println(n1 + n2); }// end main() }// end FirstProgram

  18. Text Application Deconstructed<output> Please enter two numbers and I will compute their sum. 10 30 Their sum is 40

  19. GUI Program Deconstructed<HappyFace.java> Classes we need for GUI programs package happyface; import javax.swing.JFrame; import java.awt.Graphics; public class HappyFaceApplet extends JFrame{ @Override public void paint(Graphics canvas) { } } Using drawing commands canvas.drawOval(100, 50, 200, 200); canvas.fillOval(155, 100, 10, 20); canvas.fillOval(230, 100, 10, 20); canvas.drawArc(150, 160, 100, 50, 180, 180);

  20. GUI Program Deconstructed<HappyFace.java> Set window's initial width and height public HappyFace() { setSize(600, 400); setDefaultCloseOperation(EXIT_ON_CLOSE); }// end HappyFace() Exit program when window is closed. public static void main(String[] args) { HappyFaceguiWindow = new HappyFace(); guiWindow.setVisible(true); }// end main() }// end HappyFace Initialize the window and make it visible

  21. 1.3Programming Basics

  22. Java is OO

  23. Objects can representmany things

  24. A class providesthe blueprint

  25. OOP is based onthree pillars Encapsulation Polymorphism Inheritance

  26. Encapsulation = Information Hiding You can drive a car, but you may not know how an engine works.

  27. Inheritance = Reuse / Extend Objects can be reused Objects can be extended

  28. Polymorphism = React in own way Come back!

  29. Before coding beginsdevelop your algorithms Algorithms come inmany flavors

  30. Once coding beginsbe aware of bugs Syntax – Grammar not followed Run-time – Computer can't honor request Logic – Programmer slip

  31. 1.4Graphics Supplement

  32. The Coordinate System (0,0) X (100, 50) Y

  33. Drawing an Oval (0,0) X (100, 50) Y canvas.drawOval(100, 50, 100, 100);

  34. Filling an Oval (0,0) X (100, 50) Y canvas.fillOval(155, 100, 10, 20);

  35. Filling an Oval (0,0) X (100, 50) Y canvas.fillOval(230, 100, 10, 20);

  36. Drawing an Arc (0,0) X (150, 160) Y canvas.drawArc(150, 160, 100, 50, 180, 180);

More Related