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

Java Programming Day 1

This document provides an agenda for a session on Java programming that includes discussions on object oriented vs procedural programming, differences between C++ and Java, an introduction to Java, Java's history, and Java features. The session agenda covers topics such as the JVM architecture, Java program building blocks, variables and data types, user input, operators, and comparisons between C++ and Java regarding parameters like compilers/interpreters, inheritance, and portability.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Java Programming Day 1

This document provides an agenda for a session on Java programming that includes discussions on object oriented vs procedural programming, differences between C++ and Java, an introduction to Java, Java's history, and Java features. The session agenda covers topics such as the JVM architecture, Java program building blocks, variables and data types, user input, operators, and comparisons between C++ and Java regarding parameters like compilers/interpreters, inheritance, and portability.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 46

JAVA

PROGRAMMING
Faculty: BIRENDRA KUMAR SINGH
Session Agenda
• Object Oriented Programming vs Procedural Programming
• Differences between C++ & Java Programming Language
• Introduction to Java
• History of Java
• Features of Java
• JDK, JRE, JVM
• Building blocks of Java Program
Session Agenda
• JVM Architecture
• Building Blocks of Java Program
• Variables and Datatypes
• Input from user
• Operators in Java
OBJECT ORIENTED VS PROCEDURAL
PROGRAMMING
Object Oriented Programming vs Procedural
Programming
• Procedural Programming can be defined as a programming model which is
derived from structured programming, based upon the concept of calling procedure.
• Procedures, also known as routines, subroutines or functions, simply consist of a
series of computational steps to be carried out. During a program’s execution, any
given procedure might be called at any point, including by other procedures or
itself.
• Languages used in Procedural Programming:
• FORTRAN, ALGOL, COBOL, BASIC, Pascal and C.
Object Oriented Programming vs Procedural
Programming
• Object oriented programming can be defined as a programming model
which is based upon the concept of objects.
• Objects contain data in the form of attributes and code in the form of
methods.
• In object oriented programming, computer programs are designed using
the concept of objects that interact with real world.
Object Oriented Programming vs Procedural
Programming
Procedural Oriented Programming Object Oriented Programming
In procedural programming, program is divided In object oriented programming, program is
into small parts called functions. divided into small parts called objects.

Procedural programming follows top down Object oriented programming follows bottom up


approach. approach.

There is no access specifier in procedural Object oriented programming have access


programming. specifiers like private, public, protected etc.

Procedural programming does not have any proper Object oriented programming provides data hiding
way for hiding data so it is less secure. so it is more secure.
Object Oriented Programming vs
Procedural Programming
Procedural Oriented Programming Object Oriented Programming

In procedural programming, overloading is not Overloading is possible in object oriented


possible. programming.
Object oriented programming is based on real
Procedural programming is based on unreal world.
world.

Examples: C, FORTRAN, Pascal, Basic etc. Examples: C++, Java, Python, C# etc.

In procedural programming, overloading is not Overloading is possible in object oriented


possible. programming.
COMPARISON BETWEEN C++ &
JAVA
C++ vs Java
Parameter C++ Java
Compiler and Interpreter C++ only support compiler Java supports both compiler
and interpreter

Support for programming Allows both procedural programming and object- Support object-oriented
type oriented programming. programming model.

Memory management Accessible to programmer System controlled


Multiple inheritance C++ provide multiple Inheritance. The keyword Java doesn't provide multiple
virtual is used to resolve problems during inheritance.
multiple inheritance if there is any.
C++ vs Java
Parameter C++ Java
Portability The source must be recompiled for the Bytecode classes are
platform; hence the code is not portable. transferrable to platform-
specific JVM's.
Platform C++ programs are platform dependent. They Java programs are platform
need to be compiled for a particular platform. independent. Java programs
are written for Java Virtual
Machine (JVM). It will run
without needing recompilation.
Runtime error detection In C++, It is Programmer responsibility to It is system responsibility to
check the errors. check error in the program.
C++ vs Java
Parameter C++ Java
Pointer C++ support pointers. Java offers only limited
support for pointers.
Structure It supports structures. It does not any support for
structures.
Unions C++ supports unions. Java does not support unions.
Object management C++ supports manual object management with Java is heavy depend on
the help of new and delete keywords. automatic garbage collection.
It does not support destructors.
Concept Write once compile anywhere Write once run anywhere
everywhere
JAVA INTRODUCTION
Introduction to Java
• JAVA was developed by James Gosling at Sun Microsystem Inc in the
year 1991, later acquired by Oracle Corporation.
• Java is an object-oriented programming language made for developers
based on write once run anywhere concept. It means that compiled Java
code can run on all platforms that support Java. Java applications are
compiled to byte code that can run on any Java Virtual Machine.
• The syntax of Java is similar to C/C++
Introduction to Java
• The first publicly available version of Java (Java 1.0) was released in
1995. Sun Microsystems was acquired by the Oracle Corporation in 2010.
• Oracle has now the steermanship for Java. In 2006 Sun started to make
Java available under the GNU General Public License (GPL). GNU stands
for GNU's Not UNIX. It is a UNIX like computer operating system, but
unlike UNIX. Oracle continues this project called OpenJDK.
• Over time new enhanced versions of Java have been released. The current
version of Java is Java 1.8 which is also known as Java 8.
HISTORY OF JAVA
History of Java
• The history of Java starts with the Green Team. Java team members (also known as
Green Team), initiated this project to develop a language for digital devices such as
set-top boxes, televisions, etc.
• James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language
project in June 1991. The small team of sun engineers called Green Team.
• Firstly, it was called "Greentalk" by James Gosling, and the file extension was .gt.
After that, it was called Oak and was developed as a part of the Green project.
• In 1995, Oak was renamed as "Java" because it was already a trademark by Oak
Technologies.
History of Java
• Java is an island in Indonesia where the first coffee was produced (called
Java coffee). It is a kind of espresso bean. Java name was chosen by
James Gosling while having a cup of coffee nearby his office.
• Initially developed by James Gosling at Sun Microsystems (which is now
a subsidiary of Oracle Corporation) and released in 1995.
• JDK 1.0 was released on January 23, 1996. Now Java is being used in
Windows applications, Web applications, enterprise applications, mobile
applications, cards, etc.
Version history of Java
 JDK Alpha and Beta (1995) Java SE 7 (28th July 2011)
Java SE 8 (18th Mar 2014)
 JDK 1.0 (23rd Jan 1996)
 Java SE 9 (21st Sep 2017)
 JDK 1.1 (19th Feb 1997)  Java SE 10 (20th Mar 2018)
 J2SE 1.2 (8th Dec 1998)  Java SE 11 (September 2018)
 Java SE 12 (March 2019)
 J2SE 1.3 (8th May 2000)  Java SE 13 (September 2019)
 J2SE 1.4 (6th Feb 2002)  Java SE 14 (Mar 2020)
 Java SE 15 (September 2020)
 J2SE 5.0 (30th Sep 2004)  Java SE 16 (Mar 2021)
 Java SE 6 (11th Dec 2006)
JAVA FEATURES
Features of Java
• Platform Independent:  Compiler converts source code to bytecode and
then the JVM executes the bytecode generated by the compiler. This
bytecode can run on any platform be it Windows, Linux, macOS which
means if we compile a program on Windows, then we can run it on Linux
and vice versa. Each operating system has a different JVM, but the output
produced by all the OS is the same after the execution of bytecode. That is
why we call java a platform-independent language.
Features of Java
• Object-Oriented Programming Language: Organizing the program in
the terms of collection of objects is a way of object-oriented
programming, each of which represents an instance of the class. The four
main concepts of Object-Oriented programming are:
• Abstraction
• Encapsulation
• Inheritance
• Polymorphism
Features of Java
• Simple:  Java is one of the simple languages and easy to learn if you
know any object oriented programming language. It does not have
complex features like pointers, operator overloading, multiple
inheritances, Explicit memory allocation. 
• Robust:  Java language is robust that means Java Application are reliable.
This is because of JVM. JVM is responsible for execution of Java
runnable code and handling the task such memory management, handling
runtime errors etc.
Features of Java
• Secure:  Java is secure due to the following reasons:
• Java programs run inside a virtual machine which is known as a sandbox.
• Java does not support explicit pointer.
• Byte-code verifier checks the code fragments for illegal code that can violate access right to
object.
• The security manager is responsible for checking the permissions and properties of the classes.
It monitors the system resources accessed by the authorized classes. It also controls socket
connections.
• The exception handling feature adds more security in Java. The feature reports the error to the
programmer during the runtime. The code will not run until the programmer will not rectify it.
Features of Java
• Multithreading:  Java supports multithreading. It is a Java feature that
allows concurrent execution of two or more parts of a program for
maximum utilization of CPU.
• Portable:  As we know, java code written on one machine can be run on
another machine. The platform-independent feature of java in which its
platform-independent bytecode can be taken to any platform for execution
makes java portable.
TYPES OF APPLICATIONS
Types of Java Applications
• Standalone applications are also known as desktop applications or window-based applications.
These are software that we need to install on every machine. Examples of standalone application
are Media player, antivirus, etc. AWT and Swing are used in Java for creating standalone
applications.
• Web Application: An application that runs on the server side and creates a dynamic page is called a
web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc. technologies are used
for creating web applications in Java.
• Enterprise Application: An application that is distributed in nature, such as banking applications,
etc. is called an enterprise application. It has advantages like high-level security, load balancing,
and clustering. In Java, EJB is used for creating enterprise applications.
• Mobile Application: An application which is created for mobile devices is called a mobile
application. Currently, Android and Java ME are used for creating mobile applications.
JAVA EDITIONS/PLATFORMS
Java Editions
• Java SE (Java Standard Edition): It is a Java programming platform. It includes Java
programming APIs such as java.lang, java.io, java.net, java.util, java.sql, java.math etc. It
includes core concepts like OOPs, String, Regex, Exception, Inner classes, Multithreading,
I/O Stream, Networking, AWT, Swing, Reflection, Collection, etc.
• Java EE (Java Enterprise Edition): It is an enterprise platform that is mainly used to
develop web and enterprise applications. It is built on top of the Java SE platform. It includes
topics like Servlet, JSP, Web Services, EJB, JPA, etc.
• Java ME (Java Micro Edition): It is a micro platform that is dedicated to mobile
applications.
• JavaFX: It is used to develop rich internet applications. It uses a lightweight user interface
API.
JDK, JRE, JVM
JDK, JRE & JVM
• JDK
• acronym for Java Development Kit
• Software development environment used to develop Java Applications
• Contains JRE and development tools.
• JRE
• Acronym for Java Runtime Environment
• It contains set of libraries that is called during the execution of Java runnable code.
• Consist of JVM.
JDK, JRE & JVM
• JVM
• It is a virtual machine that provided environment to execute Java runnable code.
• It is available for every hardware and software platforms.
• It performs following task
• Loads code
• Verifies code
• Executes Code
JAVA ARCHITECTURE
Java Architecture
 The various components of the Java architecture are:

Source file

Application
Programmin Class file
g Interface

JVM
Java Architecture
 The source code of a Java application is saved in a source file with
the extension, .java.
 JVM is responsible for executing the bytecode and generating the
machine specific code for the machine on which the Java program
needs to be executed.
 The Java API is a collection of software components, such as
classes, interfaces, and methods.
Java Architecture (Contd.)
JVM ARCHITECTURE
JVM Architecture
JVM Architecture(Contd.)
• Class Loader : Used to load class files
• Bootstrap ClassLoader: Loads rt.jar file which contains all class files
present in Java Packages
• Extension ClassLoader: Child classloader of Bootstrap class loader.
It loads the jar files located inside $JAVA_HOME/jre/lib/ext
directory
• System/Application Classloader: Child classloader of Extension
classloader.
• Loads the class files from classpath.
JVM Architecture(Contd.)
• Class(Method) Area: Stores per-class structure such as fields, method data and
code for methods
• Heap: Runtime data area in which objects are allocated.
• Stack: It store frames. It stores local variables and plays important role in
method invocation and return.
• Each time a new frame is created when a method is invoked and get destroyed when
method invocation completes’
• Program Counter Register: Contains the address of JVM instructions
executing currently.
JVM Architecture(Contd.)
• Native Method Stack: Contains all the native methods used in application. A native method is a Java
method (either an instance method or a class method) whose implementation is also written in another
programming language such as C/C++.
• Execution engine: It contains :-
• A virtual processor
• Interpretor: It is responsible for reading and executing the program. It is designed in such a way that it can read the
source program and translate the source code instruction by instruction.
• JIT compiler:  JIT compiles parts of the byte code that have similar functionality at the same time, and hence
reduces the amount of time needed for compilation. It is a translator from the instruction set of a Java virtual machine
(JVM) to the instruction set of a specific CPU.
• Java Native Interface
• Provides an interface to communicate with another application written in another language like C, C++, Assembly etc.
JAVA PROGRAM COMPONENTS
PREREQUISITE

• JDK & JRE Installed (JDK 1.8 or higher version)

• SET PATH VARIABLE

• JAVA IDE such as NETBEANS, ECLIPSE, INTELLIJ IDE

• ONLINE JAVA COMPILER such as CodeChef, Jdoodle etc


Building Blocks of a Java Program

Packages

Classes

A Java program comprises


Class members

Main Method
THANK YOU

You might also like