Академический Документы
Профессиональный Документы
Культура Документы
Course Content
EE2425 • Review of OOP Fundamentals
Objects Orientated
• Overview of Java and the BlueJ Environment
•Java Language basics
http://math.hws.edu/javanotes/
Java Tutorials
Sun Microsystems created Java and have an
excellent on-line reference known as Java Tutorials
Updated http://java.sun.com/docs/books/tutorial/
Slide
25/02/10 http://java.sun.com/docs/books/tutorial/reallybigindex.html5 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 6
concepts of OOP
All OOP languages adhere to the following key
principles: -
• Encapsulation
• Polymorphism
• Inheritance
Please review the definitions for these given in
computer technology 2 module.
In this module we will implement all three of
these principles
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 7 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 8
Review of the fundamental concepts of OOP Review of the fundamental concepts of OOP
Notes
Review of the fundamental concepts of OOP
Objects and Classes
• Most modern programming languages are
based upon Object Orientated Programming
techniques.
• Applications are designed around the Objects
that are used.
• Code and data for a particular Object is
Encapsulated within Classes.
– A Class is a complex data type that can contain
both data (fields/properties) & functions (methods)
– Generally Classes are not used directly, instead an
instance (copy) is made.
– An Object is an instance of a particular Class.
Objects–First
Many
with Java instances may
- A Practical Introduction usingbe
BlueJ,created from
© David J. Barnes, a Kölling
Michael single class
11 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 12
Objects and Classes Review of the fundamental concepts of OOP
Form1 is an Object:
Properties & Fields
Created from the • These define what values or parameters
Jframe Class.
are associated with the class.
label1 is an Object: – Each object has it’s own set of values
Created from the
Jlabel Class. known as the state of the object.
button1 is an Object: – These are known as instance values or
Created from the instance variables.
Jbutton Class.
– They are Encapsulated into a class and only
act upon a specific Object of that class.
Jframe Form1 = new Jframe(“Form1”); i.e That is each Object has it’s own
Jlabel label1 = new Jlabel(); independent copy of these variables.
Updated
Slide Jbutton button1 = new Jbutton(); 13
Updated
Slide Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 14
28/01/10 28/01/10
Updated
Slide
Example:Two circle objects
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 15 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 16
28/01/10
Review of the fundamental concepts of OOP Review of the fundamental concepts of OOP
Methods Methods
• As well as values, Classes can must also Method Declaration – Optional
contain implementation code General Form parameters
scope return_type MethodName(type Arg1, type Arg2,..)
• This code is contained within special {Implementation code; //Java code to perform required task
functions called Methods. return (return_type); //Returns value (optional)
}
• Methods should only act upon the • scope: public, private, protected, etc
specific instance of the class in which it • return_type: void, int, char, String, etc
was invoked. • parameters: are values that can be passed
• As with functions, Methods may receive when method is called (they are local variables).
arguments, or return a value. – type: void, int, char, String, etc
Updated Updated
Slide
17
Slide – Arg1,Arg2: Name assigned to argument.
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 18
28/01/10 28/01/10
Scope Example
public class Car Visible from
{ outside of class
public String Make,Model,Colour;
private int NumberOfDoors; Only visible
private float EngineSize; from inside class
public void SetDoors(int doors)
{ if doors<6 && doors >1 NumberOfDoors=doors;}
Allows indirect
public int GetDoors(); access to
{ return(NumberOfDoors);}
NumberOfDoors
public abstract void SetEngine(float engine);
public abstract float GetEngine();
}Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 23 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 24
Review of the fundamental concepts of OOP Review of the fundamental concepts of OOP
Notes
Overview of Java
and the BlueJ IDE
• Characteristics of the Java language
– Java history
– What’s different about Java?
– Java program structure
– Writing java from scratch
• Introduction to BlueJ
• Java language basics
27 28
Characteristics of the Characteristics of the Java language
Java History
Java language • 1991:First launched as a OOP language
• Developed by Sun Microsystems for embedded hardware applications.
• Object Orientated language based on C++ Not very popular. Project was endanger of collapse
• First language developed specifically for web. • 1993: Explosion in internet use allowed
• First truly platform independent language. Sun to re-develop Java for use dynamic
• Open source. Web pages.
– Download www.java.sun.com • 1995: Java re-launched for Web
• Hybrid interpreted and compiled modes development
• Computational speed(?) – Java now the principle language used to
– Slower than true compiled language create web pages that have interactive
content.
29 – Also popular for smartcard applications30
Java
Java
Hello.java
Hello.java Hello.class
Hello.class
Compiler
Compiler
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 39 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 40
Introduction to BlueJ Java Language basics
As Java is based on C++ much of the language
• Developed at the University of Southern most syntax should be familiar.
Denmark specifically for the purpose of • Primitive data types
teaching OOP. • Overview
• Casting between primitives
• Provides a simple IDE for Java.
• Operators
– Uses Sun JVM
• Therefore no compatibility problems
– Arithmetic and Assignment operators
• Requires JDK to be present on machine – Relational
• Does require addition of main method to run – Logical
standalone.
– Other Java operators
– Free download available • Control flow statements
– On-line support. • Class-based data types
Objects First with JavaNow try
- A Practical exercise
Introduction using BlueJ, © 2 inJ. Barnes,
David first lab
Michael …
Kölling 41 • Characters & Strings
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 42
Example:
byte 8 –128 to +127
short 16 –32,768 to +32,767
int 32 –2,147,483,648 to
+2,147,483,647
final int MyAge = 21;
long 64 –9,223,372,036,854,775,808 to int Age=0;
+9,223,372,036,854,775,807
float 32 –3.40292347E+38 to (IEEE 754 floating
double
+3.40292347E+38
–1.79769313486231570E+308
point)
(IEEE 754 floating
Age++; //Variable Age would be incremented
64 to
+1.79769313486231570E+308
point) MyAge++; //This would produce a compiler error
Note: Float values out of range are return ± infinity
Non numerical values return NaN (Not a Number)
Note: As with C there is no String data type.
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 45 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling 46
See Java tutorial webpages for more details See Java tutorial webpages for more details
Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling
53 Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling
54
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/bitwise.html http://java.sun.com/docs/books/tutorial/java/nutsandbolts/other.html
Slide
Added
Java Language basics Notes
4/2/10
Input/Output Methods
• Among the facilities provided by the Java System class are
methods that allow the user to access the standard input , and
standard output streams of the computer These are typically
Keyboard and Display.
Output: System.out.println() methods:
A series of overloaded methods that allows data of most
common types to be displayed on the standard output device.
System.out.println(value to be displayed);