Chapter 1-Introduction to JAVA
Chapter 1-Introduction to JAVA
3.How to implement it
by declaring access modifiers
by declaring your data as private
Abstraction -- Abstract means Incomplete
1.What is Abstraction
Hiding internal implementation ,just highlight the set of services that we are going to
offer
3. How to implement it
Using GUI screen, Interface. API ‘s etc
Encapsulation –
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
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
Security
2.Inheritance
Code Reusability
3.Polymorphism
Flexibility
1. An Introduction to Java
2.Web Applications
3.Embeded System
5.Enterprise Applications
6.Scientific applications
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 :-
•Java combines both these approaches ,thus making Java a two stage system
•First Java compiler translates source code into byte code instructions
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 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.
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
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 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
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.