Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
64 views

Programming Paradigms and Introduction To Java

This document provides an introduction to Java programming. It discusses Java's object-oriented programming paradigm and compares procedural and object-oriented approaches. It also defines key Java concepts like classes, objects, inheritance and polymorphism. The document outlines Java's history and describes where it is commonly used today such as for desktop applications, web applications, and mobile apps. It explains the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). Finally, it provides an overview of how a typical Java program works by compiling Java code into bytecode that runs on the JVM.

Uploaded by

AK FREEZE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Programming Paradigms and Introduction To Java

This document provides an introduction to Java programming. It discusses Java's object-oriented programming paradigm and compares procedural and object-oriented approaches. It also defines key Java concepts like classes, objects, inheritance and polymorphism. The document outlines Java's history and describes where it is commonly used today such as for desktop applications, web applications, and mobile apps. It explains the Java Development Kit (JDK), Java Runtime Environment (JRE), and Java Virtual Machine (JVM). Finally, it provides an overview of how a typical Java program works by compiling Java code into bytecode that runs on the JVM.

Uploaded by

AK FREEZE
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

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

Information Hiding Public and Private Members

Polymorphism Function Overriding Function overloading

Inheritance Derived 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

• *We can write programs using both procedural as well as object-


oriented approach in Java. Java is more suited for object oriented
programming.
15
Where it is used?
According to Oracle, 3 billion devices run java. There are many
devices where java is currently used. Some of them are:
1. Desktop Applications such as acrobat reader, media player,
antivirus etc.
2. Web Applications such as irctc.co.in, etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games etc.
Types of Java Applications
There are mainly 4 type of applications that can be created using
java:
1) Standalone Application
It is also known as desktop application. An application that we need
to install on every machine such as media player, antivirus etc.

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

 JRE – Java Runtime Environment (to say JRE) is an installation


package which provides environment to only run(not develop) the
java program(or application)onto your machine.

 JVM – Java Virtual machine(JVM) is a very important part of both


JDK and JRE because it is contained or inbuilt in both. Whatever
Java program you run using JRE or JDK goes into JVM. JVM is
20
Source: https://www.quora.com/What-is-the-difference-between-Java-SDK-JRE-JVM-Java-SE-
Runtime-and-J2SE

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

• Program may not work on first try


• Make changes in edit phase and repeat

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

Class loader puts


Disk bytecodes in memory.
..
..
..
Primary
Memory
Phase 4 Bytecode Verifier Bytecode verifier
confirms that all
bytecodes are valid
and do not violate
Java’s security
.. restrictions.
..
..
Primary
Interpreter Memory Interpreter reads
Phase 5 bytecodes and
translates them into a
language that the
computer can
understand, possibly
.. storing data values as
.. the program executes.
..
28
Installing JDK and Sublime editor
•For executing any java program, you need to install the JDK if you
don't have installed it, download the JDK and install it.
•set path of the jdk/bin directory:
•https://java.com/en/download/help/path.xml

•Download Sublime editor from: https://www.sublimetext.com/


Write your first program
 Open Sublime
 Create a Folder JavaPrograms to save all your Java Programs
 Create another folder Program1
 Within Program1 create 2 folders: src and classes.
 Open src folder
 Open a file and save it as DisplayHello.java

30
DisplayHello.java

1 // Printing a line with multiple statements


2 // Program name must be same as Main class name
3 class DisplayHello {
All java applications
4 public static void main( String args[] ) begin execution by
5 { calling
main( ).
6 System.out.print( “Hello " );
7 System.out.println( “Hello!" );
System.out.print keeps the
cursor on the same line, so
9 }
System.out.println continues
10 } on the same line.
Note:
a) How to write Comments.
b) Code indentation.
c) program name same as class
name
d) System.out.println
31
Compile and Run
 Compiled code: .class file
 .class file should be saved in classes folder
 Syntax to compile: javac –d <pathOfClassesFolder>
DisplayHello.java
 Syntax to run:
 change directory to classes folder. (Use cd command)
 java DisplayHello

32
Resources for learning Java
a) Java How to Program, 10/e (Early Objects) by Paul J.
Deitel (Author), Harvey Deitel (Author)

b) Java: The Complete Reference  by Herbert Schildt

c) Head First Java by Bert Bates and Kathy Sierra

d) Detailed documentation of Java covered in


• http://java.sun.com

33

You might also like