Intro
Intro
|
Overview
• Sub divided into two sections:
– Intro to Java: basic Java concepts
Thursday,
August 31,
2017
OOP I | 2
Sections
• Intro to Java: basic Java concepts
Thursday,
August 31,
2017
OOP I | 3
Introduction to Java Programming
|
Objectives
• Describe the basic Java development cycle.
Thursday,
August 31,
2017
OOP I | 5
Java Development Lifecycle
|
Java Development Lifecycle
http://ee402.eeng.dcu.ie/introduction/chapter-5---introduction-to-java
Thursday,
August 31,
2017
OOP I | 7
IDEs for Java
• Netbeans
– Comes configured with JDK
• Eclipse
– Needs configuration for Java
Thursday,
August 31,
2017
OOP I | 8
How do I start coding in Java?
|
Hello World
public class Welcome
System.out.println("Hello World");
|
Primitive Types
• int
• float
• double
• char
|
Output
System.out.println("Hello World");
System.out.print("Hello World\n");
Thursday,
August 31,
2017
OOP I | 15
Input
• Most frequently the Scanner class is used to
implement input functions.
Scanner input = new Scanner(System.in);
Thursday,
August 31,
2017
OOP I | 16
Class Work (15 Minutes)
• Write a java application that will prompt
the user to enter two numbers. The
program should add the two numbers and
display the result to the user.
Thursday,
August 31,
2017
OOP I | 17
Solution
import java.util.Scanner;
public class Addition {
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
int number1;
int number2;
int sum;
Thursday,
August 31,
2017
OOP I | 18
Operators & Control Structures
|
Operators
• Assignment (=)
• Arithmetic (+, -, /, %, *)
Thursday,
August 31,
2017
OOP I | 20
Control Structures
• Selection control structures
– if-else
– for-loop
– do-while
Thursday,
August 31,
2017
OOP I | 21
Write down the
output of this
program
Thursday,
August 31,
2017
OOP I | 22
Class Work (15 Minutes)
• Write a java application that will prompt
the user to enter two integer numbers
– The program should display the largest of
them all
Thursday,
August 31,
2017
OOP I | 23
Sections
• Intro to Java: basic Java concepts
Thursday,
August 31,
2017
OOP I | 24
Introduction to Object-oriented
Programming
|
Objectives
• Explain the concept of OOP.
Thursday,
August 31,
2017
OOP I | 26
Video
• https://www.youtube.com/watch?v=NUl8lcb
eN2Y
Thursday,
August 31,
2017
OOP I | 27
Classifications and Real-world Objects
|
Real World Objects
• Most human beings think in terms of objects.
We can learn about existing objects by studying
their attributes and observing their behaviors.
Thursday,
August 31,
2017
OOP I | 30
Class Demo
• Using the examples below, model a real-
world classification-object structure by
their attributes, behaviors and relationship:
– Vehicle, FastCar, audi, bugatti, vitz
Thursday,
August 31,
2017
OOP I | 31
Class Demo
Classification: Vehicle
Attributes: Doors
Wheels
Behaviors: Starts()
Stops() – in 10 seconds
Thursday,
August 31,
2017
OOP I | 33
Class Exercise (5 Minutes)
Thursday,
August 31,
2017
OOP I | 34
Class Work (15 Minutes)
• Using the examples below, model a real
world classification-object structure by
their attributes, behaviors and
relationships:
– Animal, Carnivore, cow, lion, pig
Thursday,
August 31,
2017
OOP I | 35
Basic Object-oriented design concepts
|
OOP Definitions
• Object-oriented design models software in terms
similar to those people use to describe real-world
objects.
2. Inheritance
3. Polymorphism
4. Data hiding
5. Encapsulation
6. Abstraction
Thursday,
August 31,
2017
OOP I | 38
Object-oriented Design - Classes
1. User-defined types: object-oriented design enables a
programmer to define his/her own custom type (class);
and then use it to create any number of objects.
Objects of a certain class, such as a class of vehicles,
have same characteristics (attributes and behavior).
Thursday,
August 31,
2017
OOP I | 39
Class Demo
• Create the two classes: Automobile and
Convertible. List down their attributes and
behaviors. {user-defined class & inheritance}
– Automobile: attributes & behaviors
Behaviors: Starts()
Stops()
Thursday,
August 31,
2017
OOP I | 41
Object-oriented Design - Classes
3. Polymorphism: This is where new classes first inherit
the characteristics of an existing class and then modify
the behavior of the existing class to suite its own
behavior. This is process is known as overriding
behaviors.
Thursday,
August 31,
2017
OOP I | 42
Class Demo
• From the demo, one can create a class
Nonconvertible that inherits all the attributes and
behaviors of class Convertible.
– Then modify class Nonconvertible so that the roof
stays permanently down. {Polymorphism}
Thursday,
August 31,
2017
OOP I | 44
Class Demo- Data Hiding
Class Automobile
Attributes: Doors: private
Wheels: public
Thursday,
August 31,
2017
OOP I | 45
Object-oriented Design - Objects
5. OOD encapsulates (wraps) attributes and behaviors
into objects. An object’s attributes and operations are
intimately tied together.
Thursday,
August 31,
2017
OOP I | 47
Class Demo
Objects of classes Automobile, Convertible and Nonconvertible
Automobile nissan Has: 4 doors, 4 wheels
nissan.starts(), nissan.stops()
Thursday,
August 31,
2017
OOP I | 48
Class Work (15 Minutes)
• Using the categories listed below and model a
class-object relationship using OOD concepts.
Illustrate inheritance, polymorphism and data
hiding.
– Plant, Flowering, Nonflowering
Thursday,
August 31,
2017
OOP I | 51
Ole Sangale Road, Madaraka Estate. PO Box 59857-00200, Nairobi, Kenya
Tel: (+254) (0)703 034000/200/300 Fax : +254 (0)20 607498
Email: [email protected] Website: www.strathmore.edu
|