Programming Paradigms and Introduction To Java
Programming Paradigms and Introduction To Java
1
Programming Paradigm
• A Computer program is a set of instructions that is designed for a
specific purpose written in a programming language.
• A program comprises of a code that works on a given data.
• Programming paradigm helps to classify programming languages
on the basis of their features.
2
Programming Paradigm:
Categorization
• Imperative • Declarative:
• the programmer instructs the • programmer merely declares
machine how to change its properties of the desired result,
state but not how to compute it
• procedural : focus on steps • Functional, Logic, SQL
to follow Suppose we have a record of
• object-oriented focus on students (Table Name:
data to be processed; Students) studying in a class
defines steps around the and we are required to find the
data set of students who stay in
Delhi.
*We focus on two: Procedural In SQL this problem will be
and Object-oriented): written as – Select * from
Students where address =
“Delhi” 3
Procedure-Based Programming
Source:https://www.csd.uoc.gr/~hy252/html/Lectures2012/CS252Intro12.pdf
4
Procedural Programming
• It follows divide and conquer technique by breaking larger problem
into smaller problems.
• A program is collection of such procedures(functional
decomposition.
• But the biggest disadvantage is that larger the system more
restructuring is required.
Source:https://www.csd.uoc.gr/~hy252/html/Lectures2012/CS252Intro12.pdf
5
Object Oriented Programming
• Based on five major principles:
• 1. Data Abstraction: act of representing essential features without
including the background details or explanations.
• 2. Encapsulation: refers to the wrapping up of data and
operations / functions (that operate on the data ) into a single unit
(called class).
• 3. Information Hiding: Everything is not known to everyone.
• 4. Polymorphism (dynamic binding): to allow one interface to be
used for a general class of actions. E.g. walk
• 5. Inheritance: is the process by which one object acquires the
properties of another object.
6
Terminology
•Object oriented programming build around classes and objects:
•Class: A class can be defined as a template/blueprint that describes
the state and behaviour of entities. Example: Lamp is a class has
states –color, status as well as behaviours – turn-on, turn-off.
•State : Data Members – Color, status
•Behaviour: Member Functions - turn-on, turn-off
•Object: An object is an instance of a class.
7
• Class Definition • Object Declaration
• class lamp { • lamp lamp1 = new
• string color; lamp( “red”,1);
• Boolean status; • Lamp1.turnoff( );
• void turnon( ) {
• status =1;
• }
• void turnoff( ) {
• status =0;
• }
8
O-O Concepts Programming language
Construct(s)
Abstraction Classes
Encapsulation Classes
9
Object –Oriented Programming
Source:https://www.csd.uoc.gr/~hy252/html/Lectures2012/CS252Intro12.pdf
10
Procedural ( Top-Down) Object –oriented (Bottom-Up)
Source:
http://www.cse.iitm.ac.in/~rupesh/teaching/oop/0-
intro.pdf
11
Drill 1
• You have to go for a vacation. How would you plan the solution of
this problem using:
Procedural Approach
Object Oriented Approach
12
Drill 2
• You have to create an application that generates report cards of
students in a University exam. How would you plan the solution of
this problem using:
Procedural Approach
Object Oriented Approach
13
Java – Programming Language
14
Java Introduction
Object Multithreade
Distributed
oriented d
Architecture
Dynamic Portable
neutral
High
Robust Secure
performance
2) Web Application
Web application is a client server software application which is run
by the client. Currently, servlet, jsp etc. technologies are used for
creating web applications in java.
Types of Java Applications(cont.)
3) Enterprise Application
An application that is distributed in nature, such as banking
applications etc. It has the advantage of high level security, load
balancing and clustering.
4) Mobile Application
An application that is created for mobile devices. Currently Android
and Java ME are used for creating mobile applications.
History of Java
1) James Gosling, Mike Sheridan, and Patrick Naughton initiated
the Java language project in June 1991. The small team of sun
engineers called Green Team.
2) Originally designed for small, embedded systems in electronic
appliances like set-top boxes.
3) Firstly, it was called "Greentalk" by James Gosling and file
extension was .gt.
4) After that, it was called Oak and was developed as a part of the
Green project.
5) In 1995, Oak was renamed as "Java" because it was already a
trademark by Oak Technologies.
6) JDK 1.0 released in(January 23, 1996).
7) Many JDK versions have been released. Latest being: Java SE 11
Three important terms
JDK – Java Development Kit (in short JDK) is Kit which provides
the environment to develop and execute(run) the Java program.
JDK is a kit(or package) which includes two things
• Development Tools(to provide an environment to develop your java
programs)
• JRE (to execute your java program).
21
• In the Java programming language:
all source code is first written in plain text files ending with
the .java extension.
Those source files are then compiled into .class files by the javac
compiler. A .class file does not contain code that is native to your
processor; it instead contains bytecodes — the machine language of
the Java Virtual Machine (Java VM).
The java launcher tool then runs your application with an instance
of the Java Virtual Machine.
22
Source:https://docs.oracle.com/javase/tutorial/getStarted/intro/definition.html
23
Programming in Java
• Java programs
• Consist of pieces called classes
• Classes contain methods, which perform tasks
• Class libraries
• Also known as Java API (Applications Programming Interface)
• Rich collection of predefined classes, which you can use
• Two parts to learning Java
• Learning the language itself, so you can create your own classes
• Learning how to use the existing classes in the libraries
24
Basics of a Typical Java Environment
• Java programs have five phases
• Edit
• Use an editor to type Java program
• notepad, Jbuilder, Visual J++, sublime
• .java extension
• Compile
• Translates program into bytecodes, understood by Java
interpreter
• javac command: javac myProgram.java
• Creates .class file containing bytecodes (myProgram.class)
25
Basics of a Typical Java Environment
• Java programs have five phases (continued)
• Loading
• Class loader transfers .class file into memory
• Applications - run on user's machine
• Classes loaded and executed by interpreter with java
command
java Welcome
• Verify
• Bytecode verifier makes sure bytecodes are valid and do not
violate security
• Java must be secure - possible to damage files (viruses)
26
Basics of a Typical Java Environment
• Java programs have five phases (continued)
• Execute
• Computer interprets program one bytecode at a time
• Performs actions specified in program
27
Program is created in
Phase 1 Editor Disk the editor and stored
on disk.
Compiler creates
Phase 2 Compiler Disk bytecodes and stores
them on disk.
Primary
Memory
Class Loader
Phase 3
30
DisplayHello.java
32
Resources for learning Java
a) Java How to Program, 10/e (Early Objects) by Paul J.
Deitel (Author), Harvey Deitel (Author)
33