principles of object-oriented programming in java...java runtime environment (jre) is part of jdk...

21
Principles of Object-Oriented Programming in Java Dr. Hikmat Abdeljaber ©2014 by SAU. All Rights Reserved.

Upload: others

Post on 21-May-2020

29 views

Category:

Documents


0 download

TRANSCRIPT

Principles of Object-Oriented Programming in Java

Dr. Hikmat Abdeljaber

©2014 by SAU. All Rights Reserved.

A Program is a sequence of instructions that define tasks for the computer to execute.

Programming languages are human-engineered languages developed to convey instructions to machines.

Any programming language has two essentials: syntax and semantics.

A translator is a program that translates a source-code to an object-code.

©2014 by SAU. All Rights Reserved.

©2014 by SAU. All Rights Reserved.

A programming paradigm is the manner or approach used in programming.

Programming languages are classified into two levels: low-level languages and high-level languages.

Low-level languages are classified into two languages: machine language and assembly language.

Machine language is the only language the CPU understands and thus needs no translator.

©2014 by SAU. All Rights Reserved.

Assembly language is a symbolic language needs an assembler for translating source code to object code.

Machine language is called first-generation programming language and assembly language is called second-generation programming language.

High-level languages are classified into four main programming paradigms: imperative, functional, declarative and object-oriented.

©2014 by SAU. All Rights Reserved.

Imperative, functional and declarative programming languages are called third-generation programming languages while object-oriented programming (OOP) languages are called fourth-generation programming languages.

Java is an OOP language intended to let application developers write once run anywhere (WORA).

©2014 by SAU. All Rights Reserved.

High-level languages use compiler or interpreter translators, while Java uses both translators.

OOP specifies both the data and the operations that can be applied to those data.

Class and object are two key concepts of OOP.

A class is a data-type or a construct consists of data and operations.

©2014 by SAU. All Rights Reserved.

A class is a template or prototype from which objects are instantiated (created).

An object is an instance of a class. A class can instantiate many objects.

Programs in OOP are collections of classesand objects.

Objects are communicated through exchanging messages.

Exchanging messages between objects results final states of these objects.

©2014 by SAU. All Rights Reserved.

Data are interchangeably called attributes, properties, data fields, instance variables, or states. Operations are interchangeably called functions, methods, or actions.

Java uses instance variables for data and methods for operations.

OOP has introduced three key principles: data encapsulation, inheritance, and polymorphism.

©2014 by SAU. All Rights Reserved.

Applets and applications are two types of Java programs.

Java applications support console applications and windowed applications.

©2014 by SAU. All Rights Reserved.

James Gosling, Patrick Naughton, and Mike Sheridan were the original inventors of Java.

©2014 by SAU. All Rights Reserved.

Java is object-oriented, portable, interpreted, robust, distributed, secure, multithreaded, and dynamic language.

©2014 by SAU. All Rights Reserved.

Java class library (JCL) is a set of libraries contain a collection of predefined classes that can be called and used by developers to develop Java applications. JCL is also called application programming interfaces (APIs).

Java libraries are listed as packages in the integrated development environment (IDE).

©2014 by SAU. All Rights Reserved.

Java development environment (JDE) is a tool embedded in IDE which allows developers to create, compile, and execute Java applications.

The user creates source file with extension .java. The compiler then translates the source file into bytecode file which have the same name but with extension .class. Finally, JVM interprets and executes the bytecode.

©2014 by SAU. All Rights Reserved.

©2014 by SAU. All Rights Reserved.

Java development kit (JDK) is a collection of tools for compiling and running Java programs.

JDK comes in three editions: J2SE, J2EE, and J2ME.

J2SE is used to develop client-side applications. J2EE is used to develop server-side applications. J2ME is used to develop applications for mobile devices.

©2014 by SAU. All Rights Reserved.

Eclipse, NetBeans, JGrasp, BlueJ, and TextPadare some examples of IDEs.

Java runtime environment (JRE) is part of JDK used for executing Java programs. JRE consists of JVM, APIs, Java plug-in, and Java web start.

Java virtual machine (JVM) is part of JRE that interprets and executes bytecodes on any computer platform.

©2014 by SAU. All Rights Reserved.

©2014 by SAU. All Rights Reserved.

A Java program is almost makeup of basic components that specifies its structure including comments, reserved words, modifiers, statements, blocks, classes, methods and the main method.

Java uses three types of comments: line comment, paragraph comment, and Javadoccomment.

import, public, class, if, for, int, static, and switch are some reserved words in Java.

©2014 by SAU. All Rights Reserved.

Modifiers are reserved words that determine the visibility and accessibility of the attributes and methods of an object to other objects.

Modifiers include access modifiers (such as private, public, and protected) and non-access modifiers (such as final, static, and abstract).

A statement is an action or a sequence of actions.

©2014 by SAU. All Rights Reserved.

A block is a group of statements surrounded by braces {}.

Blocks have two styles: next-line block style and end-line block style.

A class is a template or blueprint for objects.

A method is sequence of statements that performs a task and return information when it completes its task.

The Java classes within the same application must contain exactly one main methodbecause it is the starting point for execution.

©2014 by SAU. All Rights Reserved.