0% found this document useful (0 votes)
39 views19 pages

INTRODUCTION TO JAVA CH 1-2

The document discusses procedural programming versus object-oriented programming. Procedural programming follows a top-down approach and focuses on functions while object-oriented programming follows a bottom-up approach and focuses on objects. The document provides examples of languages for each paradigm.

Uploaded by

Abhijit Bhatjire
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)
39 views19 pages

INTRODUCTION TO JAVA CH 1-2

The document discusses procedural programming versus object-oriented programming. Procedural programming follows a top-down approach and focuses on functions while object-oriented programming follows a bottom-up approach and focuses on objects. The document provides examples of languages for each paradigm.

Uploaded by

Abhijit Bhatjire
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/ 19

BY: Prof Pavan Malani

Procedural Oriented Object Oriented Programming


Programming
It is a programming language that is Object-oriented programming is a computer
derived from structure programming and programming design philosophy or
based upon the concept of calling methodology that organizes/ models
procedures software design around data or objects rather
than functions and logic.
It is less secure than OOPs. Data hiding is possible in object-oriented
programming due to abstraction. So, it is
more secure than procedural programming.
It follows a top-down approach. It follows a bottom-up approach
In procedural programming, data moves In OOP, objects can move and communicate
freely within the system from one function with each other via member functions.
to another.

In Procedural programming, a program is In OOP, a program is divided into small parts


divided into small programs that are referred that are referred to as objects.
to as functions.

Examples :- C, Fortran, Pascal, and VB. Examples:-Python, Java, C#.NET, and C++.
 Objects: Any entity that has state and behavior is known as
an object. For example, a chair, pen, table, keyboard, bike,
etc. It can be physical or logical. An Object can be defined as
an instance of a class.
 Class
Collection of objects is called class. It is a logical entity. A class
can also be defined as a blueprint from which you can create
an individual object.
 Inheritance
When one object acquires all the properties and behaviors of
a parent object, it is known as inheritance. It provides code
reusability.
 Polymorphism
If one task is performed in different ways, it is known as
polymorphism. For example: to convince the customer
differently, to draw something, for example, shape, triangle,
rectangle, etc.
 In Java, we use method overloading and method overriding
to achieve polymorphism

Another example can be to speak


something; for example, a cat speaks
meow, dog barks woof, etc
Abstraction
Hiding internal details and showing functionality is known as
abstraction. In Java, we use abstract class and interface to achieve
abstraction.

Encapsulation
Binding (or wrapping) code and data together into a single unit
are known as encapsulation.
A java class is the example of encapsulation.
 Java was designed by sun microsystem of USA in 1991
originally it was known as " Oak " language which is
develop by ‘James Gosling". Further in 1995 it was
renamed as Java.
 Java runs on a variety of platforms, such as Windows, Mac OS,
and the various versions of UNIX.
 Mostly Java is used to design application software .
Software's for electronics devices such as TV, VCR ,Mobile
Games etc.
 Features of Java:
 The features of java is also known as buzzwords
Features of java
1.Complied & Interpreted Language
Javac Java
Source code Byte code Machine
compiler
java file interpreter

Java source program can be compile by using Javac compiler which


produces byte code that it is (.class file ) but these byte code is not exactly
machine code so there is need of Java interpreter which converts byte code
into machine code which is directly executed by machine that’s why Java is
known as compile and interpreted language.
2. OBJECT ORIENTED LANGUAGE
The object is runtime entity which is used to access variables and
method of class.
The keyword “new” is used to create object of a class
Syntax:
class name object name=new class name();
eg. abc t =new abc();
Here abc is class and t is object or instance of that class.
3. ROBUST & SECURE LANGUAGE
There are 3 reasons due to which Java is known as Robust & Secure
language
a. Java is garbage collected language it means Java free all the memory
occupied by object Automatically if is not in used.
b. Java support the concept of exception handling to handle run time
error.
c. In Java due to absence of pointer no one can access the memory
location without proper authorization.
4. Distributed Language
Java is designed as distributed language for creating an application on
the network. It has an ability to share both data and program within the
network.
This feature enabled multiple programmers from multiple remote
location to collaborate & work on single project.
5.Multithreading & Interactive
Thread means process of execution when there are multiple process execute
simultaneously it is known as multi threading. Because of multithreading the
performance of java is very high as compared to C and C++.
6. Architecture-neutral −
Java compiler generates an architecture-neutral object file format,
which makes the compiled code executable on many processors, with
the presence of Java runtime system.
JAVA and INTERNET
Java is strongly associated with internet hence we require web browser to
run applet on internet.
Internet users can use java to create an applet and run them using java
enabled browser such as hot java or Netscape navigator etc. Java also
supports the protocols which are used for networking such as TCP/IP and
UDP.
We can also use java’s browser to download an applet located on computer
anywhere in the internet & run it on local applet. Due to above reason java is
known as Internet language.
 Demo program
class sample
{
public static void main(String args[])
{
int i=10;
System.out.println (“ Welcome to Java”);
System.out.println (“The value of i” +i);
}
}
Save the above code. as sample.java
Compilation : javac sample. java
To run Code : java sample
Note: Java is case sensitive language it means we have to differentiate
between capital & small letters
All the java code is saved using class name
Meaning of public static void main
Public: The public is a access specifier that declares the main
method and making it available or accessible to all other classes.
Static: It means the main method belongs to entire class but it is
not part of any object
void :It states that main method does not return any value.
String args: It is a command line argument during execution if
we are pass some argument that are stored in args.
System.out. println (" ");
It is similar to printf or cout statement since java is pure Object
oriented language so every method is a part of object here
System is a class out is the object and println is method of that
class.
Datatypes
Datatype

Boolean type Numeric type

Boolean Integer type Floating point

char integral float double

byte short int long

Primitive data types are characterized as follows


1) Integer type
a)Byte : 1 byte memory
b) short : 2byte
c) int : 4 byte
d) long : 8 byte
2)floating point types:
i) float: 4 byte
ii) double : 8 byte
3) Boolean types :
i) Boolean : 1 byte.
4) Characters:
Characters in java is not same as characters in C and C++.In java it is of 16
bit i.e. 2 bytes and they are called as universal or unicode characters
Unicode is a standard that represents characters in all human languages i.e it
consists of characters from latin, greek, italic etc. There are total 65535
characters in java.
Type Conversion and type casting :
To assign the value of one type of variable to another type if the 2 types are
compatible (same group) then java will perform type conversion
automatically. To perform this type conversion 2 conditions are to be
satisfied
1) Both the types of variable are compatible.
2) Source type must be less than destination type it means byte can be
converted into short int or long but the opposite conversion is not possible.
Type Casting:
To create conversion between 2 incompatible types (Float to
int) then we must use cast operator ie. explicit type conversion.
(Target datatype ) expression ;
eg float a= 3.5
int z = (int)a; o/p: 3
 Java Development Tools
Tool Name Description
javac It is a java compiler which converts source code into byte
code.
java It is a interpreter which is used to execute byte code
javap It is a dissembler which works to reverse to javac that
converts byte code into source code description.

javadoc: The documentation generator, which automatically


generates documentation from source code comments
jdb: the debugger.
Appletviewer: Used to execute java's applet program.
JAR The specifies the archiver, which packages related class
libraries into a single JAR file. This tool also helps manage
JAR files.
 Scanner Class:
Scanner class in Java is found in the java.util package.
Java provides various ways to read input from the
keyboard, the java.util.Scanner class is one of them.
Methods of Scanner class

nextDouble() Reads a double value from the


user
nextFloat() Reads a float value from the
user
nextInt() Reads a int value from the
user
nextLine() or next() Reads a String value from the
user
Write a java code to accept employee name, age and salary from user and display
it.
import java.util.*;
class emp
{
public static void main(String args[])
{
Scanner t=new Scanner(System.in);
System.out.println("Enter employee name");
String nm=t.next();
System.out.println("Enter employee age");
int age=t.nextInt();
System.out.println("Enter employee salary");
float sal=t.nextFloat();
System.out.println("Employee name is"+nm);
System.out.println("employee age is"+age);
System.out.println("Employee salary is"+sal);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy