SlideShare uma empresa Scribd logo
1 de 38
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

Mais conteúdo relacionado

Mais procurados

PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESABHINAV SINGH
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programmingyarkhosh
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Krishna Sai
 
introduction to programming languages
introduction to programming languagesintroduction to programming languages
introduction to programming languagesNaqashAhmad14
 
Swift language seminar topic
Swift language seminar topicSwift language seminar topic
Swift language seminar topicHyacinth Okeke
 
Presentation of programming languages for beginners
Presentation of programming languages for beginnersPresentation of programming languages for beginners
Presentation of programming languages for beginnersClement Levallois
 
Programming languages
Programming languagesProgramming languages
Programming languagesvito_carleone
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming LanguagesSayanee Basu
 
The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189Mahmoud Samir Fayed
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functionsray143eddie
 
Programming languages of computer
Programming languages of computerProgramming languages of computer
Programming languages of computerKeval Goyani
 
Programming languages
Programming languagesProgramming languages
Programming languagesAsmasum
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages PraShant Kumar
 

Mais procurados (18)

PROGRAMMING LANGUAGES
PROGRAMMING LANGUAGESPROGRAMMING LANGUAGES
PROGRAMMING LANGUAGES
 
Introduct To C Language Programming
Introduct To C Language ProgrammingIntroduct To C Language Programming
Introduct To C Language Programming
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-
 
introduction to programming languages
introduction to programming languagesintroduction to programming languages
introduction to programming languages
 
Swift language seminar topic
Swift language seminar topicSwift language seminar topic
Swift language seminar topic
 
Programming landuages
Programming landuagesProgramming landuages
Programming landuages
 
Presentation of programming languages for beginners
Presentation of programming languages for beginnersPresentation of programming languages for beginners
Presentation of programming languages for beginners
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming Languages
 
Computer languages
Computer languagesComputer languages
Computer languages
 
JAVA
JAVAJAVA
JAVA
 
The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189The Ring programming language version 1.6 book - Part 6 of 189
The Ring programming language version 1.6 book - Part 6 of 189
 
270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions270 1 c_intro_up_to_functions
270 1 c_intro_up_to_functions
 
Programming languages of computer
Programming languages of computerProgramming languages of computer
Programming languages of computer
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
software development and programming languages
software development and programming languages software development and programming languages
software development and programming languages
 

Destaque

Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimSkills Matter
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmSkills Matter
 
5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard LawrenceSkills Matter
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShareSlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShareSlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShareSlideShare
 

Destaque (9)

Scala modules
Scala modulesScala modules
Scala modules
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
enhanced er diagram
enhanced er diagramenhanced er diagram
enhanced er diagram
 
2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare2015 Upload Campaigns Calendar - SlideShare
2015 Upload Campaigns Calendar - SlideShare
 
What to Upload to SlideShare
What to Upload to SlideShareWhat to Upload to SlideShare
What to Upload to SlideShare
 
Getting Started With SlideShare
Getting Started With SlideShareGetting Started With SlideShare
Getting Started With SlideShare
 

Semelhante a Oop lecture1-chapter1(review of java)

Semelhante a Oop lecture1-chapter1(review of java) (20)

Programming language
Programming languageProgramming language
Programming language
 
Plc part 1
Plc part 1Plc part 1
Plc part 1
 
Top Programming Languages of 2020
Top Programming Languages of 2020Top Programming Languages of 2020
Top Programming Languages of 2020
 
Advance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptxAdvance C# Programming Part 1.pptx
Advance C# Programming Part 1.pptx
 
Advance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdfAdvance C# Programming Part 1.pdf
Advance C# Programming Part 1.pdf
 
Programming lesson1
Programming lesson1Programming lesson1
Programming lesson1
 
Unit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptxUnit 1 introduction to c++.pptx
Unit 1 introduction to c++.pptx
 
Unit 1
Unit 1Unit 1
Unit 1
 
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.docICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
ICT-DBA4 -05-0811-Apply-Object-Oriented-Programming-Language-Skills.doc
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
Java
JavaJava
Java
 
Compilers.pptx
Compilers.pptxCompilers.pptx
Compilers.pptx
 
Programming using C++ - slides.pptx
Programming using C++ - slides.pptxProgramming using C++ - slides.pptx
Programming using C++ - slides.pptx
 
Unit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptx
 
Intro1
Intro1Intro1
Intro1
 
Evolution of Programming Languages.pdf
Evolution of Programming Languages.pdfEvolution of Programming Languages.pdf
Evolution of Programming Languages.pdf
 
Evolution of Programming Languages.pdf
Evolution of Programming Languages.pdfEvolution of Programming Languages.pdf
Evolution of Programming Languages.pdf
 
Code learning
Code learningCode learning
Code learning
 
Presentation-1.pptx
Presentation-1.pptxPresentation-1.pptx
Presentation-1.pptx
 
c vs java (2).pptx
c vs java (2).pptxc vs java (2).pptx
c vs java (2).pptx
 

Mais de Dastan Kamaran

Mais de Dastan Kamaran (7)

Quiz 1
Quiz 1Quiz 1
Quiz 1
 
Q1 (a)
Q1 (a)Q1 (a)
Q1 (a)
 
Field properties
Field propertiesField properties
Field properties
 
Create table relationships
Create table relationshipsCreate table relationships
Create table relationships
 
Field properties
Field propertiesField properties
Field properties
 
Create table relationships
Create table relationshipsCreate table relationships
Create table relationships
 
Oop lecture1-chapter1(review of java)
Oop lecture1-chapter1(review of java)Oop lecture1-chapter1(review of java)
Oop lecture1-chapter1(review of java)
 

Último

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 

Último (20)

DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 

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

Notas do Editor

  1. 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