0% found this document useful (0 votes)
2 views23 pages

L01 - Intro to Java

Introduction of java

Uploaded by

jad man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views23 pages

L01 - Intro to Java

Introduction of java

Uploaded by

jad man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Lecture 1

Introduction to Object Oriented


Programming
What is a Computer Program?
• For a computer to be able to do anything
(multiply, play a song, run a word processor),
it must be given the instructions to do so.

• A program is a set of instructions written by


humans for computers to perform tasks.

• The instructions are written in programming


languages such as C, C++, Java, etc.
Recipe Analogy
Comparing a computer program to a food recipe

Food Recipe Computer Program


• a chef writes a set of • a programmer writes a set of
instructions called a recipe instructions called a program

• the recipe requires • the program requires


specific ingredients specific inputs

• the cook follows the • the computer follows the


instruction step-by-step instructions step-by-step

• the food will vary • the output will vary


depending on the amount depending on the values of
of ingredients and the cook the inputs and the computer
Compiling Programs

• Computers do not understand the languages


(C++, Java, etc) that programs are written in.

• Programs must first be compiled (converted)


into machine code that the computer can run.

• A compiler is a program that translates a


programming language into machine code.
Running Programs
• All programs follow a simple format:
Input Execution Output

• Inputs can be from users, files, or


other computer programs

• Outputs can take on many forms:


numbers, text, graphics, sound, or
commands to other programs
Multiple Compilers
• Because different operating systems (Windows, Macs,
Unix) require different machine code, you must compile
most programming languages separately for each platform.

program

compiler compiler

compiler

Unix
Win
MAC
Java Interpreter
• Java is a little different.
• Java compiler produces bytecode not
machine code.
• Bytecode can be run on any computer
Win
with the Java interpreter installed.

Java Program Java Bytecode


MAC

compiler Interpreter

Unix
Advantages and Disadvantages of Java
Advantages:
• Java is platform independent. Once it's compiled, you can run
the bytecode on any machine with a Java interpreter. You do not
have to recompile for each platform.
• Java is safe. Certain common programming bugs and dangerous
operations are prevented by the language and compiler.
• Java standardizes many useful operations like managing
network connections and providing graphical user interfaces.

Disadvantages:
• Running bytecode through the interpreter is not as fast as
running machine code, which is specific to that platform.
• Because it is platform independent, it is difficult to use platform
specific features (e.g., Windows taskbar, quick launch) in Java.
• Java interpreter must be installed on the computer in order to run
Java programs.
Object-Oriented Programming
• Java is an object-oriented
programming language

• For the rest of this lecture, we’ll


introduce you to the basic principles
of object-oriented programming.

• We won’t be using these principles


immediately, but they will become
important over the next lectures.
OOP Concepts
• In object-oriented programming (OOP),
programs are organized into objects

• The properties of objects are


determined by their class

• Objects act on each other by passing


messages
Object
• Definition: An object is a software
bundle that has State and Behavior.

• Software Objects are often used to


model real-world objects.

• Example: dogs have states (name,


color) and behaviors (bark and wag
tail).
Object Examples

• Example 1: Dogs
– States: name, color and “is hungry?”
– Behaviors: bark, run, and wag tail

• Example 2: Cars
– States: color, model…
– Behaviors: accelerate, turn, change gears
Class
• Definition: A class is a blueprint that defines the
states and the behaviors common to all objects of
a certain kind.

• In the real world, you often have many objects of


the same kind. For example, a guard dog, snoop
dog . . .

• Even though all dogs have four legs, and bark,


each dog’s behavior is independent of other dogs.
Message

• Definition: Software objects interact and


communicate with each other by sending
messages to each other.

• Example: when you want your dog to


gather a herd of goats, you whistle and
send him out.
Summary of OOP
• When writing an object-oriented program, we
define classes, which describe categories of
objects, and the states and behaviors that they
have in common.

• We then create objects which belong to classes,


and share the common features of their class.

• Objects interact with each other by passing


messages.
Types of programming paradigm
 The programming paradigm is defined as a set of principles, ideas,
design concepts and norms that defines the manner in which the
program code is written and organized.
 The programming paradigm does not specify the programming
language syntax.
 The paradigm simply defines the program structure and the set of
principles that the programming language compiler should enforce.
 A programming paradigm is a framework that defines how the
programmer can conceptualize and model complex problem to be
solved.
 The programming paradigms can be classified into two main types.
 The paradigm type depends upon the programming language
features and a particular style of organizing the program code.
1. Imperative Paradigm
2. Declarative Paradigm
Types of programming paradigm
1. Imperative Paradigm
 The program code in imperative paradigm programming language
directs the program execution as sequence of statements executed
one by one.

 The imperative style program consist of set of program statements.


Each statement directs the computer to perform specific task.

 In imperative style program, the programmer has to elaborate each


statement in details.

 Each statement directs what is to be done and how it is to be done.

 The execution of the program statements is decided by the control


flow statements. And the program flow can be directed as per the
program logic.
Types of programming paradigm
2. Declarative Paradigm
 The declarative paradigm focuses on the logic of the program and the
end result.

 In this paradigm control flow is not the important element of the


program.

 The main focus of the declarative style of programming is achieving


the end result.

 This paradigm is straight forward and to the point while writing the
program code.
Types of programming paradigm
Types of programming paradigm
1. Procedural Programming Paradigm
 The program consist of set of procedures.

 The procedures are also referred as function, method or subroutines.

 The program structure in procedural programming consist of set of


functions and each performs a specific operation.

 The function consist of group of computational steps that directs the


computer to perform specific operation.

 The function once defined can be called many time in the program to
repeat the same operation.
Types of programming paradigm
2. Structured Programming Paradigm
 The structured programming intends to optimize the code by using
the program control flow constructs, decision making constructs and
the iteration constructs, blocks and the functions.

 The main intent of the structured programming approach is to improve


the readability of the code.

 This approach also facilitates the re-usability of the code.

 In modular (structured) programming, the program code is optimized


for readability and re-usability by dividing the code into semi
independent modules.

 These modules can be called number of times as may be required.


Types of programming paradigm
1. Functional Programming Paradigm
 The functional programming is based on the mathematical
functions.

 The functional programming attempts to solve the


problem by composing mathematical functions as
program components.

 In functional programming style the computer program is


created with the application and composing the
mathematical functions.
Types of programming paradigm
2. Logic Programming Paradigm
 The program written in logic programming language
consist of set of program statements in the logical form.

 Each statement is an expression of facts, rules and the


order of rules.

 The logic programming is an abstract model of


computation. It is based on the first order predicate logic.

You might also like