0% found this document useful (0 votes)
10 views

1 Introduction

Uploaded by

Mahek N
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)
10 views

1 Introduction

Uploaded by

Mahek N
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/ 36

Chapter 1

Introduction

Prof Amruta Deshmukh 1


1.1 About Java
• Java is a general-purpose, class-based, object-
oriented programming language .
• Which work on different operating systems such
as Windows, Linux.
• Using java programming language, we can create
applications on multiple devices.
• . It is widely used for developing Java applications
in laptops, data centers, game consoles, cell
phones, etc.
• It is considered as one of the fast, secure, and
reliable programming language.
• Java is fast, secure, and reliable.
Prof Amruta Deshmukh 2
History of Java Programming Language
• Java is an Object Oriented Programming language (OOP)
developed by James Gosling at Sun Microsystems in 1991.
The language was first called Oak, but later renamed as Java
in 1995.
• The trouble with C and C++ is that they are designed to be
compiled for a specific target. The problem is that compilers
are expensive and time consuming to create.
• In an attempt to find such a solution, Gosling and others
began work on a portable, platform independent language
that could be used to produce code that would run on a
variety of CPUs under different environments. This effort
ultimately led to the creation of Java. Java is based on Write
once and run anywhereProf principle
Amruta Deshmukh 3
What is Java?
• Java is a programming language and
a platform.
• Platform: Any hardware or software
environment in which a program runs is
known as a platform.
• Since Java has its own runtime environment
(JRE) and API, it is called platform.
• Java is a platform-independent language,
meaning we run the same code on multiple
platforms.

Prof Amruta Deshmukh 4


Using java develop many application
• Desktop Applications.
• Mobile Applications.
• Web Applications.
• Big Data Processing.

Prof Amruta Deshmukh 5


Where it is used?
• There are many devices where java is currently used.
Some of them are as follows:
1. Desktop Applications such as media player, antivirus
etc.
2. Web Applications.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games etc.
Prof Amruta Deshmukh 6
Features of Java
• Simple
• Secure
• Portable
• Platform-Independent
• Object Oriented
• Robust
• Multithreaded
• Architecture Neutral
• Interpreted
• High Performance
• Distributed
• Dynamic
Prof Amruta Deshmukh 7
Prof Amruta Deshmukh 8
1)Object Oriented:
• In Java, everything is an Object.
• Java can be easily extended since it is based on the
Object model.
• Object-oriented means we organize our software as a
combination of different types of objects that
incorporate both data and Methods.
• Object oriented programming is about creating
objects that contain both data and methods.
• These concepts implement real-world entities in
programs, and they create working methods and
variables to reuse them without compromising
security.
• Object oriented programming is a model that
provides different type of concepts, such as
inheritance, abstraction, polymorphism etc.
Prof Amruta Deshmukh 9
2)Simple:
• Java is very easy to learn, and its syntax is simple,
clean and easy to understand. According to Sun
Micro system, Java language is a simple
programming language because:
• Java syntax is based on C++ (so easier for
programmers to learn it after C++).
• Java has removed many complicated and rarely-
used features, for example, explicit pointers,
operator overloading, etc.
• There is no need to remove unreferenced objects
because there is an Automatic Garbage Collection
in Java.

Prof Amruta Deshmukh 10


3)Secure:
• With Java's secure feature it enables to develop virus-free,
tamper-free systems.
• Authentication techniques are based on public-key
encryption.
• Java is best known for its security.
• With Java, we can develop virus-free systems.
• Java is secured because:
• No explicit pointer
• Java language provides these securities by default. Some
security can also be provided by an application developer
explicitly through SSL(Secure Sockets Layer), JAAS(Java
Authorization Service etc.

Prof Amruta Deshmukh 11


4) Platform Independent:
• Java is a platform-independent language,
meaning we run the same code on multiple
platforms.
• Java achieves this using JVM and Byte Code.
• Java compiler converts the programming code
into byte code.
• Byte code is platform-independent and can be
run on any processor or system.
• Java code can be executed on multiple
platforms, for example, Windows, Linux, Sun
Solaris, Mac/OS, etc.
Prof Amruta Deshmukh 12
• Java is platform independent because it is different from
other languages like C, C++, etc.
• which are compiled into platform specific machines while
Java is a write once, run anywhere language.
• A platform is the hardware or software environment in
which a program runs.

Prof Amruta Deshmukh 13


5)Robust:
• highly supported language and portable,
• Strongly typed language,
• Memory Management,
• Garbage Collection,
• Exception Handling,
• No pointers

6)Portable:
• Being platform independent , Java application
developed in one environment can be deployed to
different platform and executed using JVM.
• Java programs are portable, which means that the
same byte code program can run on any computer
system that has a Java interpreter.
• Also, a source program can be compiled into byte
codes on any computer that has a Java compiler.
Prof Amruta Deshmukh 14
8)Dynamic:
• Java programs can carry an extensive amount of run-
time information that can be used to verify

Prof Amruta Deshmukh 15


9)Interpreted:
• Java byte code is translated on the fly to
native machine instructions and is not stored
anywhere.
10)High Performance:
• With the use of Just-In-Time compilers, Java
enables high performance.

Prof Amruta Deshmukh 16


11)Multithreaded:
• With Java's multithreaded feature it is possible to
write programs that can perform many tasks
simultaneously.

12)Distributed:
• Java is distributed because users to create
distributed applications in Java.
• RMI(Remote Method Invocation) and
EJB(Enterprise Java Bean) 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.
Prof Amruta Deshmukh 17
What is SDK?
• SDK stands for Standard developer’s kit.
• We can write, compile and run java programs
using SDK.
• A java program can be written once and then
run on many different devices, having JVM.
• There are different SDK’s available for
different platform i.e. Windows, Linux,
Solaris…
Prof Amruta Deshmukh 18
What is JDK?
• JDK (Java Development Kit) is provided by Sun
Microsystems which comes with its own set of
tools like Java Compiler, Java Interpreter,
Applet viewer and java API’s which are set of
classes to develop java programs.
• What is Bytecode?
• Compiled java code referred to as bytecode.
• Bytecode is a highly optimized set of
instructions designed to be executed by the
JVM (Java Virtual Machine).
• Bytecode is independent of operating system.
Prof Amruta Deshmukh 19
What is JVM?
• JVM stands for Java Virtual Machine.
• Execution of every java program is under the
control of the JVM.
• Most JVMs are written in C or C++.
• JVM is responsible for the execution of java
bytecode.

Prof Amruta Deshmukh 20


• Modern JVMs are much more efficient and
include a feature known as Just in time
compiler.
• A JIT compiler actually takes your java byte
code and translates it into native code, so that
the program runs on the specific operating
system.
• For different operating systems there are
different versions of JVM.
• Java programs can run on any device that has
a JVM.

Prof Amruta Deshmukh 21


1.2 Flavours of Java /JDK Editions
According to the SunMicroSystem java is available in 3 flavors
[1] Standard edition:
• which is used for developing Standalone Applications.
• It is also known as J2SE,JSE.

[2]Enterprise edition:
• which is used for developing web applications.
• It is also known as J2EE,JEE

[3] Micro edition :


• which is used for developing device programs and mobile
applications.
• It is also known as J2ME,JME.

Prof Amruta Deshmukh 22


[1] Java Standard edition:
• J2SE can be used to develop client-side standalone
applications or applets.
• When we starting to learn Java, first we should
learn Java Standard Edition(JSE) as this particular version of
Java includes the basic application structure, Fundamental
structure (Operator, Data type, OPP concept) Exception
handling and File handling.
• It is also known as core Java.
• Standard edition is a widely used platform for computer
programming in the Java Language.
• It is the Java platform commonly used to deploy portable
applications (Desktop applications) for general use.

Prof Amruta Deshmukh 23


[2] Java Enterprise Edition
• (Java 2 platform Enterprise Edition):- J2EE can be used
to develop server-side applications such as Java
servlets and Java Server Pages.
• It is known as J2EE or JEE.
• J2EE is build up from JSE with additional features for
business purpose.
• It has extra libraries which can be used to develop JEE
applications.
• It provides functions distributed multi-tier Java
software.
• This software is based largely on modular component
running on an application server.
• To develop the application such as Desktop base and
web base we can use J2EE.

Prof Amruta Deshmukh 24


[3] Java Micro Edition
• (Java 2 platform Micro Edition):- J2ME can be
used to develop applications for mobile
devices such as cell phones.
• It is known as J2ME or JME- Java ME is a Java
platform used to design for embedded
systems(Mobile phones).
• Nowadays, this version is very popular for
mobile application development – Android is
the best example for use of Java ME.
• Example: games, messaging applications

Prof Amruta Deshmukh 25


1.3 Java Installation
• https://www.oracle.com/in/java/technologies
/javase-jdk15-downloads.html
Setting path and Classpath in windows:-
• Path-> C:\Program Files\Java\jdk1.8.0_66\bin;
• Classpath-> C:\Program
Files\Java\jdk1.8.0_66\lib;.;

Prof Amruta Deshmukh 26


1.4 Java Program Development Environnent
• Eclipse
• NetBeans
• IntelliJ Idea
• BlueJ
• JBuilder

• https://www.eclipse.org/downloads/downloa
d.php?file=/oomph/epp/2020-12/R/eclipse-
inst-jre-win64.exe
Prof Amruta Deshmukh 27
How java program executes?
1>Create program using text editor (like
notepad) and give file extension as .java
2> Compile the source code with “javac”.
3> It will produce bytecode. i.e. .class file
4> Execute bytecode by “java” (Interpreter).
5> Obtain result or output.

Prof Amruta Deshmukh 28


Simple java program
public class Example {
// your program begin with a call to main ( ).
public static void main (String args [ ])
{ System.out.println (“Welcome to Java”);
}
}
Save above program as Example.java
• Name of the source code file must match the name of
the public class defined in that file and the file
extension must be .java.
C :\> javac Example.java
C :\> java Example
Output: - Welcome to Java
Prof Amruta Deshmukh 29
Internal Details of Hello Java Program
At runtime, the following steps are performed:

Prof Amruta Deshmukh 30


• Compilation Flow:
• When we compile Java program using javac
tool, the Java compiler converts the source
code into byte code.

Prof Amruta Deshmukh 31


ClassLoader :
• Java ClassLoader is a part of the Java Runtime Environment that
dynamically loads Java classes into the Java Virtual
Machine.. the Java ClassLoader is called by the JRE and these
ClassLoaders load classes into memory dynamically.

Bytecode Verified:
• Variables are initialized before they are used.
• Method calls match the types of object references.
• Rules for accessing private data and methods are not violated.
• Local variable accesses fall within the runtime stack.
• The run-time stack does not overflow.
• If any of the above checks fail, the verifier doesn’t allow the
class to be loaded.

Prof Amruta Deshmukh 32


• Roles of Java Interpreter
• Interpreter scans the program line by line and
translates it into machine code
• To convert the bytecode into the native code
of the machine.
• This process is done line by line.
• If the error comes on any line, the process is
stopped over there.

Prof Amruta Deshmukh 33


Addition
• public class addition {

• public static void main(String[] args) {


• // TODO Auto-generated method stub
• System.out.println("enter the value");
• int a=10;
• int b=20;
• System.out.println(a+"and"+b);
• int c=a+b;
• System.out.println("the sum is="+c);

• }

• }

Prof Amruta Deshmukh 34


Prime Number
• import java.util.Scanner;

• public class Prime {

• public static void main(String[] args) {


• int num, i, c=0;
• Scanner s=new Scanner(System.in);
• System.out.println("enter a number");
• num= s.nextInt();
• for(i=2;i<num;i++)
• {
• if(num%i==0)
• {
• c++;
• break;
• }

• }
• if(c==0)
• System.out.println("It is a Prime Number");
• else
• System.out.println("It is not Prime Number");

• }

• } Prof Amruta Deshmukh 35


Difference between C++ and JAVA
• No pointers in JAVA
• No multiple inheritance in JAVA
• No operator overloading
• No need for header files.
• Robust API
• Java Compiler converts source code into byte
code and interpreter converts byte code into
executable file. JAVA use JVM – Java Virtual
Machine so that JAVA program can run on any
platform.
• Event Driven Programming is possible in JAVA.
• ‘new’ keyword for creating objects in Java.
Prof Amruta Deshmukh 36

You might also like