An Introduction to Computers and Java

48 slides
0.62 MB

Similar Presentations

Presentation Transcript


Introduction to Computers and JavaChapter 1


RecitationReview of important material or relevant material not yet covered Introduction to projects A chance to ask questions Come prepared and participate A quiz every week


CompilersA compiler translates a program from a high-level language to a low-level language the computer can run. You compile a program by running the compiler on the high-level-language version of the program called the source program. Compilers produce machine- or assembly-language programs called object programs.


Java Byte-CodeThe Java compiler does not translate a Java program into assembly language or machine language for a particular computer. Instead, it translates a Java program into byte-code. Byte-code is the machine language for a hypothetical computer (or interpreter) called the Java Virtual Machine.


Java Byte-Code, cont.A byte-code program is easy to translate into machine language for any particular computer. A program called an interpreter translates each byte-code instruction, executing the resulting machine-language instructions on the particular computer before translating the next byte-code instruction.


Compiling, Interpreting, RunningUse the compiler to translate the Java program into byte-code (done using the compile command). Use the byte-code interpreter for your computer to translate each byte-code instruction into machine language and to run the resulting machine-language instructions (done using the run command).


PortabilityAfter compiling a Java program into byte-code, that byte-code can be used on any computer with a byte-code interpreter and without a need to recompile. Byte-code can be sent over the Internet and used anywhere in the world. This makes Java suitable for Internet applications.


ProgrammingProgramming is a creative process. Programming can be learned by discovering the techniques used by experienced programmers. These techniques are applicable to almost every programming language, including Java.


Object-Oriented ProgrammingOur world consists of objects (people, trees, cars, cities, airline reservations, etc.). Objects can perform actions which affect themselves and other objects in the world. Object-oriented programming (OOP) treats a program as a collection of objects that interact by means of actions.


OOP Design PrinciplesOOP adheres to three primary design principles: encapsulation polymorphism inheritance.


Introduction to EncapsulationThe data and methods associated with any particular class are encapsulated (“put together in a capsule”), but only part of the content is made accessible. Encapsulation provides a means of using the class, but it omits the details of how the class works. Encapsulation often is called information hiding.


Accessibility ExampleAn automobile consists of several parts and pieces and is capable of doing many useful things. Awareness of the accelerator pedal, the brake pedal, and the steering wheel is important to the driver. Awareness of the fuel injectors, the automatic braking control system, and the power steering pump are not important to the driver.


Introduction to Polymorphismfrom the Greek meaning “many forms” The same program instruction adapts to mean different things in different contexts. A method name, used as an instruction, produces results that depend on the class of the object that used the method. everyday analogy: “throw me the ball” causes different people to do different activities more about polymorphism in Chapter 7


Introduction to InheritanceClasses can be organized using inheritance.


Introduction to Inheritance, cont.A class at a lower level inherits all the characteristics of classes above it in the hierarchy. At each level, classifications become more specialized by adding other characteristics. Higher classes are more inclusive; lower classes are less inclusive.


Inheritance in Javaused to organize classes “Inherited” characteristics do not need to be repeated. New characteristics are added. more about inheritance in Chapter 7


Reusable ComponentsMost programs are created by combining components that exist already. Reusing components saves time and money. Reused components are likely to be better developed, and more reliable. New components should be designed to be reusable by other applications.


Making Components ReusableSpecify exactly how objects of the class interact with other objects. Design a class so that objects are general, rather than unique to a particular application.


Testing and DebuggingEliminate errors by avoiding them in the first place. Carefully design classes, algorithms, and methods. Carefully code everything into Java. Test your program with appropriate test cases (some where the answer is known), discover and fix any errors, then retest.


ErrorsAn error in a program is called a bug. Eliminating errors is called debugging. three kinds or errors syntax errors runtime errors logic errors


Syntax Errorsgrammatical mistakes in a program the grammatical rules for writing a program are very strict The compiler catches syntax errors and prints an error message. example: using a period where a program expects a comma


Runtime Errorserrors that are detected when your program is running, but not during compilation When the computer detects an error, it terminates the program and prints an error message. example: attempting to divide by 0


Logic Errorserrors that are not detected during compilation or while running, but which cause the program to produce incorrect results example: an attempt to calculate a Fahrenheit temperature from a Celsius temperature by multiplying by 9/5 and adding 23 instead of 32


History of JavaIn 1991, James Gosling and Sun Microsystems began designing a language for home appliances (toasters, TVs, etc.). challenging, because home appliances are controlled by many different chips (processors) Programs were translated first into an intermediate language common to all appliance processors.


History of Java, cont.Then the intermediate language was translated into the machine language for a particular appliance’s processor. Appliance manufacturers weren’t impressed. In 1994, Gosling realized that his language would be ideal for a Web browser that could run programs over the Internet. Sun produced the browser known today as HotJava.

Browse More Presentations

Last Updated: 8th March 2018

Recommended PPTs