Chapter 1 - Introduction
Chapter 1 - Introduction
2018
Advanced Programming
Code: SWEG2033
Chapter One
Revision (Points to Recall)
o Class
o Inheritance
o Polymorphism
o Abstraction
o Encapsulation
1
05.03.2018
• The language OAK was developed by James Gosling with the goal of
using C++’s popularity.
2
05.03.2018
3
05.03.2018
4
05.03.2018
• Object means a real word entity such as pen, chair, table etc.
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
10
5
05.03.2018
Have 2 point.
11
12
6
05.03.2018
Object
• An object has three characteristics:
• state: represents data (value) of an object.
• behavior: represents the behavior (functionality) of an object such as deposit, withdraw etc.
• identity: Object identity is typically implemented via a unique ID. The value of the ID is not
visible to the external user. But, it is used internally by the JVM to identify each object
uniquely.
• For Example: Pen is an object. Its name is lexine, color is white etc. known as
its state. It is used to write, so writing is its behavior.
13
Object
• Represent ‘things/objects’ from the real world, or from some problem
domain (example: “the red car down there in the car park”)
14
7
05.03.2018
Object
From the above facts Object can be Definitions :
• Object is a real world entity.
• Object is a run time entity.
• Object is an entity which has state and behavior.
• Object is an instance of a class.
15
16
8
05.03.2018
17
Class
• Class Declaration
• The syntax for a simple class declaration is
18
9
05.03.2018
Class
Class Activity Q2: 1.5 point
class test1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
}
}
Is Empty .java file name a valid source file name for the above code?
19
String name;
System.out.println(s1.id);
System.out.println(s1.name);
20
10
05.03.2018
class TestStudent1{
public static void main(String args[]){
Student s1=new Student();
System.out.println(s1.id);
System.out.println(s1.name);
}
}
21
22
11
05.03.2018
class Student {
int id ;
String name;
}
class TestStudent {
public static void main(String[] args) {
Student s1 = new Student();
s1.id = 1234;
s1.name= "Kebede Megersa Zebre";
System.out.println("Full Name :" + s1.name );
System.out.println("ID : "+ s1.id);
}
23
In this example, we are creating the two objects of Student class and initializing the value to these objects
by invoking the insertRecord method. Here, we are displaying the state (data) of the objects by invoking the
displayInformation() method.
class Student{
int rollno;
String name;
void insertRecord(int r, String n){
rollno=r;
name=n;
}
void displayInformation(){System.out.println(rollno+" "+name);}
}
class TestStudent4{
public static void main(String args[]){
Student s1=new Student();
Student s2=new Student();
s1.insertRecord(111,"Kasa Haylu");
s2.insertRecord(222,"Lechiso Gebremeskel");
s1.displayInformation();
s2.displayInformation();
}
}
24
12
05.03.2018
25
26
13
05.03.2018
27
28
14
05.03.2018
29
Abstraction
• Hiding internal details and showing functionality is known as
abstraction. For example: phone call, we don't know the internal
processing. In java, we use abstract class and interface to achieve
abstraction.
30
15
05.03.2018
31
• The two main objects in this problem are the video and the customer.
• Then, specify for each object the relevant data and possible operations to be
performed on that data.
• For a video object, the data might include: movie name, starring actors, producer,
production company, number of copies in stock
32
16
05.03.2018
33
• Inheritance
• Polymorphism
34
17
05.03.2018
35
36
18
05.03.2018
37
38
19
05.03.2018
Class Activity Q 5
39
Variables
• A variable has a type and holds a single value while the object may
contain many variables
20
05.03.2018
Variables (cnt’d)
• Besides reference types, there are eight other types in Java. These
are called primitive types, to distinguish them from reference
types - to store the locations of objects in the computer’s memory.
41
Variables (cnt’d)
Class Activity Q6
42
21
05.03.2018
• If you do not follow the rules when writing a program, the computer will
be unable to understand it.
• The Java language specification and Java API define the Java standard.
• The Java language specification is stable, but the API is still expanding.
43
• Java Micro Edition (Java ME) - to develop applications for mobile devices
• Besides JDK, you can use a Java development tool (e.g., Net-Beans,
Eclipse, etc) – provides IDE
44
22
05.03.2018
Assignments
45
Review Exercise
46
23
05.03.2018
Review Exercise
47
24