Upload
kynton
View
17
Download
0
Embed Size (px)
DESCRIPTION
CMSC 202. Computer Science II for Majors Object-Oriented Programming. Instructors. Mr. Dennis Frey Sections 0101 – 0105 Tues/Thurs 10:00am – 11:15am LH 4 (ACIV) Mr. Sa’ad Raouf Sections 0201 - 0205 Mon/Wed 5:30pm – 6:45pm LH 2 (CHEM). Course Co-ordination. - PowerPoint PPT Presentation
Citation preview
CMSC 202
Computer Science II for Majors
Object-Oriented Programming
Aug 24, 2007 2
Instructors
Mr. Dennis FreySections 0101 – 0105Tues/Thurs 10:00am – 11:15amLH 4 (ACIV)
Mr. Sa’ad RaoufSections 0201 - 0205Mon/Wed 5:30pm – 6:45pmLH 2 (CHEM)
Aug 24, 2007 3
Course Co-ordination
All sections are assigned the same projects All sections are assigned the same labs All sections get the same lecture material, but
exams are different. You must take the exam given by your instructor
Aug 24, 2007 4
What is CMSC 202?
CMSC 202 is an introduction to Object-Oriented programming using the Java programming language
Course websitewww.cs.umbc.edu/courses/undergraduate/202/fall07
Aug 24, 2007 5
Eclipse
An integrated development environment (IDE) for writing Java programs
Free download for your PC See course “Resources” page
Available in all OIT labs around campus We’ll show you more in lab 1
Aug 24, 2007 6
What is OOP?
Object-Oriented Programming (OOP) is a different way of thinking about a programming problem.
Rather than looking at a problem as some data and functions (procedures) that manipulate that data, we look at a problem and think about what “things” (objects) must be represented in the problem What are the attributes/properties/characteristics of each
object What are the behaviors of each object
Aug 24, 2007 7
More OOP
How is OOP different than programming in a language like C?
With C, your program consists of lots of functions being called from main, or calling each other. Functions are the focus.
With OOP (using Java/C++) your program consists of lots of objects used to represent “things” in your program. The objects use each other’s services.
Aug 24, 2007 8
What’s an Object? A bundle of related
data which make up the object’s “state” operations which define the objects “behavior”
Data are referred to as “instance variables” Operation are referred to as “methods”
Aug 24, 2007 9
Object Examples Bank Account
State: account number, owner’s name, balance, interest rate, etc
Operations: deposit, withdraw, transfer, etc Student
State: name, ID, birthday, major Operations: compute age, compute tuition, lookup grades
String State: sequence of characters Operations: compute length, test for equality, concatenate,
etc.
Aug 24, 2007 10
What is Java?
Created by Sun Microsystems team led by James Gosling (1991)
Originally designed for programming home appliances Difficult task because appliances are controlled by
a wide variety of computer processors Team developed a two-step translation process to
simplify the task of compiler writing for each class of appliances
Aug 24, 2007 11
Significance of Java translation process Writing a compiler (translation program) for each
type of appliance processor would have been very costly
Instead, developed intermediate language that is the same for all types of processors : Java byte-code
Therefore, only a small, easy to write program was needed to translate byte-code into the machine code for each processor
Aug 24, 2007 12
Why Java?
Popular Modern Language Used in many applications Desirable Features
Object-oriented Garbage Collection Portability of Byte Code Simpler GUI programming
Aug 24, 2007 13
Java is an Object-Oriented Language
Programming methodology that views a program as consisting of objects that interact with one another by means of actions (called methods)
Objects of the same kind are said to have the same type or be in the same class
Other high-level languages have constructs called procedures, methods, functions, and/or subprograms These types of constructs are called methods in Java All programming constructs in Java, including methods, are
part of a class
Aug 24, 2007 14
Java Applications
There are two types of Java programs: applications and applets
A Java application program or "regular" Java program is a class with a method named main When a Java application program is run, the run-
time system automatically invokes the method named main
All Java application programs start with the main method
Aug 24, 2007 15
Applets
A Java applet (little Java application) is a Java program that is meant to be run from a Web browser Can be run from a location on the Internet Can also be run with an applet viewer program for
debugging Applets always use a windowing interface
In contrast, application programs may use a windowing interface or console (i.e., text) I/O
Aug 24, 2007 16
Java Byte-Code The compilers for most programming languages
translate high-level programs directly into the machine language for a particular computer Since different computers have different machine
languages, a different compiler is needed for each one In contrast, the Java compiler translates Java
programs into byte-code, a machine language for a fictitious computer called the Java Virtual Machine (JVM) Once compiled to byte-code, a Java program can be used
on any computer, making it very portable
Aug 24, 2007 17
Java Virtual Machine
The JVM is the program that translates a program written in Java byte-code into the machine language for a particular computer when a Java program is executed The JVM translates and immediately executes
each byte-code instruction, one after another Translating byte-code into machine code is
relatively easy compared to the initial compilation step
Aug 24, 2007 18
Compiling and Running C/C++
C/C++ Code
Linux binary
Windowsbinary
Linux executable
Windowsexecutable
Project Library for Linux
Project Library for WindowsLinux C/C++ compiler
Windows C/C++
compiler
Linux C/C++ linker
Windows C/C++ linker
Aug 24, 2007 19
Compiling and Running Java
JavaCode
JavaBytecode
JRE for Linux
JRE for Windows
Java compiler
Hello.java
javac Hello.java
Hello.class
java Hello
java Hello
Java interpreter translates bytecode to machine code in JRE
Aug 24, 2007 20
Java Terminology
The Java acronyms are plentiful and confusing. Here are the basics.
JRE – Java Runtime Environment This is the Java Virtual Machine (JVM) that executes your Java
byte code JDK (formerly SDK) – Java Development Kit
JRE + tools (compiler, debugger) for developing Java applications and applets
J2SE – Java 2 Platform, Standard Edition The JRE and JDK products taken as a “family”
JSE API – application programming interface for the class libraries included with the JSE
To learn more about JDK, JRE, etc, visithttp://java.sun.com/javase/technologies/index.jsp
Aug 24, 2007 21
Java Versions
The current version of Java is Java 6, also known as Java 1.6 or Java 1.6.0 This is the version running on GL servers
The previous version was Java 5, also known as Java 1.5, Java 1.5.0 or “Java 2 SE Version 5” This is the recommended version for your PC/laptop
To learn find what version is on your PC/laptop, visit http://www.javatester.org/version.html
To learn more about Java version naming, visit http://java.sun.com/javase/namechange.html