SlideShare a Scribd company logo
Introduction to Java
Java Evolution;History; Java and the Internet; How Java differs from C and C++; Features;
platform-independent nature of java; Overview of Java; simple Java program; Structure;
Fundamentals of Object-Oriented Programming; Object-Oriented Paradigm; Basic
Concepts of Object-Oriented Programming; Benefits of Object-Oriented Programming;
application of Object-Oriented Programming;
Java Development Kit (JDK); Java interpreter; Byte Code; Java Virtual Machine.
History of Java
➔ Java is a general-purpose, object-oriented programming language
developed by Sun Microsystems of USA in 1991.
➔ Java was developed by a team led by James Gosling and his colleague Mike
Sheridan and Patrick Naughton.
UNIT 1 Programming in java Bsc program.pptx
History of Java
➔ They named this project “Greentalk”, and the file extension was called .gt.
➔ Finally, James Gosling named the project “Oak” after the Oak tree planted
outside the office of Sun Microsystems.
➔ He named the software – “Java” in 1995. This name was based on the name
of an espresso bean he thought of while having coffee near his office.
History of Java
➔ Java was designed for the development of software for consumer electronic
devices like TVs, VCRs, toasters and such other electronic machines.
➔ The goal had a strong impact on the development team to make the
language simple, portable and highly reliable.
History of Java
➔ The most striking feature of the language is that it is a platform-neutral
language.
➔ Programs developed in Java can be executed anywhere on any system.
➔ Write Once Run Anywhere (WORA).
➔ Designed for easy Web/Internet applications
➔ In 1993 Java Was So Popular in the World Wide Web or in the Internet For
Developing Games and Graphical Applications with the help of Applets
History of Java
History of Java
➔ In 1995, Sun Microsystems released the first Java version, java 1.0. After
that, it was incorporated into web browsers.
➔ This also made the Java team realise that the Internet would be the perfect
network to promote their product.
History of Java
The latest version of Java is Java 22 or JDK 22 released on
March, 19th 2024
platform-independent nature of java
➔ The meaning of Java platform-independent is that the Java compiled
code(byte code) can run on all operating systems.
➔ A program is written in a language that is human-readable.
➔ For the source code to be understood by the machine, it needs to be in a
language understood by machines, typically a machine-level language.
➔ The compiler converts the high-level language (human language) into a format
understood by the machines.
platform-independent nature of java
➔ Step-by-Step Execution of Java Program
➔ Whenever a program is written in JAVA, the java compiles it.
➔ The result of the JAVA compiler is the .class file or the bytecode and not the
machine’s native code (unlike the C compiler).
➔ The bytecode generated is a non-executable code and needs an interpreter to
execute on a machine.
➔ This interpreter is the JVM ( Java Virtual Machine ) and thus the Bytecode is
executed by the JVM.
➔ And finally, the program runs to give the desired output.
platform-independent nature of java
➔ In the case of C or C++ (languages that are not platform independent), the
compiler generates an executable file (such as a .exe file) which is both OS-
dependent and CPU-dependent.
platform-independent nature of java
➔ platform-independent nature of java adds to an important feature in the JAVA language
termed portability.
➔ Every system has its own JVM which gets installed automatically when the JDK (Java
Development Kit ) software is installed.
➔ For every operating system separate JVM is available which is capable to read the .class
file or byte code.
➔ An important point to be noted is that while JAVA is a platform-independent language,
the JVM is platform-dependent.
➔ Different JVM is designed for different OS and byte code is able to run on different OS.
UNIT 1 Programming in java Bsc program.pptx
Java Development Kit (JDK)
➔ Java Development Kit (JDK) is a software development environment used
for developing Java applications and applets.
➔ It includes the Java Runtime Environment (JRE), an interpreter/loader (Java),
a compiler (javac), an archiver (jar), a documentation generator (Javadoc),
and other tools needed in Java development.
Java Runtime Environment
➔ JRE stands for “Java Runtime Environment” .
➔ The Java Runtime Environment provides the minimum requirements for
executing a Java application; it consists of the Java Virtual Machine (JVM),
core classes, and supporting files.
JVM (Java Virtual Machine)
➔ JVM (Java Virtual Machine) 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 and JVM is
responsible for executing the java program line by line, hence it is also
known as an interpreter.
UNIT 1 Programming in java Bsc program.pptx
Java Interpreter
➔ The interpreter reads and executes bytecode instructions line-by-line or
instruction-by-instruction.
➔ It performs the translation from bytecode to native machine code
dynamically at runtime.
➔ It translates bytecode into native instructions, which are then executed by
the host machine’s CPU.
JAVA FEATURES
➔ The primary objective of Java programming language creation was to make
it a portable, simple and secure programming language.
➔ he features of Java are also known as Java buzzwords.
UNIT 1 Programming in java Bsc program.pptx
JAVA FEATURES
Simple
➔ Java is easy to learn and its syntax is quite simple, clean and easy to
understand.
➔ Eg : Pointers and Operator Overloading are not there in java but were an
important part of C++.
JAVA FEATURES
Object Oriented
➔ In java everything is an Object which has some data and behavior.
➔ Java can be easily extended as it is based on Object Model.
JAVA FEATURES
Robust
➔ Java makes an effort to eliminate error prone codes by emphasizing mainly
on compile time error checking and runtime checking.
➔ But the main areas which Java improved were Memory Management and
mishandled Exceptions by introducing automatic Garbage Collector and
Exception Handling.
JAVA FEATURES
Platform Independent
➔ Java guaranteed to be a write-once, run-anywhere language.
➔ On compilation Java programs are compiled into bytecode.
➔ This bytecode is platform independent and can be run on any machine, plus
this bytecode format also provides security.
JAVA FEATURES
Secure
➔ When it comes to security, Java is always the first choice.
➔ With java secure features it enables us to develop virus free, tamper free
systems.
➔ Java programs always run in a Java runtime environment with almost null
interaction with system OS, hence it is more secure.
JAVA FEATURES
Multi Threading
➔ Java multithreading feature makes it possible to write programs that can do many
tasks simultaneously.A thread is like a separate program, executing concurrently.
➔ Benefit of multithreading is that it utilizes the same memory and other resources to
execute multiple threads at the same time, like While typing, grammatical errors are
checked along.
➔ The main advantage of multi-threading is that it doesn't occupy memory for each
thread. It shares a common memory area.
JAVA FEATURES
Architectural Neutral
➔ Compilers generate bytecodes, which have nothing to do with a particular
computer architecture, hence a Java program is easy to interpret on any
machine.
JAVA FEATURES
Portable
➔ Java Byte code can be carried to any platform.
➔ No implementation dependent features.
➔ Everything related to storage is predefined, example: size of primitive data
types
JAVA FEATURES
High Performance
➔ Java is an interpreted language, so it will never be as fast as a compiled
language like C or C++.
➔ But, Java enables high performance with the use of just-in-time compilers.
JAVA FEATURES
Distributed
➔ Java is distributed because it facilitates users to create distributed
applications in Java. RMI and EJB are used for creating distributed
applications.
➔ This feature of Java makes us able to access files by calling the methods
from any machine on the internet.
JAVA FEATURES
Dynamic
➔ Java is a dynamic language.
➔ It supports the dynamic loading of classes.
➔ It means classes are loaded on demand.
JAVA DIFFERENT FROM C AND C++
1. C Uses header Files but java uses Packages.
2. C Uses Pointers but java doesn't supports pointers.
3. The Code of C Language is Converted into the Machine code after
Compilation But in Java Code First Converted into the Bytes Codes then
after it is converted into the Machine Code.
4. C++ supports Operator Overloading but java doesn't Supports Operator
Overloading.
5. In C++ Multiple Inheritance is Possible but in java A Class Can not Inherit
the features from the two classes in other words java doesn't supports
Multiple Inheritance
JAVA DIFFERENT FROM C AND C++
6. Java Uses import statement for including the contents of screen instead of
#include.
7. Java Doesn't uses goto.
8. Java Doesn't have Destructor like C++ Instead Java Has finalize Method.
9. Java Doesn't have Structure Union , enum data types.
10.C++ needs manual garbage memory clearance whereas Java has an
automatic garbage collector
JAVA DIFFERENT FROM C AND C++
11.Java does not have preprocessor, so we can’t use #define, #include and
#ifdef statements.
12.Java does not perform automatic type conversions that result in loss of
precision.
13.It is not possible to declare unsigned integers in java.
14.Java does not support global variables. Every method and variable is
declared within a class and forms part of that class.
Object-Oriented Programming- paradigms
➔ Emphasis is on data rather than procedure.
➔ Programs are divided into what are known as Objects.
➔ Data structures are designed such that they characterize the objects.
➔ Methods that operate on the data of an object are tied together in the data
structure
➔ Data is hidden and cannot be accessed by external functions.
➔ Objects may communicate with each other through methods.
➔ New data and methods can be easily added whenever necessary.
➔ Follows bottom-up approach in program design.
Object-Oriented Programming- paradigms
➔ Class: A blueprint or template for creating objects.
➔ It defines a type of object and encapsulates data and methods that operate
on that data.
➔ It has its own data members and member functions.
➔ The data members inside the class are manipulated using these member
functions.
➔ Example: class Car { }
Object-Oriented Programming- paradigms
➔ Object: An instance of a class. It represents a concrete entity with state and
behavior.
➔ Notably, the system does not allocate any memory space when a class is
specified, but it’s allocated when it is instantiated, i.e., when an object is
formed.
➔ Example: Car myCar = new Car();
Fundamentals of Object-Oriented Programming
➔ OOP allows objects to interact with each other using four basic principles:
➔ Encapsulation,
➔ Inheritance,
➔ Polymorphism, and
➔ Abstraction.
➔ These four OOP principles enable objects to communicate and collaborate to
create powerful applications.
Fundamentals of Object-Oriented Programming
Encapsulation
➔ Encapsulation is defined as the wrapping up of data under a single unit.
➔ It is the mechanism that binds together code and the data it manipulates.
➔ In Encapsulation, the variables or data of a class are hidden from any other
class and can be accessed only through any member function of their class
in which they are declared.
➔ As in encapsulation, the data in a class is hidden from other classes, so it is
Fundamentals of Object-Oriented Programming
Encapsulation
Fundamentals of Object-Oriented Programming
Inheritance
➔ Inheritance is an important pillar of OOP(Object-Oriented Programming).
➔ A class derives properties and characteristics from another class is called Inheritance.
➔ When we write a class, we inherit properties from other classes.
➔ So when we create a class, we do not need to write all the properties and functions
again and again, as these can be inherited from another class that possesses it.
➔ Inheritance allows the user to reuse the code whenever possible and reduce its
redundancy.
Fundamentals of Object-Oriented Programming
Inheritance
Fundamentals of Object-Oriented Programming
Inheritance
Fundamentals of Object-Oriented Programming
Polymorphism
➔ The word polymorphism means having many forms.
➔ In simple words, we can define polymorphism as the ability of a message to
be displayed in more than one form.
➔ For example, A person at the same time can have different characteristics.
Like a man at the same time is a father, a husband, an employee.
➔ So the same person posses different behavior in different situations.
➔ This is called polymorphism.
Fundamentals of Object-Oriented Programming
Polymorphism
Fundamentals of Object-Oriented Programming
Abstraction
➔ It is the ability to represent important information for the context of the
problem.
➔ And hiding all the implementation details
➔ Eg: normal user use different apps but they are unaware of the code that
makes the app
➔ This pillar aims to abstract only what we need to solve the problem and its
Benefits of Object-Oriented Programming
➔ Code Reusability: Inheritance supports the reusability of code.
➔ Simple Troubleshooting: the data and the methods that operate on it are
kept together in the same class, allowing for easier organization and
debugging of the code.
➔ Prevents Data Redundancy: Using encapsulation, OOPs help reduce data
redundancy by allowing to reuse of data in multiple classes. This means that
without having to rewrite, the same data can be used in multiple classes.
➔ Modularity: Modularity helps break down complex code into smaller, more
manageable chunks..
Benefits of Object-Oriented Programming
➔ Code Maintenance: OOPs provide tools such as inheritance, abstraction,
and encapsulation that make it easier to modify, maintain, and debug code.
➔ Code Security: Data abstraction and encapsulation in Java provide security
advantages by allowing the user to restrict access to certain data and
methods.
➔ Problem-Solving Ability: Object-oriented programming (OOPS) is a
powerful approach to solving complex problems by breaking them down
into smaller, bite-sized components. It enables modules with the same
interface to replace smaller codes. This approach enables efficient problem-
solving and improved overall performance
Applications of Object-Oriented Programming
➔ Object-Oriented Databases: They are also called Object Database
Management Systems (ODBMS). These databases store objects instead of
data, such as real numbers and integers. Objects consist of the following:
➔ Attributes: Attributes are data that defines the traits of an object. This data
can be as simple as integers and real numbers. It can also be a reference to
a complex object.
➔ Methods: They define the behavior and are also called functions or
procedures.
Applications of Object-Oriented Programming
➔ Real-Time System Design: Real time systems inherit complexities that
makes difficult to build them. Object-oriented techniques make it easier to
handle those complexities.
➔ Office Automation Systems: These include formal as well as informal
electronic systems primarily concerned with information sharing and
communication to and from people inside as well as outside the
organization.
➔ Client-Server Systems: Object-oriented Client-Server Systems provide the IT
infrastructure, creating object-oriented Client-Server Internet (OCSI)
applications.
Applications of Object-Oriented Programming
➔ CIM(Computer integrated manufacturing)/CAD(computer aided
design)/CAM Systems(Computer aided manufacturing): OOP can also be
used in manufacturing and design applications as it allows people to reduce
the effort involved.
➔ For instance, it can be used while designing blueprints, flowcharts, etc.
➔ OOP makes it possible for the designers and engineers to produce these
flowcharts and blueprints accurately
Java and the Internet
Networking Capabilities
➔ Java has built-in support for network programming.
➔ The java.net package provides classes for implementing network protocols
and handling network communications.
➔ This includes the ability to create sockets for TCP/IP communication, making
Java ideal for developing networked applications.
Java and the Internet
➔ Internet users use Java to create the applet programs and run them locally
using 'Java-enabled browsers' like HotJava.
Java and the Internet
What is Applet?
➔ An applet is a small Java program that can be embedded into a web page to
generate dynamic content.
➔ It runs inside the web browser and works at client side.
➔ An applet is embedded in an HTML page using the APPLET or OBJECT tag and
hosted on a web server.
➔ Applets are used to make the website more dynamic and entertaining.
Java and the Internet
➔ Java is a platform-independent, object-oriented programming language
(OOP).
➔ It is not to be confused with JavaScript, a scripting language used to create
dynamic web pages.
Structure of Java Program
Structure of Java Program
Documentation Section
➔ The documentation section is an important section but optional for a
Java program.
➔ It includes basic information about a Java program.
➔ It improves the readability of the program.
➔ Whatever we write in the documentation section, the Java compiler
ignores the statements during the execution of the program.
Documentation Section
➔ Single-line Comment: It starts with a pair of forwarding slash (//).
➔ For example: //First Java Program
➔ Multi-line Comment: It starts with a /* and ends with */. We write
between these two symbols.
➔ For example: /*It is an example of
multiline comment*/
Package Declaration
➔ The package declaration is optional.
➔ It is placed just after the documentation section.
➔ In this section, we declare the package name in which the class is
placed.
➔ Note that there can be only one package statement in a Java program.
➔ It must be defined before any class and interface declaration.
package mypack;
UNIT 1 Programming in java Bsc program.pptx
Import Statements
➔ The package contains the many predefined classes and interfaces.
➔ If we want to use any class of a particular package, we need to import
that class.
➔ The import statement represents the class stored in the other package.
➔ We use the import keyword to import the class.
import java.util.Scanner; //it imports the Scanner class only
import java.util.*; //it imports all the class of the java.util
package
Interface Section
➔ It is an optional section.
➔ We can create an interface in this section if required.
➔ We use the interface keyword to create an interface.
➔ An interface is a slightly different from the class.
➔ It contains only constants and method declarations.
Interface Section
➔ It is an optional section.
➔ We can create an interface in this section if required.
➔ We use the interface keyword to create an interface.
➔ An interface is a slightly different from the class.
➔ It contains only constants and method declarations.
Interface Section
interface car
{
void start();
void stop();
}
Class Definition
➔ In this section, we define the class. It is vital part of a Java program.
➔ A Java program may contain more than one class definition.
➔ We use the class keyword to define the class.
➔ It contains information about user-defined methods, variables, and
constants.
➔ Every Java program has at least one class that contains the main()
method. For example:
class Student //class definition
{ Body }
Main Method Class
➔ In this section, we define the main() method.
➔ It is essential for all Java programs. Because the execution of all Java
programs starts from the main() method.
➔ In other words, it is an entry point of the class. It must be inside the
class.
➔ Inside the main method, we create objects and call the methods.
Main Method Class
➔ We use the following statement to define the main() method:
public class Student //class definition
{
public static void main(String args[])
{
//statements
}
}
Main Method Class
Basic Syntax
Java program can be defined as a collection of objects that communicate via
invoking each other's methods.
Basic Syntax
➔ Object Objects have states and behaviors. Example: A dog has states -
−
color, name, breed as well as behavior such as wagging their tail,
barking, eating. An object is an instance of a class.
➔ Class A class can be defined as a template/blueprint that describes the
−
behavior/state that the object of its type supports.
➔ For ex:
Class - fruit
Objects - Apple, Banana, Mango
Basic Syntax
➔ Methods A method is basically a behavior. A class can contain many
−
methods. It is in methods where the logics are written, data is
manipulated and all the actions are executed.
➔ Instance Variables Each object has its unique set of instance
−
variables. An object's state is created by the values assigned to these
instance variables.
Basic Syntax
➔ Case Sensitivity Java is case sensitive, which means identifier
− Hello and
hello would have different meaning in Java.
➔ Class Names For all class names the
− first letter should be in Upper Case.
If several words are used to form a name of the class, each inner word first
letter should be in UpperCase. Ex: class MyFirstJavaClass
➔ Method Names All method names should start with a
− Lowercase letter. If
several words are used to form the name of the method, then each inner
word first letter should be in UpperCase. Ex: public void myMethodName()
➔ public static void main(String args[]) Java program processing starts
−
from the main() method which is a mandatory part of every Java program.
Basic Syntax
➔ Program File Name Name of the program file should exactly match
−
the class name.
➔ When saving the file, you should save it using the class name (Remember
Java is case sensitive) and append '.java' to the end of the name (if the file
name and the class name do not match, your program will not compile).
➔ Ex: Assume 'MyFirstJavaProgram' is the class name. Then the file should
be saved as 'MyFirstJavaProgram.java'
Basic Syntax
Java Identifiers
All Java components require names. Names used for classes, variables, and
methods are called identifiers.
➔ All identifiers should begin with a letter (A to Z or a to z), currency
character ($) or an underscore (_).
➔ After the first character, identifiers can have any combination of
characters.
➔ A keyword cannot be used as an identifier.
➔ Most importantly, identifiers are case sensitive.
➔ Examples of legal identifiers: age, $salary, _value, __1_value.
➔ Examples of illegal identifiers: 123abc, -salary.
Sample program
/* This is my first java program.
This will print 'Hello, World!' as the output*/
public class MyFirstJavaProgram
{
public static void main(String []args)
{
System.out.println("Hello, World!");
//prints Hello,World!
}
}
Sample program
/* This is a java program to create an object.
public class MyClass
{
Int x = 5; //Data member/variable
public static void main(String []args)
{
MyClass myObject = new MyClass(); //creating an object
System.out.println(myObject.x); //prints the value of x
}
}
public class MyClass
{
Int x = 5; //Data member/variable
public static void main(String []args)
{
MyClass myObject1 = new MyClass(); //creating object1
MyClass myObject2 = new MyClass(); //creating object2
myObject2.x = 25;
System.out.println(myObject1.x);//outputs x = 5
System.out.println(myObject2.x);//outputs x = 25
}
}
Sample program
class MyClass{
Int id;
String name;
}
public Class Student{
public static void main(String []args)
{
MyClass myObject = new MyClass(); //creating an object
myObject.id = 101;
myObject.name= “yourname”;
System.out.println(myObject.id +” “ +
myObject.name); //prints the members with whitespace
}
}

More Related Content

Similar to UNIT 1 Programming in java Bsc program.pptx (20)

DOCX
Srgoc java
Gaurav Singh
 
PPTX
Java programming Introduction | Java basic architecture
shaswinayyan
 
PPTX
Java Lecture 1
Qualys
 
PPTX
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
PPTX
Java Introduction
sunmitraeducation
 
PPT
PPS Java Overview Unit I.ppt
CDSukte
 
PPT
PPS Java Overview Unit I.ppt
RajeshSukte1
 
PPT
Java ppt-class_Introduction_class_Objects.ppt
VGaneshKarthikeyan
 
PDF
Java chapter 1
Mukesh Tekwani
 
PDF
0f0cef_1dac552af56c4338ab0672859199e693.pdf
DeepakChaudhriAmbali
 
PDF
Java Evolution-2.pdf
kumari36
 
PPT
Java ppt-class_basic data types methods definitions
ganeshkarthy
 
PPTX
JAVA ALL 5 MODULE NOTES.pptx
DrPreethiD1
 
PPTX
Iintroduction to java , Java Coding , basics of java.pptx
MayankParashar31
 
PPTX
JAVAPart1_BasicIntroduction.pptx
Murugesh33
 
PPTX
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
PPTX
Java session2
Jigarthacker
 
PPTX
UNIT 1.pptx
EduclentMegasoftel
 
PPTX
Chapter-1 Introduction.pptx
SumanBhandari40
 
Srgoc java
Gaurav Singh
 
Java programming Introduction | Java basic architecture
shaswinayyan
 
Java Lecture 1
Qualys
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Java Introduction
sunmitraeducation
 
PPS Java Overview Unit I.ppt
CDSukte
 
PPS Java Overview Unit I.ppt
RajeshSukte1
 
Java ppt-class_Introduction_class_Objects.ppt
VGaneshKarthikeyan
 
Java chapter 1
Mukesh Tekwani
 
0f0cef_1dac552af56c4338ab0672859199e693.pdf
DeepakChaudhriAmbali
 
Java Evolution-2.pdf
kumari36
 
Java ppt-class_basic data types methods definitions
ganeshkarthy
 
JAVA ALL 5 MODULE NOTES.pptx
DrPreethiD1
 
Iintroduction to java , Java Coding , basics of java.pptx
MayankParashar31
 
JAVAPart1_BasicIntroduction.pptx
Murugesh33
 
JAVA_Day1_BasicIntroduction.pptx
Murugesh33
 
Java session2
Jigarthacker
 
UNIT 1.pptx
EduclentMegasoftel
 
Chapter-1 Introduction.pptx
SumanBhandari40
 

Recently uploaded (20)

PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
Ad

UNIT 1 Programming in java Bsc program.pptx

  • 2. Java Evolution;History; Java and the Internet; How Java differs from C and C++; Features; platform-independent nature of java; Overview of Java; simple Java program; Structure; Fundamentals of Object-Oriented Programming; Object-Oriented Paradigm; Basic Concepts of Object-Oriented Programming; Benefits of Object-Oriented Programming; application of Object-Oriented Programming; Java Development Kit (JDK); Java interpreter; Byte Code; Java Virtual Machine.
  • 3. History of Java ➔ Java is a general-purpose, object-oriented programming language developed by Sun Microsystems of USA in 1991. ➔ Java was developed by a team led by James Gosling and his colleague Mike Sheridan and Patrick Naughton.
  • 5. History of Java ➔ They named this project “Greentalk”, and the file extension was called .gt. ➔ Finally, James Gosling named the project “Oak” after the Oak tree planted outside the office of Sun Microsystems. ➔ He named the software – “Java” in 1995. This name was based on the name of an espresso bean he thought of while having coffee near his office.
  • 6. History of Java ➔ Java was designed for the development of software for consumer electronic devices like TVs, VCRs, toasters and such other electronic machines. ➔ The goal had a strong impact on the development team to make the language simple, portable and highly reliable.
  • 7. History of Java ➔ The most striking feature of the language is that it is a platform-neutral language. ➔ Programs developed in Java can be executed anywhere on any system. ➔ Write Once Run Anywhere (WORA). ➔ Designed for easy Web/Internet applications ➔ In 1993 Java Was So Popular in the World Wide Web or in the Internet For Developing Games and Graphical Applications with the help of Applets
  • 9. History of Java ➔ In 1995, Sun Microsystems released the first Java version, java 1.0. After that, it was incorporated into web browsers. ➔ This also made the Java team realise that the Internet would be the perfect network to promote their product.
  • 10. History of Java The latest version of Java is Java 22 or JDK 22 released on March, 19th 2024
  • 11. platform-independent nature of java ➔ The meaning of Java platform-independent is that the Java compiled code(byte code) can run on all operating systems. ➔ A program is written in a language that is human-readable. ➔ For the source code to be understood by the machine, it needs to be in a language understood by machines, typically a machine-level language. ➔ The compiler converts the high-level language (human language) into a format understood by the machines.
  • 12. platform-independent nature of java ➔ Step-by-Step Execution of Java Program ➔ Whenever a program is written in JAVA, the java compiles it. ➔ The result of the JAVA compiler is the .class file or the bytecode and not the machine’s native code (unlike the C compiler). ➔ The bytecode generated is a non-executable code and needs an interpreter to execute on a machine. ➔ This interpreter is the JVM ( Java Virtual Machine ) and thus the Bytecode is executed by the JVM. ➔ And finally, the program runs to give the desired output.
  • 13. platform-independent nature of java ➔ In the case of C or C++ (languages that are not platform independent), the compiler generates an executable file (such as a .exe file) which is both OS- dependent and CPU-dependent.
  • 14. platform-independent nature of java ➔ platform-independent nature of java adds to an important feature in the JAVA language termed portability. ➔ Every system has its own JVM which gets installed automatically when the JDK (Java Development Kit ) software is installed. ➔ For every operating system separate JVM is available which is capable to read the .class file or byte code. ➔ An important point to be noted is that while JAVA is a platform-independent language, the JVM is platform-dependent. ➔ Different JVM is designed for different OS and byte code is able to run on different OS.
  • 16. Java Development Kit (JDK) ➔ Java Development Kit (JDK) is a software development environment used for developing Java applications and applets. ➔ It includes the Java Runtime Environment (JRE), an interpreter/loader (Java), a compiler (javac), an archiver (jar), a documentation generator (Javadoc), and other tools needed in Java development.
  • 17. Java Runtime Environment ➔ JRE stands for “Java Runtime Environment” . ➔ The Java Runtime Environment provides the minimum requirements for executing a Java application; it consists of the Java Virtual Machine (JVM), core classes, and supporting files.
  • 18. JVM (Java Virtual Machine) ➔ JVM (Java Virtual Machine) 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 and JVM is responsible for executing the java program line by line, hence it is also known as an interpreter.
  • 20. Java Interpreter ➔ The interpreter reads and executes bytecode instructions line-by-line or instruction-by-instruction. ➔ It performs the translation from bytecode to native machine code dynamically at runtime. ➔ It translates bytecode into native instructions, which are then executed by the host machine’s CPU.
  • 21. JAVA FEATURES ➔ The primary objective of Java programming language creation was to make it a portable, simple and secure programming language. ➔ he features of Java are also known as Java buzzwords.
  • 23. JAVA FEATURES Simple ➔ Java is easy to learn and its syntax is quite simple, clean and easy to understand. ➔ Eg : Pointers and Operator Overloading are not there in java but were an important part of C++.
  • 24. JAVA FEATURES Object Oriented ➔ In java everything is an Object which has some data and behavior. ➔ Java can be easily extended as it is based on Object Model.
  • 25. JAVA FEATURES Robust ➔ Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time error checking and runtime checking. ➔ But the main areas which Java improved were Memory Management and mishandled Exceptions by introducing automatic Garbage Collector and Exception Handling.
  • 26. JAVA FEATURES Platform Independent ➔ Java guaranteed to be a write-once, run-anywhere language. ➔ On compilation Java programs are compiled into bytecode. ➔ This bytecode is platform independent and can be run on any machine, plus this bytecode format also provides security.
  • 27. JAVA FEATURES Secure ➔ When it comes to security, Java is always the first choice. ➔ With java secure features it enables us to develop virus free, tamper free systems. ➔ Java programs always run in a Java runtime environment with almost null interaction with system OS, hence it is more secure.
  • 28. JAVA FEATURES Multi Threading ➔ Java multithreading feature makes it possible to write programs that can do many tasks simultaneously.A thread is like a separate program, executing concurrently. ➔ Benefit of multithreading is that it utilizes the same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along. ➔ The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area.
  • 29. JAVA FEATURES Architectural Neutral ➔ Compilers generate bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to interpret on any machine.
  • 30. JAVA FEATURES Portable ➔ Java Byte code can be carried to any platform. ➔ No implementation dependent features. ➔ Everything related to storage is predefined, example: size of primitive data types
  • 31. JAVA FEATURES High Performance ➔ Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. ➔ But, Java enables high performance with the use of just-in-time compilers.
  • 32. JAVA FEATURES Distributed ➔ Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. ➔ This feature of Java makes us able to access files by calling the methods from any machine on the internet.
  • 33. JAVA FEATURES Dynamic ➔ Java is a dynamic language. ➔ It supports the dynamic loading of classes. ➔ It means classes are loaded on demand.
  • 34. JAVA DIFFERENT FROM C AND C++ 1. C Uses header Files but java uses Packages. 2. C Uses Pointers but java doesn't supports pointers. 3. The Code of C Language is Converted into the Machine code after Compilation But in Java Code First Converted into the Bytes Codes then after it is converted into the Machine Code. 4. C++ supports Operator Overloading but java doesn't Supports Operator Overloading. 5. In C++ Multiple Inheritance is Possible but in java A Class Can not Inherit the features from the two classes in other words java doesn't supports Multiple Inheritance
  • 35. JAVA DIFFERENT FROM C AND C++ 6. Java Uses import statement for including the contents of screen instead of #include. 7. Java Doesn't uses goto. 8. Java Doesn't have Destructor like C++ Instead Java Has finalize Method. 9. Java Doesn't have Structure Union , enum data types. 10.C++ needs manual garbage memory clearance whereas Java has an automatic garbage collector
  • 36. JAVA DIFFERENT FROM C AND C++ 11.Java does not have preprocessor, so we can’t use #define, #include and #ifdef statements. 12.Java does not perform automatic type conversions that result in loss of precision. 13.It is not possible to declare unsigned integers in java. 14.Java does not support global variables. Every method and variable is declared within a class and forms part of that class.
  • 37. Object-Oriented Programming- paradigms ➔ Emphasis is on data rather than procedure. ➔ Programs are divided into what are known as Objects. ➔ Data structures are designed such that they characterize the objects. ➔ Methods that operate on the data of an object are tied together in the data structure ➔ Data is hidden and cannot be accessed by external functions. ➔ Objects may communicate with each other through methods. ➔ New data and methods can be easily added whenever necessary. ➔ Follows bottom-up approach in program design.
  • 38. Object-Oriented Programming- paradigms ➔ Class: A blueprint or template for creating objects. ➔ It defines a type of object and encapsulates data and methods that operate on that data. ➔ It has its own data members and member functions. ➔ The data members inside the class are manipulated using these member functions. ➔ Example: class Car { }
  • 39. Object-Oriented Programming- paradigms ➔ Object: An instance of a class. It represents a concrete entity with state and behavior. ➔ Notably, the system does not allocate any memory space when a class is specified, but it’s allocated when it is instantiated, i.e., when an object is formed. ➔ Example: Car myCar = new Car();
  • 40. Fundamentals of Object-Oriented Programming ➔ OOP allows objects to interact with each other using four basic principles: ➔ Encapsulation, ➔ Inheritance, ➔ Polymorphism, and ➔ Abstraction. ➔ These four OOP principles enable objects to communicate and collaborate to create powerful applications.
  • 41. Fundamentals of Object-Oriented Programming Encapsulation ➔ Encapsulation is defined as the wrapping up of data under a single unit. ➔ It is the mechanism that binds together code and the data it manipulates. ➔ In Encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of their class in which they are declared. ➔ As in encapsulation, the data in a class is hidden from other classes, so it is
  • 42. Fundamentals of Object-Oriented Programming Encapsulation
  • 43. Fundamentals of Object-Oriented Programming Inheritance ➔ Inheritance is an important pillar of OOP(Object-Oriented Programming). ➔ A class derives properties and characteristics from another class is called Inheritance. ➔ When we write a class, we inherit properties from other classes. ➔ So when we create a class, we do not need to write all the properties and functions again and again, as these can be inherited from another class that possesses it. ➔ Inheritance allows the user to reuse the code whenever possible and reduce its redundancy.
  • 44. Fundamentals of Object-Oriented Programming Inheritance
  • 45. Fundamentals of Object-Oriented Programming Inheritance
  • 46. Fundamentals of Object-Oriented Programming Polymorphism ➔ The word polymorphism means having many forms. ➔ In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. ➔ For example, A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. ➔ So the same person posses different behavior in different situations. ➔ This is called polymorphism.
  • 47. Fundamentals of Object-Oriented Programming Polymorphism
  • 48. Fundamentals of Object-Oriented Programming Abstraction ➔ It is the ability to represent important information for the context of the problem. ➔ And hiding all the implementation details ➔ Eg: normal user use different apps but they are unaware of the code that makes the app ➔ This pillar aims to abstract only what we need to solve the problem and its
  • 49. Benefits of Object-Oriented Programming ➔ Code Reusability: Inheritance supports the reusability of code. ➔ Simple Troubleshooting: the data and the methods that operate on it are kept together in the same class, allowing for easier organization and debugging of the code. ➔ Prevents Data Redundancy: Using encapsulation, OOPs help reduce data redundancy by allowing to reuse of data in multiple classes. This means that without having to rewrite, the same data can be used in multiple classes. ➔ Modularity: Modularity helps break down complex code into smaller, more manageable chunks..
  • 50. Benefits of Object-Oriented Programming ➔ Code Maintenance: OOPs provide tools such as inheritance, abstraction, and encapsulation that make it easier to modify, maintain, and debug code. ➔ Code Security: Data abstraction and encapsulation in Java provide security advantages by allowing the user to restrict access to certain data and methods. ➔ Problem-Solving Ability: Object-oriented programming (OOPS) is a powerful approach to solving complex problems by breaking them down into smaller, bite-sized components. It enables modules with the same interface to replace smaller codes. This approach enables efficient problem- solving and improved overall performance
  • 51. Applications of Object-Oriented Programming ➔ Object-Oriented Databases: They are also called Object Database Management Systems (ODBMS). These databases store objects instead of data, such as real numbers and integers. Objects consist of the following: ➔ Attributes: Attributes are data that defines the traits of an object. This data can be as simple as integers and real numbers. It can also be a reference to a complex object. ➔ Methods: They define the behavior and are also called functions or procedures.
  • 52. Applications of Object-Oriented Programming ➔ Real-Time System Design: Real time systems inherit complexities that makes difficult to build them. Object-oriented techniques make it easier to handle those complexities. ➔ Office Automation Systems: These include formal as well as informal electronic systems primarily concerned with information sharing and communication to and from people inside as well as outside the organization. ➔ Client-Server Systems: Object-oriented Client-Server Systems provide the IT infrastructure, creating object-oriented Client-Server Internet (OCSI) applications.
  • 53. Applications of Object-Oriented Programming ➔ CIM(Computer integrated manufacturing)/CAD(computer aided design)/CAM Systems(Computer aided manufacturing): OOP can also be used in manufacturing and design applications as it allows people to reduce the effort involved. ➔ For instance, it can be used while designing blueprints, flowcharts, etc. ➔ OOP makes it possible for the designers and engineers to produce these flowcharts and blueprints accurately
  • 54. Java and the Internet Networking Capabilities ➔ Java has built-in support for network programming. ➔ The java.net package provides classes for implementing network protocols and handling network communications. ➔ This includes the ability to create sockets for TCP/IP communication, making Java ideal for developing networked applications.
  • 55. Java and the Internet ➔ Internet users use Java to create the applet programs and run them locally using 'Java-enabled browsers' like HotJava.
  • 56. Java and the Internet What is Applet? ➔ An applet is a small Java program that can be embedded into a web page to generate dynamic content. ➔ It runs inside the web browser and works at client side. ➔ An applet is embedded in an HTML page using the APPLET or OBJECT tag and hosted on a web server. ➔ Applets are used to make the website more dynamic and entertaining.
  • 57. Java and the Internet ➔ Java is a platform-independent, object-oriented programming language (OOP). ➔ It is not to be confused with JavaScript, a scripting language used to create dynamic web pages.
  • 58. Structure of Java Program
  • 59. Structure of Java Program
  • 60. Documentation Section ➔ The documentation section is an important section but optional for a Java program. ➔ It includes basic information about a Java program. ➔ It improves the readability of the program. ➔ Whatever we write in the documentation section, the Java compiler ignores the statements during the execution of the program.
  • 61. Documentation Section ➔ Single-line Comment: It starts with a pair of forwarding slash (//). ➔ For example: //First Java Program ➔ Multi-line Comment: It starts with a /* and ends with */. We write between these two symbols. ➔ For example: /*It is an example of multiline comment*/
  • 62. Package Declaration ➔ The package declaration is optional. ➔ It is placed just after the documentation section. ➔ In this section, we declare the package name in which the class is placed. ➔ Note that there can be only one package statement in a Java program. ➔ It must be defined before any class and interface declaration. package mypack;
  • 64. Import Statements ➔ The package contains the many predefined classes and interfaces. ➔ If we want to use any class of a particular package, we need to import that class. ➔ The import statement represents the class stored in the other package. ➔ We use the import keyword to import the class. import java.util.Scanner; //it imports the Scanner class only import java.util.*; //it imports all the class of the java.util package
  • 65. Interface Section ➔ It is an optional section. ➔ We can create an interface in this section if required. ➔ We use the interface keyword to create an interface. ➔ An interface is a slightly different from the class. ➔ It contains only constants and method declarations.
  • 66. Interface Section ➔ It is an optional section. ➔ We can create an interface in this section if required. ➔ We use the interface keyword to create an interface. ➔ An interface is a slightly different from the class. ➔ It contains only constants and method declarations.
  • 67. Interface Section interface car { void start(); void stop(); }
  • 68. Class Definition ➔ In this section, we define the class. It is vital part of a Java program. ➔ A Java program may contain more than one class definition. ➔ We use the class keyword to define the class. ➔ It contains information about user-defined methods, variables, and constants. ➔ Every Java program has at least one class that contains the main() method. For example: class Student //class definition { Body }
  • 69. Main Method Class ➔ In this section, we define the main() method. ➔ It is essential for all Java programs. Because the execution of all Java programs starts from the main() method. ➔ In other words, it is an entry point of the class. It must be inside the class. ➔ Inside the main method, we create objects and call the methods.
  • 70. Main Method Class ➔ We use the following statement to define the main() method: public class Student //class definition { public static void main(String args[]) { //statements } }
  • 72. Basic Syntax Java program can be defined as a collection of objects that communicate via invoking each other's methods.
  • 73. Basic Syntax ➔ Object Objects have states and behaviors. Example: A dog has states - − color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class. ➔ Class A class can be defined as a template/blueprint that describes the − behavior/state that the object of its type supports. ➔ For ex: Class - fruit Objects - Apple, Banana, Mango
  • 74. Basic Syntax ➔ Methods A method is basically a behavior. A class can contain many − methods. It is in methods where the logics are written, data is manipulated and all the actions are executed. ➔ Instance Variables Each object has its unique set of instance − variables. An object's state is created by the values assigned to these instance variables.
  • 75. Basic Syntax ➔ Case Sensitivity Java is case sensitive, which means identifier − Hello and hello would have different meaning in Java. ➔ Class Names For all class names the − first letter should be in Upper Case. If several words are used to form a name of the class, each inner word first letter should be in UpperCase. Ex: class MyFirstJavaClass ➔ Method Names All method names should start with a − Lowercase letter. If several words are used to form the name of the method, then each inner word first letter should be in UpperCase. Ex: public void myMethodName() ➔ public static void main(String args[]) Java program processing starts − from the main() method which is a mandatory part of every Java program.
  • 76. Basic Syntax ➔ Program File Name Name of the program file should exactly match − the class name. ➔ When saving the file, you should save it using the class name (Remember Java is case sensitive) and append '.java' to the end of the name (if the file name and the class name do not match, your program will not compile). ➔ Ex: Assume 'MyFirstJavaProgram' is the class name. Then the file should be saved as 'MyFirstJavaProgram.java'
  • 77. Basic Syntax Java Identifiers All Java components require names. Names used for classes, variables, and methods are called identifiers. ➔ All identifiers should begin with a letter (A to Z or a to z), currency character ($) or an underscore (_). ➔ After the first character, identifiers can have any combination of characters. ➔ A keyword cannot be used as an identifier. ➔ Most importantly, identifiers are case sensitive. ➔ Examples of legal identifiers: age, $salary, _value, __1_value. ➔ Examples of illegal identifiers: 123abc, -salary.
  • 78. Sample program /* This is my first java program. This will print 'Hello, World!' as the output*/ public class MyFirstJavaProgram { public static void main(String []args) { System.out.println("Hello, World!"); //prints Hello,World! } }
  • 79. Sample program /* This is a java program to create an object. public class MyClass { Int x = 5; //Data member/variable public static void main(String []args) { MyClass myObject = new MyClass(); //creating an object System.out.println(myObject.x); //prints the value of x } }
  • 80. public class MyClass { Int x = 5; //Data member/variable public static void main(String []args) { MyClass myObject1 = new MyClass(); //creating object1 MyClass myObject2 = new MyClass(); //creating object2 myObject2.x = 25; System.out.println(myObject1.x);//outputs x = 5 System.out.println(myObject2.x);//outputs x = 25 } } Sample program
  • 81. class MyClass{ Int id; String name; } public Class Student{ public static void main(String []args) { MyClass myObject = new MyClass(); //creating an object myObject.id = 101; myObject.name= “yourname”; System.out.println(myObject.id +” “ + myObject.name); //prints the members with whitespace } }

Editor's Notes

  • #65: It does not create objects (Abstract classes)
  • #79: MyClass(); //constructor
  • #80: MyClass(); //constructor
  • #81: MyClass(); //constructor