1 / 31

Chapter 1 Fundamentals of Java Progra m ming By Ms.Ramsha Sohail

Chapter 1 Fundamentals of Java Progra m ming By Ms.Ramsha Sohail. Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The Memory Usage by a Java Program

ellard
Télécharger la présentation

Chapter 1 Fundamentals of Java Progra m ming By Ms.Ramsha Sohail

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. Chapter1 Fundamentals ofJava Programming By Ms.Ramsha Sohail

  2. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  3. Understand how computers and computer programswork. • Understand how a Java program iswritten, • compiled, andexecuted. • Understand what makes Java platform independent. • Identify the object-oriented features of Java. • Identify different elements of a Java program: primitive variable, reference variable, local variable, instance variable, method, and class.

  4. Identify where in memory the method invocations, objects, and variablesare stored. • Understand how access modifiers define the accessibility of classes and class members. • Understand the concepts of early binding and late binding in the context ofprogram errors.

  5. How a ComputerWorks How a Computer ProgramWorks

  6. From a computer program’s perspective, a computer consists of components to dothe following: • Receive data from auser • Process the data according to instructions froma program or auser • Place the resultssomewhere

  7. Places to Store Data: • Permanent storage: harddrive • Temporary storage:RAM • I/O Devices: monitor, keyboard, disk, and printer • CPU: The Brain of theComputer

  8. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  9. A compiler translates a program in C/C++ to a binary format called executablecode • The executable code is machine dependent • Java programs are machine independent, thanks to Javavirtual machine(JVM).

  10. Writing a JavaProgram • Compiling a JavaProgram • Executing a JavaProgram

  11.  Source code: a set of instructions in text format written according to the rules ofthe Java programminglanguage.  Source file: contains these instructions, and has the file extension .java

  12. Machine language: a binaryformat • In Java, the compiler compiles the source code intobytecode • To create the bytecode files (.class) from the source fileRobotManager.java: • javacRobotManager.java

  13. Executing a Java program by issuingthe • javacommand: • java RobotManager Ginny420 • The JVM reads the bytecode file and translates the instructions to the executable format that your computercan understand

  14. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  15. Classes andObjects • Methods • Variables and DataTypes • Execution Flow of aProgram

  16. A class is a template (or a blueprint) from which objects arecreated • Writing a class is called implementing a class: declaration &body • An object is instantiated from a class, and also called the instance of thatclass • Each object has a state, a set of characteristics, and a behavior represented bymethods

  17. The state of an object is represented by a set of data items that are handled byusing variables • The variable’s type determines whatkind • of values it canhold • The declaration of avariable: • <type> <name>; • An object reference variable refer to an object: • Robotrobot;

  18. Expressions: combination of variables, operators, literals, and methodcalls • Statements: a complete execution unitof • a program; contain one ormore expressions • Blocks: a group of zero ormore • statements between an opening braceand a closingbrace • Execution Flow Control: skip, execute,or • repeatedly execute a block ofstatements

  19. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  20. PlatformIndependence • Object-OrientedProgramming

  21. “write once, runanywhere.” • The Java compiler compiles the source code into bytecode, which can be interpreted by a suitable JVM on any platform • The JVM can prevent the code from generating side effects outside thesystem.

  22. Encapsulation: combining an object’s data with itsmethods • Inheritance: • Codereusability • Codemaintenance • ImplementingOOP • Polymorphism: allows an object of a superclass to refer to an object ofany • subclass.

  23. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  24. Class members: variables, methods, and nestedclasses. • Access modifiers: control the access to the classmembers • public • protected • default • private

  25. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  26. Computers and ComputerProgramming • Writing and Executing a JavaProgram • Elements of a JavaProgram • Features ofJava • Accessing the Classes and Class Members • The Memory Usage by a JavaProgram • When Will the ErrorOccur?

  27. Compilationfails • An exception is thrown atruntime

More Related