SlideShare a Scribd company logo
Object Oriented Programming-Java
Rebaz M. Nabi
Email: rebazmala86@gmail.com
1
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
Class Policy
RESPECT
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
2
Background
• Deitel, H.M. & Deitel, P.J. (2009). Java: How to Program. Prentice Hall (8th
ed.).
• Flanagan, D. (2005). Java in a nutshell : a desktop quick reference. O’Reilly
(5th ed.).
• Flanagan, D. (2004). Java examples in a nutshell : a tutorial companion to
Java in a nutshell. O’Reilly (3rd ed.).
• Gamma, E., Helm, R., Johnson, R. & Vlissides, A. (1995). Design patterns:
elements of reusable object-oriented software. Addison-Wesley.
• Bloch, J. & Gafter, N. (2005). Java puzzlers. Addison-Wesley.
• Object Oriented Modeling and Design with UML Michael Blaha and James
Rambaugh – PEARSON second edition.
• UML Distilled: A Brief Guide to the Standard Object Modeling Language
(3rd Edition) by Martin Fowle.
• Douglas Bell. Software Engineering. Third Edition. 2000.
• Cay Horstmann, “ Big Java”, 3rd Edition, John Wiley and Sons, 2008, ISBN:
978-0-470-10554-2
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
3
Objectives
• The goal of this course is to provide students with the
ability to write programs in Java and make use of the
concepts of Object-Oriented Programming (the principles
of OOP which is inheritance, polymorphism, abstract, and
encapsulation). Examples and discussions will use Java
primarily, but other languages may be used to illustrate
specific points where appropriate. As well as this course
considered the GUI programs in java and JDBC to access
database applications from java code. The course is
designed to accommodate students with diverse
programming backgrounds; it is taught with a mixture of
lectures and practical sessions where students can work at
their own pace from a course handbook. Each practical
class will culminate in an assessed exercise.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
4
Aims
After learning the course the students should be able to:
• Be familiar with the main features and limitations of the Java
language;
• Be able to write a Java program to solve a well specified problem;
• Understand the principles of OOP;
• Understand how to use GUI components in Java
• Be able to demonstrate good object-oriented programming skills in
Java;
• Be able to describe, recognise, apply and implement selected
design patterns in Java;
• Develop database-driven applications
• Identify exception handling methods.
• Implement multithreading in object oriented programs.
• Prepare UML diagrams for software system
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
5
Course Content
• Revision of principles of programming in java
• Principles of Object-Oriented Programming
• Classes and Objects in Java
• Graphical User Interface
• Encapsulation and inner class
• Packages and Standard libraries
• Interface and Abstract class
• Exceptions Handling
• Input Output stream
• Java Database Connectivity JDBC
• Collection Classes
• Concurrent programming
• Software Testing and Flow Diagram
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
6
Basic Definitions
• A computer is a machine that performs
calculations and processes information
– A computer works under the control of a computer
program
• A computer program is a set of instructions that
tell a computer what to do
• Hardware refers to the electronic and mechanical
components of a computer
• Software refers to the programs that control the
hardware
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
7
Computers
HardwareSoftware
Computers
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
8
Hardware
• A computer's hardware is organized into
several main subsystems or components
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
9
Software
• There are two main types of software:
• Application software
– designed to provide a particular task or service
– word processors, computer games, spreadsheet programs,
and Web browsers
• System software
– includes programs that perform the basic operations that
make a computer usable
– An example of the system software is operating systems,
which contains programs that manage the data stored on
the computer's disks, such as Windows or Linux
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
10
Programming Languages
• Programmers write instructions in various programming
languages, some directly understandable by computers and
others requiring intermediate translation steps. Hundreds of
computer languages are in use today. These may be divided
into three general types:
1. Machine languages( Numbers)
2. Assembly languages ( Keywords)
3. High-level languages(Close to Human English )
4. New Generation Languages
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
11
Machine languages
• Any computer can directly understand only its own
machine language. Machine language is the "natural
language" of a computer and as such is defined by its
hardware design. Machine languages generally consist
of strings of numbers (ultimately reduced to 1s and 0s)
that instruct computers to perform their most
elementary operations one at a time.
Samples
– +1300042774
– +1400593419
– +1200274027
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
12
assembly languages
• Machine-language programming was simply too slow
and tedious for most programmers. These
abbreviations formed the basis of assembly languages.
Translator programs called assemblers were developed
to convert early assembly-language programs to
machine language at computer speeds.
• Although such code is clearer to humans, it is
incomprehensible to computers until translated to
machine language.
– load
– add
– store
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
13
High level languages
• To speed the programming process, high-level languages were
developed in which single statements could be written to
accomplish substantial tasks. Translator programs called
compilers convert high-level language programs into machine
language. High-level languages allow programmers to write
instructions that look almost like everyday English and contain
commonly used mathematical notations.
• grossPay = basePay + overTimePay
–
C, C++, Microsoft's .NET languages (e.g., Visual Basic
.NET, Visual C++ .NET and C#) and Java are among the
most widely used high-level programming languages.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
14
Compilers and Interpreters
• The process of compiling a high-level language program into
machine language can take a considerable amount of
computer time. Interpreter programs were developed to
execute high-level language programs directly.
• Translators are used to translate a high-level or source code
program (in C++ or Java) into machine language code or
object code
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
15
Compilers and Interpreters e)
• Source code translators come in two varieties:
– An interpreter translates a single line of source code
directly into machine language and executes the code
before going on to the next line of source code
• for example PHP and Perl.
– A compiler translates the entire source code program
into executable object code. The object code can be
run directly without further translation
• for example C, C++, and Pascal
• Java programs use both compilation and interpretation in
their translation process
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
16
History of Java
• Java evolved from C++, which evolved from C.
• The C language was evolved from B by Dennis
Ritchie(Father of Computer Programming(my point of
view) at Bell Laboratories and was originally implemented
in 1972. It initially became widely known as the
development language of the UNIX operating system.
Today, most of the code for general-purpose operating
systems (e.g., those found in laptops, desktops,
workstations and small servers) is written in C or C++.
• C++, an extension of C, was developed by Bjarne
Stroustrup in the early 1980s at Bell Laboratories (now part
of Lucent). C++ provides a number of features that "spruce
up" the C language, but more important, it provides
capabilities for object-oriented programming
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
17
History of Java (Cont.)
• Microprocessors are having a profound impact in
intelligent consumer-electronic devices. Recognizing
this, Sun Microsystems in 1991 funded an internal
corporate research project code-named Green, which
resulted in the development of a C++-based language
that its creator, James Gosling, called Oak after an oak
tree outside his window at Sun.
• It was later discovered that there already was a
computer language called Oak. When a group of Sun
people visited a local coffee shop, the name Java was
suggested, and it stuck.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
18
Why Java?
 Object Oriented
 Object-oriented languages divide programs into separate modules, called objects,
that encapsulate the program's data and operations
 Robust
 meaning that errors in Java programs don't cause system crashes as often as errors
in other programming languages
 Platform Independent
 Platform is a particular kind of computer system, such as a Macintosh or Windows
system
 Java program can be run without changes on different kinds of computers
 Distributed Language
 which means that its programs can be designed to run on computer networks
 Secure
 Java designed to be used on networks, Java contains features that protect against
untrusted code
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
19
Software Development Process
• source code is written in plain text files with the
.java extension
• source files are then compiled into .class files by
the java compiler
• A .class contains bytecodes: the machine
language of the Java Virtual Machine (Java VM).
• The java runs the application with an instance of
the Java VM
•
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
20
Fundamentals of Programming
in Java
• Java VM is available on many different
operating systems
• The same .class files are capable of running on
– Microsoft Windows
– Solaris OS
– Linux
– Mac OS
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
21
The Java Platforms
• The Java platform runs on top of other hardware-
based platforms like Windows, Linux or Mac OS
• has two components:
– The Java Virtual Machine (VM)
– The Java Application Programming Interface (API)
• The Java Virtual Machine (Java VM) is the base
for the Java platform
• The API is a large collection of software
components grouped into libraries known as
packages
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
22
Write a java program
• The necessary tools are:
– The Java SE Development Kit 8 (JDK) you can download the latest
version here:
– http://www.oracle.com/technetwork/java/javase/downloads/jdk8-
downloads-2133151.html
– For description and how does it work click below link:
– http://docs.oracle.com/javase/7/docs/webnotes/install/index.html
– Text pad( will be provided during practical lectures) or you can
download it here
– http://www.textpad.com/download/
– Eclipse or NetBeans (prefer NetBeans)
• Creating an Application in Windows
– Create a source file in .java extension
– Compile the source file into a .class java compiler
– Run the program
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
23
Java Program Development
• Phase 1.0 : Editor
• Phase 2.0 : Compiler
• Phase 3.1 : Class Loader
• Phase 3.2 : Bytecode Verifier
• Phase 3.3 : Java Virtual Machine
• Program is edited in a text editor, much as a
paper for an English class is edited in a word
processor.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
24
Java Conventions
• About Java programs, it is very important to keep in mind the following
points.
• Case Sensitivity - Java is case sensitive, which means identifier Hello and
hello would have different meaning in Java.
• Class Names - For all class names the first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word's
first letter should be in Upper Case.
Example: class MyFirstJavaClass
• Method Names - All method names should start with a Lower Case letter.
If several words are used to form the name of the method, then each
inner word's first letter should be in Upper Case.
Example: public void myMethodName()
• Program File Name - Name of the program file should exactly match the
class name.
Example : Assume 'MyFirstJavaProgram' is the class name. Then the file
should be saved as 'MyFirstJavaProgram.java’
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
25
Java Identifiers
• All Java components require names. Names used for classes,
variables and methods are called identifiers.
• In Java, there are several points to remember about identifiers.
They are as follows:
• All identifiers should begin with a letter (A to Z or a to z), currency
character ($) or an underscore (_).
• After the first character identifiers can have any combination of
characters.
• A reserved key word cannot be used as an identifier.
• Most importantly identifiers are case sensitive
• Examples of legal identifiers: age, $salary, _value, __1_value
• Examples of illegal identifiers: 123abc, -salary.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
26
Java Modifiers
• Like other languages, it is possible to modify classes, methods,
etc., by using modifiers. There are two categories of
modifiers:
• Access Modifiers: default, public , protected, private
• Non-access Modifiers: final, abstract, static
• We will be looking into more details about modifiers in the
next section.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
27
Java Variables
- Local Variables
• Local variables are visible only within the declared method,
constructor or block.
• Access modifiers cannot be used for local variables.
• There is no default value for local variables so local variables
should be declared and an initial value should be assigned
before the first use.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
28
Java Variables
- InstanceVariables
• Instance variables are declared in a class, but outside a method, constructor or any
block.
• Access modifiers can be given for instance variables.
• The instance variables are visible for all methods, constructors and block in the
class. Normally, it is recommended to make these variables private (access level).
However visibility for subclasses can be given for these variables with the use of
access modifiers.
• Instance variables have default values. For numbers the default value is 0, for
Booleans it is false and for object references it is null. Values can be assigned
during the declaration or within the constructor.
• Instance variables can be accessed directly by calling the variable name inside the
class. However within static methods and different class ( when instance variables
are given accessibility) should be called using the fully qualified name .
ObjectReference.VariableName.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
29
Java Variables
- Class Variables
• Class variables are variables declared with in a class, outside
any method, with the static keyword.
• Access modifiers can be given for instance variables.
• In the case of having static variables or methods, you can
access or use them by using the class’s name following it’s
variable or method name
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
30
Variables
 Definition: a variable is a location in the computer memory
which can store a value of a certain type
 Each variable has a name, a type, a size, and a value.
 Examples of variables: 1 byte
byte age = 22;
short shortNum;
int intNum; age
long longNum;
char mychar;
boolean isMale; Name
value
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
31
22
Java Keywords
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
32
abstract Assert boolean break
byte Case catch char
class Const continue default
do Double else enum
extends Final finally float
for Goto if implements
import Instanceof int interface
long Native new package
private Protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
Volatile while
Comments
• Java statements direct the operations of a program,
while comments are used to help document what
the program does.The Java supports three kinds of
– /* text */
• The compiler ignores everything from /* to */.
– /** documentation */
• This indicates a documentation comment
– // text
• The compiler ignores everything from // to the end of
the line.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
33
Java Data Type
– ** documentation */
• This indicates a documentation comment
– // text
• The compiler ignores everything from // to the end of
the line.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
34
Escape Sequences
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
Notation Character represented
n Newline (0x0a)
r Carriage return (0x0d)
f Formfeed (0x0c)
b Backspace (0x08)
s Space (0x20)
t tab
" Double quote
' Single quote
 backslash
ddd Octal character (ddd)
uxxxx
Hexadecimal UNICODE character
(xxxx) 35
Declares and Initializes Variable
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
36
Java Modifiers Types
- Access Control Modifiers
• Java provides a number of access modifiers to set
access levels for classes, variables, methods and
constructors. The four access levels are:
• Visible to the package, the default. No modifiers are
needed.
• Visible to the class only (private).
• Visible to the world (public).
• Visible to the package and all subclasses (protected).
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
37
Java Modifiers Types
- Non Access Modifiers
• Java provides a number of non-access modifiers to achieve
many other functionality.
• The static modifier for creating class methods and variables
• The final modifier for finalizing the implementations of
classes, methods, and variables.
• The abstract modifier for creating abstract classes and
methods.
• The synchronized and volatile modifiers, which are used for
threads.
OOP 2nd Class TCI-SPU Rebaz M. nabi
@2015-2016
38

More Related Content

PPT
C# Fundamental
PPTX
Ch1 language design issue
PPTX
Copmuter Languages
PPT
Introduction to Computers, the Internet and the Web
PDF
Programming languages and concepts by vivek parihar
PPT
Programming language design and implemenation
PPTX
Programming.language
PDF
Programming Languages Categories / Programming Paradigm By: Prof. Lili Saghafi
C# Fundamental
Ch1 language design issue
Copmuter Languages
Introduction to Computers, the Internet and the Web
Programming languages and concepts by vivek parihar
Programming language design and implemenation
Programming.language
Programming Languages Categories / Programming Paradigm By: Prof. Lili Saghafi

What's hot (18)

PPT
PROGRAMMING LANGUAGES
PPT
Introduct To C Language Programming
PDF
Principles of-programming-languages-lecture-notes-
PPTX
introduction to programming languages
DOCX
Swift language seminar topic
PPTX
Programming landuages
PDF
Presentation of programming languages for beginners
PPTX
Introduction to programming
PPTX
Introduction to Coding
PPSX
Programming languages
KEY
Evolution of Programming Languages
PPT
Computer languages
DOCX
PDF
The Ring programming language version 1.6 book - Part 6 of 189
PPT
270 1 c_intro_up_to_functions
PPTX
Programming languages of computer
PPT
Programming languages
PPT
software development and programming languages
PROGRAMMING LANGUAGES
Introduct To C Language Programming
Principles of-programming-languages-lecture-notes-
introduction to programming languages
Swift language seminar topic
Programming landuages
Presentation of programming languages for beginners
Introduction to programming
Introduction to Coding
Programming languages
Evolution of Programming Languages
Computer languages
The Ring programming language version 1.6 book - Part 6 of 189
270 1 c_intro_up_to_functions
Programming languages of computer
Programming languages
software development and programming languages
Ad

Viewers also liked (9)

PDF
Scala modules
ODP
Oscar reiken jr on our success at manheim
PDF
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
PDF
5 things cucumber is bad at by Richard Lawrence
ODP
Patterns for slick database applications
PPT
enhanced er diagram
PDF
2015 Upload Campaigns Calendar - SlideShare
PPTX
What to Upload to SlideShare
PDF
Getting Started With SlideShare
Scala modules
Oscar reiken jr on our success at manheim
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
5 things cucumber is bad at by Richard Lawrence
Patterns for slick database applications
enhanced er diagram
2015 Upload Campaigns Calendar - SlideShare
What to Upload to SlideShare
Getting Started With SlideShare
Ad

Similar to Oop lecture1-chapter1(review of java) (20)

PPTX
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
PPTX
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
PPTX
General oop concept
PPT
unit-1 JAVA FUNDAMENTALS oop concencepts
PDF
Java Programming.pdf
PDF
Introduction to Programming with Java 3rd Edition John Dean
PPTX
OOP with Java - Java Introduction (Basics)
PPT
Introduction to java programming language
PPT
JavaHTP7e_0101_DDP.ppt
PPT
JAVA object oriented programming (oop).ppt
PPTX
OODJ-MODULE 1.pptx
PPTX
PPTX
Java Programming concept
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
Introduction to Object Oriented Programming & Design Principles
PDF
PDF
Object Oriented Programming -- Dr Robert Harle
PDF
lecture-1111111111111111111111111111.pdf
PPT
Lecture01 0089
JAVA_VR23_OOPS THROUGH JAVA PPT UNIT-1.pptx
2R-3KS03-OOP_UNIT-I (Part-A)_2023-24.pptx
General oop concept
unit-1 JAVA FUNDAMENTALS oop concencepts
Java Programming.pdf
Introduction to Programming with Java 3rd Edition John Dean
OOP with Java - Java Introduction (Basics)
Introduction to java programming language
JavaHTP7e_0101_DDP.ppt
JAVA object oriented programming (oop).ppt
OODJ-MODULE 1.pptx
Java Programming concept
Introduction to Object Oriented Programming & Design Principles
Introduction to Object Oriented Programming & Design Principles
Object Oriented Programming -- Dr Robert Harle
lecture-1111111111111111111111111111.pdf
Lecture01 0089

More from Dastan Kamaran (7)

DOCX
DOCX
PPTX
Field properties
PPTX
Create table relationships
PPTX
Field properties
PPTX
Create table relationships
PPTX
Oop lecture1-chapter1(review of java)
Field properties
Create table relationships
Field properties
Create table relationships
Oop lecture1-chapter1(review of java)

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Big Data Technologies - Introduction.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
Spectroscopy.pptx food analysis technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
A comparative analysis of optical character recognition models for extracting...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
A Presentation on Artificial Intelligence
Encapsulation_ Review paper, used for researhc scholars
Machine Learning_overview_presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Spectroscopy.pptx food analysis technology
Reach Out and Touch Someone: Haptics and Empathic Computing
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Spectral efficient network and resource selection model in 5G networks
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
A comparative analysis of optical character recognition models for extracting...

Oop lecture1-chapter1(review of java)

  • 1. Object Oriented Programming-Java Rebaz M. Nabi Email: rebazmala86@gmail.com 1 OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016
  • 2. Class Policy RESPECT OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 2
  • 3. Background • Deitel, H.M. & Deitel, P.J. (2009). Java: How to Program. Prentice Hall (8th ed.). • Flanagan, D. (2005). Java in a nutshell : a desktop quick reference. O’Reilly (5th ed.). • Flanagan, D. (2004). Java examples in a nutshell : a tutorial companion to Java in a nutshell. O’Reilly (3rd ed.). • Gamma, E., Helm, R., Johnson, R. & Vlissides, A. (1995). Design patterns: elements of reusable object-oriented software. Addison-Wesley. • Bloch, J. & Gafter, N. (2005). Java puzzlers. Addison-Wesley. • Object Oriented Modeling and Design with UML Michael Blaha and James Rambaugh – PEARSON second edition. • UML Distilled: A Brief Guide to the Standard Object Modeling Language (3rd Edition) by Martin Fowle. • Douglas Bell. Software Engineering. Third Edition. 2000. • Cay Horstmann, “ Big Java”, 3rd Edition, John Wiley and Sons, 2008, ISBN: 978-0-470-10554-2 OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 3
  • 4. Objectives • The goal of this course is to provide students with the ability to write programs in Java and make use of the concepts of Object-Oriented Programming (the principles of OOP which is inheritance, polymorphism, abstract, and encapsulation). Examples and discussions will use Java primarily, but other languages may be used to illustrate specific points where appropriate. As well as this course considered the GUI programs in java and JDBC to access database applications from java code. The course is designed to accommodate students with diverse programming backgrounds; it is taught with a mixture of lectures and practical sessions where students can work at their own pace from a course handbook. Each practical class will culminate in an assessed exercise. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 4
  • 5. Aims After learning the course the students should be able to: • Be familiar with the main features and limitations of the Java language; • Be able to write a Java program to solve a well specified problem; • Understand the principles of OOP; • Understand how to use GUI components in Java • Be able to demonstrate good object-oriented programming skills in Java; • Be able to describe, recognise, apply and implement selected design patterns in Java; • Develop database-driven applications • Identify exception handling methods. • Implement multithreading in object oriented programs. • Prepare UML diagrams for software system OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 5
  • 6. Course Content • Revision of principles of programming in java • Principles of Object-Oriented Programming • Classes and Objects in Java • Graphical User Interface • Encapsulation and inner class • Packages and Standard libraries • Interface and Abstract class • Exceptions Handling • Input Output stream • Java Database Connectivity JDBC • Collection Classes • Concurrent programming • Software Testing and Flow Diagram OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 6
  • 7. Basic Definitions • A computer is a machine that performs calculations and processes information – A computer works under the control of a computer program • A computer program is a set of instructions that tell a computer what to do • Hardware refers to the electronic and mechanical components of a computer • Software refers to the programs that control the hardware OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 7
  • 8. Computers HardwareSoftware Computers OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 8
  • 9. Hardware • A computer's hardware is organized into several main subsystems or components OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 9
  • 10. Software • There are two main types of software: • Application software – designed to provide a particular task or service – word processors, computer games, spreadsheet programs, and Web browsers • System software – includes programs that perform the basic operations that make a computer usable – An example of the system software is operating systems, which contains programs that manage the data stored on the computer's disks, such as Windows or Linux OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 10
  • 11. Programming Languages • Programmers write instructions in various programming languages, some directly understandable by computers and others requiring intermediate translation steps. Hundreds of computer languages are in use today. These may be divided into three general types: 1. Machine languages( Numbers) 2. Assembly languages ( Keywords) 3. High-level languages(Close to Human English ) 4. New Generation Languages OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 11
  • 12. Machine languages • Any computer can directly understand only its own machine language. Machine language is the "natural language" of a computer and as such is defined by its hardware design. Machine languages generally consist of strings of numbers (ultimately reduced to 1s and 0s) that instruct computers to perform their most elementary operations one at a time. Samples – +1300042774 – +1400593419 – +1200274027 OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 12
  • 13. assembly languages • Machine-language programming was simply too slow and tedious for most programmers. These abbreviations formed the basis of assembly languages. Translator programs called assemblers were developed to convert early assembly-language programs to machine language at computer speeds. • Although such code is clearer to humans, it is incomprehensible to computers until translated to machine language. – load – add – store OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 13
  • 14. High level languages • To speed the programming process, high-level languages were developed in which single statements could be written to accomplish substantial tasks. Translator programs called compilers convert high-level language programs into machine language. High-level languages allow programmers to write instructions that look almost like everyday English and contain commonly used mathematical notations. • grossPay = basePay + overTimePay – C, C++, Microsoft's .NET languages (e.g., Visual Basic .NET, Visual C++ .NET and C#) and Java are among the most widely used high-level programming languages. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 14
  • 15. Compilers and Interpreters • The process of compiling a high-level language program into machine language can take a considerable amount of computer time. Interpreter programs were developed to execute high-level language programs directly. • Translators are used to translate a high-level or source code program (in C++ or Java) into machine language code or object code OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 15
  • 16. Compilers and Interpreters e) • Source code translators come in two varieties: – An interpreter translates a single line of source code directly into machine language and executes the code before going on to the next line of source code • for example PHP and Perl. – A compiler translates the entire source code program into executable object code. The object code can be run directly without further translation • for example C, C++, and Pascal • Java programs use both compilation and interpretation in their translation process OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 16
  • 17. History of Java • Java evolved from C++, which evolved from C. • The C language was evolved from B by Dennis Ritchie(Father of Computer Programming(my point of view) at Bell Laboratories and was originally implemented in 1972. It initially became widely known as the development language of the UNIX operating system. Today, most of the code for general-purpose operating systems (e.g., those found in laptops, desktops, workstations and small servers) is written in C or C++. • C++, an extension of C, was developed by Bjarne Stroustrup in the early 1980s at Bell Laboratories (now part of Lucent). C++ provides a number of features that "spruce up" the C language, but more important, it provides capabilities for object-oriented programming OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 17
  • 18. History of Java (Cont.) • Microprocessors are having a profound impact in intelligent consumer-electronic devices. Recognizing this, Sun Microsystems in 1991 funded an internal corporate research project code-named Green, which resulted in the development of a C++-based language that its creator, James Gosling, called Oak after an oak tree outside his window at Sun. • It was later discovered that there already was a computer language called Oak. When a group of Sun people visited a local coffee shop, the name Java was suggested, and it stuck. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 18
  • 19. Why Java?  Object Oriented  Object-oriented languages divide programs into separate modules, called objects, that encapsulate the program's data and operations  Robust  meaning that errors in Java programs don't cause system crashes as often as errors in other programming languages  Platform Independent  Platform is a particular kind of computer system, such as a Macintosh or Windows system  Java program can be run without changes on different kinds of computers  Distributed Language  which means that its programs can be designed to run on computer networks  Secure  Java designed to be used on networks, Java contains features that protect against untrusted code OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 19
  • 20. Software Development Process • source code is written in plain text files with the .java extension • source files are then compiled into .class files by the java compiler • A .class contains bytecodes: the machine language of the Java Virtual Machine (Java VM). • The java runs the application with an instance of the Java VM • OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 20
  • 21. Fundamentals of Programming in Java • Java VM is available on many different operating systems • The same .class files are capable of running on – Microsoft Windows – Solaris OS – Linux – Mac OS OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 21
  • 22. The Java Platforms • The Java platform runs on top of other hardware- based platforms like Windows, Linux or Mac OS • has two components: – The Java Virtual Machine (VM) – The Java Application Programming Interface (API) • The Java Virtual Machine (Java VM) is the base for the Java platform • The API is a large collection of software components grouped into libraries known as packages OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 22
  • 23. Write a java program • The necessary tools are: – The Java SE Development Kit 8 (JDK) you can download the latest version here: – http://www.oracle.com/technetwork/java/javase/downloads/jdk8- downloads-2133151.html – For description and how does it work click below link: – http://docs.oracle.com/javase/7/docs/webnotes/install/index.html – Text pad( will be provided during practical lectures) or you can download it here – http://www.textpad.com/download/ – Eclipse or NetBeans (prefer NetBeans) • Creating an Application in Windows – Create a source file in .java extension – Compile the source file into a .class java compiler – Run the program OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 23
  • 24. Java Program Development • Phase 1.0 : Editor • Phase 2.0 : Compiler • Phase 3.1 : Class Loader • Phase 3.2 : Bytecode Verifier • Phase 3.3 : Java Virtual Machine • Program is edited in a text editor, much as a paper for an English class is edited in a word processor. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 24
  • 25. Java Conventions • About Java programs, it is very important to keep in mind the following points. • Case Sensitivity - Java is case sensitive, which means identifier Hello and hello would have different meaning in Java. • Class Names - For all class names the first letter should be in Upper Case. If several words are used to form a name of the class, each inner word's first letter should be in Upper Case. Example: class MyFirstJavaClass • Method Names - All method names should start with a Lower Case letter. If several words are used to form the name of the method, then each inner word's first letter should be in Upper Case. Example: public void myMethodName() • Program File Name - Name of the program file should exactly match the class name. Example : Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java’ OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 25
  • 26. Java Identifiers • All Java components require names. Names used for classes, variables and methods are called identifiers. • In Java, there are several points to remember about identifiers. They are as follows: • All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). • After the first character identifiers can have any combination of characters. • A reserved key word cannot be used as an identifier. • Most importantly identifiers are case sensitive • Examples of legal identifiers: age, $salary, _value, __1_value • Examples of illegal identifiers: 123abc, -salary. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 26
  • 27. Java Modifiers • Like other languages, it is possible to modify classes, methods, etc., by using modifiers. There are two categories of modifiers: • Access Modifiers: default, public , protected, private • Non-access Modifiers: final, abstract, static • We will be looking into more details about modifiers in the next section. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 27
  • 28. Java Variables - Local Variables • Local variables are visible only within the declared method, constructor or block. • Access modifiers cannot be used for local variables. • There is no default value for local variables so local variables should be declared and an initial value should be assigned before the first use. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 28
  • 29. Java Variables - InstanceVariables • Instance variables are declared in a class, but outside a method, constructor or any block. • Access modifiers can be given for instance variables. • The instance variables are visible for all methods, constructors and block in the class. Normally, it is recommended to make these variables private (access level). However visibility for subclasses can be given for these variables with the use of access modifiers. • Instance variables have default values. For numbers the default value is 0, for Booleans it is false and for object references it is null. Values can be assigned during the declaration or within the constructor. • Instance variables can be accessed directly by calling the variable name inside the class. However within static methods and different class ( when instance variables are given accessibility) should be called using the fully qualified name . ObjectReference.VariableName. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 29
  • 30. Java Variables - Class Variables • Class variables are variables declared with in a class, outside any method, with the static keyword. • Access modifiers can be given for instance variables. • In the case of having static variables or methods, you can access or use them by using the class’s name following it’s variable or method name OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 30
  • 31. Variables  Definition: a variable is a location in the computer memory which can store a value of a certain type  Each variable has a name, a type, a size, and a value.  Examples of variables: 1 byte byte age = 22; short shortNum; int intNum; age long longNum; char mychar; boolean isMale; Name value OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 31 22
  • 32. Java Keywords OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 32 abstract Assert boolean break byte Case catch char class Const continue default do Double else enum extends Final finally float for Goto if implements import Instanceof int interface long Native new package private Protected public return short static strictfp super switch synchronized this throw throws transient try void Volatile while
  • 33. Comments • Java statements direct the operations of a program, while comments are used to help document what the program does.The Java supports three kinds of – /* text */ • The compiler ignores everything from /* to */. – /** documentation */ • This indicates a documentation comment – // text • The compiler ignores everything from // to the end of the line. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 33
  • 34. Java Data Type – ** documentation */ • This indicates a documentation comment – // text • The compiler ignores everything from // to the end of the line. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 34
  • 35. Escape Sequences OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 Notation Character represented n Newline (0x0a) r Carriage return (0x0d) f Formfeed (0x0c) b Backspace (0x08) s Space (0x20) t tab " Double quote ' Single quote backslash ddd Octal character (ddd) uxxxx Hexadecimal UNICODE character (xxxx) 35
  • 36. Declares and Initializes Variable OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 36
  • 37. Java Modifiers Types - Access Control Modifiers • Java provides a number of access modifiers to set access levels for classes, variables, methods and constructors. The four access levels are: • Visible to the package, the default. No modifiers are needed. • Visible to the class only (private). • Visible to the world (public). • Visible to the package and all subclasses (protected). OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 37
  • 38. Java Modifiers Types - Non Access Modifiers • Java provides a number of non-access modifiers to achieve many other functionality. • The static modifier for creating class methods and variables • The final modifier for finalizing the implementations of classes, methods, and variables. • The abstract modifier for creating abstract classes and methods. • The synchronized and volatile modifiers, which are used for threads. OOP 2nd Class TCI-SPU Rebaz M. nabi @2015-2016 38

Editor's Notes

  • #16: A complier converts the high level instruction into machine language while an interpreter converts the high level instruction into an intermediate form. • Before execution, entire program is executed by the compiler whereas after translating the first line, an interpreter then executes it and so on. • List of errors is created by the compiler after the compilation process while an interpreter stops translating after the first error. • An independent executable file is created by the compiler whereas interpreter is required by an interpreted program each time. Read more: http://www.differencebetween.com/difference-between-compiler-and-vs-interpreter/#ixzz2CheRy7UO