[go: up one dir, main page]

0% found this document useful (0 votes)
35 views30 pages

Unit 1

Data base bcgg ggcgj

Uploaded by

darkside7448
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)
35 views30 pages

Unit 1

Data base bcgg ggcgj

Uploaded by

darkside7448
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/ 30

Object Oriented Programming

with JAVA
Krupali Dave, Assistant Professor
Computer Science & Engineering
UNIT-1
Design introduction
Index
• Object oriented programming,
• OOPS principles
• Encapsulation
• Inheritance and polymorphism java as a oops & Internet enabled language
• Importance of java
• Java usage in industry
• The byte code, compiling
• And running of simple java program,
• Jvm , Jdk , Jre
Object oriented programming
• Java is a programming language and a platform. Java is a high level, robust,
object-oriented and secure programming language.
• Java was developed by Sun Microsystems (which is now the subsidiary of Oracle)
in the year 1995. James Gosling is known as the father of Java. Before Java, its
name was Oak. Since Oak was already a registered company, so James Gosling
and his team changed the name from Oak to Java.
• Platform: Any hardware or software environment in which a program runs, is
known as a platform. Since Java has a runtime environment (JRE) and API, it is
called a platform.
Object oriented programming
• Let's have a quick look at Java programming example. A detailed description of
Hello Java example is available in next page.
• Simple.java
class Simple
{
public static void main(String args[])
{
System.out.println("Hello Java");
}
}
Object oriented programming
• According to Sun, 3 billion devices run Java. There are many devices where Java
is currently used. Some of them are as follows:
• Desktop Applications such as acrobat reader, media player, antivirus, etc.
• Web Applications such as irctc.co.in, javatpoint.com, etc.
1. Enterprise Applications such as banking applications.
2. Mobile
3. Embedded System
4. Smart Card
5. Robotics
6. Games, etc.
Object oriented programming
• Types of JAVA Application:
1. Standalone Application
2. Web Application
3. Enterprise Application
4. Mobile Application
• JAVA Platforms /Edition:
1. Java SE (Java Standard Edition)
2. Java EE (Java Enterprise Edition)
3. Java ME (Java Micro Edition)
4. JavaFX
OOPS principles
• Object-Oriented Programming is a paradigm that provides many concepts,
such as inheritance, data binding, polymorphism, etc.
• The popular object-oriented languages are Java, C#, PHP, Python, C++, etc.
• The main aim of object-oriented programming is to implement real-world entities,
for example, object, classes, abstraction, inheritance, polymorphism, etc.
• Object-Oriented Programming is a methodology or paradigm to design a program
using classes and objects.
OOPS principles
• It simplifies software development and maintenance by providing some concepts:
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
OOPS principles
1. Object: Any entity that has state and behaviour is known as an object. For
example, a chair, pen, table, keyboard, bike, etc. It can be physical or logical.

2. Class: Collection of objects is called class. It is a logical entity.

3. Inheritance: When one object acquires all the properties and behaviours of a
parent object, it is known as inheritance. It provides code reusability. It is used
to achieve runtime polymorphism.
OOPS principles
4. Polymorphism: The word “Polymorphism” derives from two words i.e. “Poly”
which means many and “morphs” meaning forms. Thus polymorphism means many
forms. In a programming language, we can say that an object can take many forms,
and hence the object is polymorphic.

5. Abstraction: Abstraction in Java is the process in which we only show essential


details/functionality to the user.
6. Encapsulation: Java Encapsulation is a way of hiding the implementation details
of a class from outside access and only exposing a public interface that can be used
to interact with the class.
Encapsulation:
• Encapsulation is a way to restrict the direct access to some components of an
object, so users cannot access state values for all of the variables of a particular
object.
• Encapsulation can be used to hide both data members and data functions or
methods associated with an instantiated class or object.
• A java class is the example of encapsulation.
• Java bean is the fully encapsulated class because all the data members are private
here.
Encapsulation:
• In classes, we have Data and attributes that perform operations on that data.
So according to the OOPs principle of Encapsulation, that data can be merged
into a single unit. Encapsulation enhances more security of the data as everything
related to a single task must be grouped and access to the data is given as per
need.
• And this can be achieved using the concept of Data Hiding.
• Encapsulation = Data Hiding + Abstraction.
Inheritance:
• In Java, it is possible to inherit attributes and methods from one class to another.
• We group the "inheritance concept" into two categories:
1. subclass (child) - the class that inherits from another class
2. superclass (parent) - the class being inherited from
• To inherit from a class, use the extends keyword.
• In the example below, the Car class (subclass) inherits the attributes and methods
from the Vehicle class (superclass):
Example:
class Vehicle {
protected String brand = "Ford";
Vehicle attribute public void honk(){
Vehicle method System.out.println("Tuut, tuut!");
} }
class Car extends Vehicle {
private String modelName = "Mustang";
Car attribute public static void main(String[] args) {
Create a myCar object Car myCar = new Car();
Call the honk() method (from the Vehicle class)
on the myCar object myCar.honk(
Display the value of the brand attribute (from the Vehicle class)and
the value of the modelName from the
Car class System.out.println(myCar.brand + " " + myCar.modelName);
}}
Polymorphism java as a oops:
• Polymorphism means "many forms", and it occurs when we have many classes
that are related to each other by inheritance.
• Like we specified in the previous topic; Inheritance lets us inherit attributes and
methods from another class. Polymorphism uses those methods to perform
different tasks. This allows us to perform a single action in different ways.
• For example, think of a superclass called Animal that has a method
called animalSound().
• Subclasses of Animals could be Pigs, Cats, Dogs, Birds – And they also have
their own implementation of an animal sound (the pig oinks, and the cat meows,
etc.):
Example:
class Animal {
public void animalSound()
{ System.out.println("The animal makes a sound");
}
}
class Pig extends Animal {
public void animalSound()
{ System.out.println("The pig says: wee wee");
}
}
class Dog extends Animal { public void animalSound() {
System.out.println("The dog says: bow wow");
}
}
Importance of java:
• OOPs makes development and maintenance easier, whereas, in a procedure-
oriented programming language, it is not easy to manage if code grows as
project size increases.
• OOPs provides data hiding, whereas, in a procedure-oriented programming
language, global data can be accessed from anywhere.
• OOPs provides the ability to simulate real-world event much more effectively.
We can provide the solution of real word problem if we are using the Object-
Oriented Programming language.
Java usage in industry:
• The IT industry, especially in India, heavily uses Java in most of their projects.
Being a Java developer , on should have the knowledge about the Java-based
tools and technologies used by the most of the IT industries such as Android
application development, Web Development.
• Classification of Java Tools/Technologies Based on Different Fields
1. Web Development
2. Android Application
The Byte code:
• Java bytecode is the instruction set for the Java Virtual Machine (JVM).
• It plays a crucial role in executing programs written in the Java language and
other JVM-compatible languages. Here are some key points about Java bytecode:

➢ What is Java Bytecode?


• Java bytecode consists of a series of instructions that the JVM interprets.
• Each bytecode operation is represented by a single byte, which is why it’s called
“bytecode.” This compact form of instruction allows for efficient execution.
The Byte code:
➢ How Is Bytecode Generated?
• When you write a Java program, you create source code (e.g., .java files).
• The compiler converts this source code into bytecode (or machine code). This
bytecode is stored in a .class file.
• The Java Virtual Machine (JVM) then executes this bytecode.
➢ Why Is Bytecode Important?
• Java bytecode makes Java a platform-independent language.
• Here’s how it works:
• You write your program in a high-level language like Java.
• The compiler translates your Java source code into bytecode.
• The JVM (interpreter) executes this bytecode on any platform.
Compiling:
• When compiling a Java program, there are two main
steps: compilation and execution. Let’s break it down:
• Compilation:
•You write your Java code in a .java file (also known as the source file).
•The Java compiler (javac) processes this source code and converts it into bytecode.
•Each class in your source file gets stored in a separate .class file.
•The bytecode is platform-independent and can run on any system.
• Execution:
•The class files generated during compilation are machine-independent.
•To run your program, you pass the main class file (the one containing
the main method) to the Java Virtual Machine (JVM).
Running of simple java program:
class Test
{
public static void main(String []args)
{
System.out.println("My First Java Program.");
}
};
JVM:
• JVM (Java Virtual Machine) is an abstract machine.
• It is called a virtual machine because it doesn't physically exist.
• It is a specification that provides a runtime environment in which Java bytecode
can be executed.
• It can also run those programs which are written in other languages and compiled
to Java bytecode.
• JVM, JRE, and JDK are platform dependent because the configuration of each
OS is different from each other. However, Java is platform independent.
There are three notions of the JVM: specification, implementation, and
instance.
JVM:

• The JVM performs the following main tasks:


1. Loads code
2. Verifies code
3. Executes code
4. Provides runtime environment
JRE:

• JRE is an acronym for Java Runtime Environment. It is also written as Java RTE.
The Java Runtime Environment is a set of software tools which are used for
developing Java applications. It is used to provide the runtime environment. It is the
implementation of JVM. It physically exists. It contains a set of libraries + other files
that JVM uses at runtime.
• The implementation of JVM is also actively released by other companies besides Sun
Micro Systems.
JRE:
JDK:

• JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a
software development environment which is used to develop Java applications and
applets. It physically exists. It contains JRE + development tools.
• The JDK contains a private Java Virtual Machine (JVM) and a few other resources
such as an interpreter/loader (java), a compiler (javac), an archiver (jar), a
documentation generator (Javadoc), etc. to complete the development of a Java
Application.
JDK:
www.paruluniversity.ac.
in

You might also like