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

Chapter 1-Introduction to JAVA

The document provides an introduction to Java, covering key concepts such as data hiding, abstraction, encapsulation, inheritance, and the three pillars of object-oriented programming. It explains Java's platform independence, security features, and the differences between Java and C++. Additionally, it outlines the Java Development Kit (JDK) and Java Runtime Environment (JRE), emphasizing their roles in developing and executing Java programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Chapter 1-Introduction to JAVA

The document provides an introduction to Java, covering key concepts such as data hiding, abstraction, encapsulation, inheritance, and the three pillars of object-oriented programming. It explains Java's platform independence, security features, and the differences between Java and C++. Additionally, it outlines the Java Development Kit (JDK) and Java Runtime Environment (JRE), emphasizing their roles in developing and executing Java programs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 81

Introduction to java

Data Hiding – Hiding of Data

Imp Points to Remember

1.What is Data Hiding

Our internal data should not go outside.


Outside person can not access our internal data directly

2.What is the purpose of Data Hiding


Security

3.How to implement it
by declaring access modifiers
by declaring your data as private
Abstraction -- Abstract means Incomplete

Imp Points to Remember

1.What is Abstraction
Hiding internal implementation ,just highlight the set of services that we are going to
offer

2. What is the purpose of Data Hiding


Security
Enhancement will be easy
Maintainability of the application
Modularity of the Application

3. How to implement it
Using GUI screen, Interface. API ‘s etc
Encapsulation –

Imp Points to Remember

1.What is Encapsulation

The process of grouping data members and corresponding methods into a single unit is called
Encapsulation
Every Java class is an example of Encapsulation
If any component follows data hiding and Abstraction ,that component is said to be Encapsulated
component

Encapsulation=Data Hiding Abstraction

2.What is the Advs of Encapsulation


Whatever advs of Data Hiding and Abstraction are the adv of Encapsulation

Security ,Enhancement, Maintainability, Modularity


2.What is the Advs of Encapsulation
Whatever advs of Data Hiding and Abstraction are the adv of
Encapsulation

Security ,Enhancement ,Maintainability, Modularity

3.What are the Disadvantages of Encapsulation

1.It increases length of code (since every where we have to write validation
code)
2.Time Consuming Process
3.Low Performance
Note-So everywhere don’t try to use Encapsulation
If Security constraint is there then only use Encapsulation
Inheritance
Also known as IS-A Relationship

1.Advantage
Code Reusability
2.How to implement it
Using Extends keyword
3 Pillars of Object Oriented Programming

1.Encapsulation (Data Hiding Abstraction)

Security

2.Inheritance

Code Reusability

3.Polymorphism

Flexibility
1. An Introduction to Java

1.1 A short history of Java


1.2 What is Java
1.3 Where is Java used
1.4 Advantages and Disadvantages of Java
1.5 Comparisons of Java and C++
1.6 Features of Java
1.7 Java Environment
1.8 Java tools
1.9 Simple Java Program
1.10 Java IDE
Editions of Java

Each edition of Java has different capabilities. There


are three editions of Java:
Java Standard Editions (JSE): It is used to create
programs for a desktop computer.
Java Enterprise Edition (JEE): It is used to create
large programs that run on the server and manages
heavy traffic and complex transactions.
Java Micro Edition (JME): It is used to develop
applications for small devices such as set-top boxes,
phone, and appliances.
Java Programs comes in many forms

1.Aplications Which are standalone Programs

2.Applets Which are Java programs that run on web browsers

3.Servlets Which are a programs that run on web servers

4.Midlets Which are Java programs that run on Mobile devices


In which sectors is Java used
1.Android Apps

2.Web Applications

3.Embeded System

4.Web Servers and Application Servers

5.Enterprise Applications

6.Scientific applications

7.Big Data Techs like Hadoop


8.IOT’s-for connectinf things
Simple: Java is a simple language because its syntax is simple, clean,
and easy to understand.

Complex and ambiguous concepts of C++ are either eliminated or


re-implemented in Java.

For example, pointer and operator overloading are not used in Java.
Object-Oriented: In Java, everything is in the
form of the object.
It means it has some data and behavior. A
program must have at least one class and
object.
•Robust :-

•Robust simply means strong.


•Java makes an effort to check error at run time and compile time.
•Java uses strong memory management.
•There are lack of pointers that avoids security problem.
•There is automatic garbage collection in java.
•There is exception handling and type checking mechanism in java.
• All these points makes java robust.
•But the main areas which Java improved were mishandled Exceptions
by introducing automatic Garbage Collector and Exception Handling.
Secure:

Java is a secure programming language


because it has no explicit pointer and programs
runs in the virtual machine. Java contains a
security manager that defines the access of
Java classes.
Compiled and Interpreted
•Usually a computer language is either compiled or interpreted

•Java combines both these approaches ,thus making Java a two stage system

•First Java compiler translates source code into byte code instructions

•In the second stage Java Interpreter generates machine code

•That can be directly executed by the machine


Why Java Is Platform Independent?

What is a Platform

A platform is the hardware or software environment in which the program runs. This plat-form in
real-life is the laptop and the underlying operating system runs on that laptop.
Each and every operating system have different structure and format.

Platform Independent Vs Platform Dependent

Platform Independent means the program that we have developed can run / execute (show
results) on any platform. That is on any operating system.

Platform Dependent means the program / software that we have developed can run /execute
(show results) on a specific platform. That is on a specific operating system.
The Compiling and running of the program process is completely
different in JAVA language compared to C/C++ language

When you write program in C/C++ and when you compile it, it is directly
converted into machine readable language(.exe). This .exe file
generated is specific to the operating system i.e, when you compile
program in windows OS, the .exe file generated for that program is
specific to only windows OS and cannot be made to run in UNIX OS.

That's why C/C++ programs are platform dependent. Here .exe file is
the Native code.
Native code is similar to machine code i.e codes that is understood
by machine. Native codes are specific to platform i.e, Native code
generated by program for Windows OS is different from Native code
generated for the same program for Unix OS.
Byte codes are nothing but intermediate codes generated after compilation and it is not
the executable code like Native code. The Byte code requires a virtual machine to
execute in machine. Byte codes generated by one platform can be executed in another
platform also.

When you write program in JAVA and when you compile it, a separate file is created for
the program compiled, this file(.class) is known as byte code of java. This byte code will
not be in executable stage. The main purpose of generating byte code for a program
compiled is to achieve platform independency that means this byte code generated in
one platform can be executed in another. The one which makes the byte code generated
in Windows OS to be executed in the UNIX OS is the JVM of UNIX platform. From this
statement, you may have understand that JVM is platform dependent and the byte code
generated by Java program is platform independent. The Byte code generated can run
on any JVM irrespective of to which platform the JVM belongs .Whatever the JVM in
which the byte code runs the output remains same.
Hence Java is called Platform Independent
For every operating system separate JVM is available which is capable to read
the .class file or byte code.

When we compile your Java code then .class file is generated by java compiler
these codes are readable by JVM and every operating system have its own JVM
so JVM is platform dependent but due to JVM, java language is become
platform independent.

Note: Java is platform independent but JVM is platform dependent.


Byte code is not machine instructions that any platform like
Windows, Mac will understand it directly. This Byte code is
understood by Java made Virtual machines. Java Virtual Ma-chines
(JVM) interprets the Byte code into machine specific instructions so
that platform can understand it.

Java Virtual Machine (JVM) plays a key role in making the Byte code
understandable to any underlying platform thus makes the Byte code
platform independent. If JVM are not pre-installed on any operating
system then byte code will fail to execute on that machine. This makes
the Byte code platform independent and Java Virtual Machine
Platform (JVM) platform dependent.
Thus when you write a piece of Java code in

a particular platform and generated an

executable code .class file.

You can execute/run this .class file on any

system the only condition is that the target

system should have JVM (JRE) installed in it.


Summarize:

• Java is a platform independent


• Java programs are compiled into Byte code which
are platform independent.

• Byte code are executed on Java Virtual Machines


(JVM).
• Java Virtual Machine (JVM) is platform dependent.

• JVM needs to be pre-installed on the machine for


executing java program.

• There are different version of JVM available in the


market to support variety of plat-form
Portable-

As discussed above, java code that is written on one


machine can run on another machine.

The platform independent byte code can be carried


to any platform for execution that makes java code
portable.
Robust

Robust simply means strong.


Java is robust because:

It uses strong memory management.

There is a lack of pointers that avoids security problems.

There is automatic garbage collection in java which runs


on the Java Virtual Machine to get rid of objects which are
not being used by a Java application anymore.

There are exception handling and the type checking


mechanism in Java. All these points make Java robust.
Multithreading

Java supports multithreading. Multithreading is a Java feature that allows


concurrent execution of two or more parts of a program for maximum
utilization of CPU.
Security

Java is best known for its security. With Java, we can develop virus-free
systems. Java is secured because:
No explicit pointer
Java Programs run inside a virtual machine sandbox
Architecture-neutral

Java is architecture neutral because there are no implementation dependent


features, for example, the size of primitive types is fixed.

In C programming, int data type occupies 2 bytes of memory for 32-bit


architecture and 4 bytes of memory for 64-bit architecture.
However, it occupies 4 bytes of memory for both 32 and 64-bit
architectures in Java.

In short, Java compiler generates an architecture-neutral object file format,


which makes the compiled code executable on many processors, with the
presence of Java runtime system.
High-performance

Java is faster than other traditional interpreted programming languages


because Java byte code is "close" to native code. It is still a little bit slower than
a compiled language (e.g., C++).

Java is an interpreted language that is why it is slower than compiled languages,


e.g., C, C++, etc.

Java enabled High performance by introducing JIT- Just In Time compiler , JIT
helps the compiler to compile the code On demand basis i.e. which ever
method is called only that method block will get compiled making compilation
fast and time-efficient. This makes the java delivering high performance.
Java has so many feature which is help to high performance like oop,
multhreading, Exception handling etc.
Distributed

In Java we can divide a prog into multiple parts and store these parts on
different computers.
Now sitting on one machine ,a java programmer can access another prog
running on other machine.
This in java gives the adv of distributed programming ,which is very useful
when we develop large projects. This is achieved using RMI

Java is distributed because it facilitates users to create distributed


applications in Java.
RMI and EJB (Enterprise Java Beans)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.
Dynamic
Dynamic means always active or changing.
Java is a dynamic language. It supports dynamic loading of classes. It means
classes are loaded on demand.

It also supports functions from its native languages, i.e., C and C++.
Java supports dynamic compilation and automatic memory management
(garbage collection).
Following are the major differences between C++ and Java.
C++
Java

Java does not support pointers, unions, C++ supports pointers, unions, operator
operator overloading and structure. overloading and structure.

C++ does not supports garbage


Java supports garbage collection.
collection.

Java is platform independent. C++ is platform dependent.

Java supports inheritance except for C++ supports inheritance including


multiple inheritance multiple inheritances

Java is interpreted. C++ is compiled.

Java does not support destructor C++ supports destructors.


JDK – Java Development Kit (in short JDK)

is Kit which provides the environment to develop


and execute(run) the Java program.

JDK is a kit(or package) which includes two things


Development Tools
(to provide an environment to develop your
java programs)
JRE (to execute your java program).
Note : JDK is only used by Java Developers.
JRE – Java Runtime Environment

is an installation package which provides


environment to only run(not develop) the java
program(or application)onto your machine.

JRE is only used by them who only wants to run


the Java Programs i.e. end users of your system.
To understand the interactions between JDK and JRE consider the following diagram.

You might also like