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

Java - Lect1

The document discusses different programming paradigms including imperative, object-oriented, procedural, and declarative paradigms. It provides examples of languages that use each paradigm and compares procedural to object-oriented programming. It also covers topics like Java history, features, tokens, and control statements.

Uploaded by

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

Java - Lect1

The document discusses different programming paradigms including imperative, object-oriented, procedural, and declarative paradigms. It provides examples of languages that use each paradigm and compares procedural to object-oriented programming. It also covers topics like Java history, features, tokens, and control statements.

Uploaded by

TUSHAR NAMA
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 26

Imperative programming paradigm:

• It is one of the oldest programming paradigm.


• It is based on Von Neumann machine architecture.
• It works by changing the program state through assignment statements.
It performs step by step task by changing state.

Examples of Imperative programming paradigm:

• C : developed by Dennis Ritchie and Ken Thompson


• Fortran : developed by John Backus for IBM
• Basic : developed by John G Kemeny and Thomas E Kurtz
Imperative Languages
Advantages :

• Very simple to implement


• It contains loops, variables etc.

Disadvantage:

• Complex problem cannot be solved


• Less efficient and less productive
• Parallel programming is not possible
Imperative programming is divided into three broad categories: Procedural, OOP and
parallel processing.

Procedural Programming :

There is no difference in between procedural and imperative approach. It has the ability to
reuse the code and it was boon at that time when it was in use because of its reusability.

Examples of Procedural programming paradigm:

C : developed by Dennis Ritchie and Ken Thompson

C++ : developed by Bjarne Stroustrup

Java : developed by James Gosling at Sun Microsystems


• Objective-C : designed by Brad Cox
• Visual Basic .NET : developed by Microsoft
• Python : developed by Guido van Rossum
• Ruby : developed by Yukihiro Matsumoto
• Smalltalk : developed by Alan Kay, Dan Ingalls, Adele Goldberg
OOD Principle
• The program is written as a collection of classes and object which are meant
for communication.
• The smallest and basic entity is object and all kind of computation is
performed on the objects only.
• More emphasis is on data rather procedure.

Advantages:

• Data security
• Inheritance
• Code reusability
• Flexible and abstraction is also present
Parallel processing approach –

• Parallel processing is the processing of program instructions by


dividing them among multiple processors.

• A parallel processing system posses many numbers of processor with


the objective of running a program in less time by dividing them.

• This approach seems to be like divide and conquer.

• Examples are NESL (one of the oldest one) and C/C++ also supports
because of some library function.
Declarative programming paradigm:

• It is divided as Logic, Functional, Database.

• In computer science the declarative programming is a style of building


programs that expresses logic of computation without talking about its
control flow.

• Difference between imperative (how to do) and declarative (what to do)


programming paradigms.

• Declarative paradigm classified into logic, functional and database.


Logic Programming
In logical programming the main emphasize is on knowledge base and

the problem. Eg: PROLOG


Functional programming
The key principle of these languages is the execution of series of mathematical
functions. Function can be replaced with their values without changing the meaning of
the program.
Examples:

JavaScript : developed by Brendan Eich

Haskell : developed by Lennart Augustsson, Dave Barton

Scala : developed by Martin Odersky

Erlang : developed by Joe Armstrong, Robert Virding

Lisp : developed by John Mccarthy

ML : developed by Robin Milner

Clojure : developed by Rich Hickey .


Database/Data driven programming

• provides file creation, data entry, update, query and reporting


functions.
• Example: SQL
Difference between Procedural and OO Languages
Procedural Programming
-derived from structured programming, based upon the concept of
calling procedure.
-Procedures, also known as routines, subroutines or functions,
-During a program’s execution, any given procedure might be called at
any point, including by other procedures or itself.
-In procedural programming, the function is more important than the
data.

Example : Basic, Pascal , fortran and C


Object-Oriented Programming

• Object-oriented programming can be defined as a programming


model which is based upon the concept of objects.

• Objects are instances of class that contain data in the form of


attributes and code in the form of methods.
• In object-oriented programming, data is more important than function.

• Examples : Java, C++, C#, Python, PHP, JavaScript, Ruby, Perl,


Objective-C, Dart, Swift, Scala.
Java evolution and History

• Java was originally developed by James Gosling at Sun Microsystems. It

was released in May 1995 as a core component of Sun Microsystems'

Java platform.

• The original and reference implementation Java compilers, virtual

machines, and class libraries were originally released by Sun under

proprietary licenses
• There are four platforms of the Java programming language:
1. Java Platform, Standard Edition (Java SE): defines everything
- basic types
- objects to high-level classes for
- networking, security, database access, graphical user interface (GUI) development,
and XML parsing.
2. Java Platform, Enterprise Edition (Java EE): It is on top of Java SE. It provides API and runtime
environment for developing and running large-scale, multi-tiered, scalable, reliable, and secure
network applications.
3. Java Platform, Micro Edition (Java ME):provides an API and a small-footprint virtual machine
for running Java programming language applications on small devices, like mobile phones.
4. JavaFX: is a platform for creating rich internet applications using a lightweight user-interface
API.
Features of Java
1. Java is both compiled and interpreted language: Java compiler translates
source code into bytecode instructions. Bytecode are not machine
instructions so in second stage , Java interpreter generates machine code
that can be directly executed by the machine running the java program.
2. Platform independent and portable: java compiler generates bytecode
instructions implemented on any machine. Also, the size of the primitive data
types are machine-independent.
3. Object –oriented: everything in Java is an object. All program code and data
reside within objects and classes.
4. Robust and Secure: Java ensures reliable code. Because
- garbage collected language: The garbage collector finds these unused
objects and deletes them to free up memory. (automatic memory management).
-handles memory management mistakes.
-Exception handling : captures series of errors and eliminates risk of crashing
the system.
- Strict compile time and run-time checking for data types.
- Absence of pointers ensures not to have direct access to memory
locations.

5. Distributed: it is used to create applications on network. Eg: Web


browsers are distributed applications consisting of the back-end (server)
software and the front-end (client) software.

6. Simple , Small and Familiar: Java do not use pointers, preprocessor


header files, goto statements, operator overloading, multiple
inheritance. It is simplified version of C++.
7. Multithreaded and Interactive: Java runtime comes with tools that support
multiprocessor synchronization that handles multiple tasks simultaneously.
8. High Performance: Java architecture has multithreading that enhances the
overall execution speed of Java programs so reduces overheads during
runtime.
9. Dynamic and Extensible: Java support functions written in languages like C
and C++. These are native methods/functions for Java and can be linked with
java program dynamically at run time.
10. Ease of Development : J2SE 5.0 support Generics, Autoboxing , Unboxing ,
Varagrs, static import , Annotation. these features reduce the work of the
programmer shifting responsibility to write reusable code to the compiler.
Hence source code becomes free of bugs as errors made by compiler are less
than programmers.
11. Scalability and Performance: J2SE 5.0 improves the start up time
( loading core classes from jar files ) and reduces the amount of
memory used in Java 2 runtime environment.
12. Monitoring and Manageability : Java supports a number of APIs like
JVM Monitoring and Management API ( to track information at
application level and JVM level ie when deploying a large application ).
Tools used for monitoring and management facilities of applications
like : jconsole, jps, jstat, jstatd etc.
Java Tokens
5 types of Tokens

1. Reserved Keywords

2. Identifiers

3. Literals

4. Operators

5. Separators
Keywords and Identifiers
• Java is case sensitive so we can use these words as identifiers by changing letters
to upper case.

• Plz see table of keywords for Java.

• Identifiers: these are programmer-designed tokens. They are used for naming
classes, methods, variables , objects, labels, packages and interfaces .
• Rules:
1. Identifiers can have digits, alphabets underscore and dollar sign.
2. Not begin with a digit
3. Case sensitive
4. Any length
1. Names of public methods and instance variables start with lowercase
letter.
Eg: average, sum
2. If more than one words in name then,
dayTemp, firstDayOfMonth, totalMarks
3. All private and local variables can start with lowercase combined with
underscore.
length, class_strength
4. All classes and interfaces start with leading upper class letter
Student, HelloJava, Vehicle
5. Symbolic constants : variables having constant values use all uppercase
letters and underscore.
TOTAL, F_MAX
Literals : represent constant values stored in variables .
Integer literals, Floating point literals, character literals, String literals
and Boolean Literals

Operators: takes one or more arguments and operates on them

Separators:
(), { }, [ ], ; , .
, used to separate variables.
. Used to separate package names from sub-packages and classes
Java Control Statements
1. Selection: if , if –else, switch

2. Iteration: while, do , for

3. Jump: break, continue, return

You might also like