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

Java-Basic

Uploaded by

PRODYOT SINHA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Java-Basic

Uploaded by

PRODYOT SINHA
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

INTRODUCTION TO JAVA

Xonigiv
TheOOPjava is a pure object oriented language. Hence it supports all corner stones of
(Object Oriented Language). We should first discuss -these corner stones of
OOP.
OBJECT: An object is aruntime, ldentifiable entity, whích possesses some
specific set of characteristics and behaviors.
The STA TE of an object is represented through the values of its characteristics at a
given point of time. Like a electrical switch, which has two states either on or of.
ABSTRACTION: Abstraction refersto the act of representing essential features
without including the implementation details and explanations.
* ENCAPSULATION: The wrapping up of data and functions/methods (that
operate on data) into single unit (called class) is known as encapsulation.
Encapsulation is a way to implement data abstraction. Encapsulation hides the details
of the implementation of an object. Hence, they are complementary concept -
abstraction focuses upon the observable behaviors of an object, whereas
encapsulation focusesuponi the implementation that give riseto those behaviors.

name name

parent's
brothers roll class
profession & sisters

Medical
locality
history section marks
obtained
mafks
obtained talents &
wards Conduct
roll, class & section

STUDENT ENTITY IN REAL WORLD ABSTRACTION FOR RESULT TRACKING


SYSTEM

CLASS:Aclass represents a set of objects that share common characteristics


and behaviors.

In OOP, objects are defined by defining aclass for them.


INHERITANCE: Inheritance refers to the act of sharing characteristics and
behavior of an existing class for designing a new class. The pre-existing class
is termed as the base or super class and the newly designed class, which
shared the characteristics and behaviors of the base class, is called the derived
or sub class.

As library functions can be incorporated in different programs, an existing class can be


Used in different programs, without modifying it but adding additional features and
capabilities to it. This phenomenon is known as reusability. This done by deriing a
new cass from the existing one, using inheitarnce. The new class will inherit the
capabilities of the old class. On the other hand the newly designed class is freet
newfeatures of its own.

POLYMORPHISM: Polymorphism means single look, different activities


There may be a single function (overloaded), which can be
invoked using different
arguments. This is an example of polymorphism. There are also other forme F
polymorphism available in Java.
Moreover that, OOP also providesthe facilities Tor generic class design, using which
one can design a class that can be used for multiple data types.

n 1991 James Gosling develops Oak


(later renamed Java), as a language for
programming with intelligent consumer electronic devices

Java comes in three flavors namely:

1. Java SDK (Software Development Kit) for


developments. This is what we called Core Java. Thisstand-alone
section is alsoapplication
reguired
indeveloping applications with other Java flavors.
2. J2EE (Java2 Enterprise Edition) Used in
developments. This enables us to develop distributed enterprise application
WEB applications for
client-server architecture.
3. J2ME (Java2 Micro edition) This tool is used for
can be run upon such devices, those have limited developing applications that
memory and display
facilities, such as, mobile phones.

Java is basically a programming language as well as a platform. We can


develop
application soft wares using Java as a programming language. On the other hand Java
provides a runtime environment, which can be used by Java applications as a
platform.

Java Virtual Machine: Programs written in Java are


compiled into Java byte-code,
which is then interpreted by a special Java Interpreter for a specific platform. Actually
this Java interpreter is known as the Java Virtual
Machine
language for the Java Virtual Machine is the Java Byte-code. (JVM). The machine
interpreter running on any machine Actually the Java
that is why, the name - Java Virtualappears and behaves like a virtual processor chip
Machine, The Java virtual machine is an absract
machine designed to be implemented on the top existing processor. It hides the
underlying operating system from Java application, ofThus it provides a level of security
for the host environment. AJava
as well as hard ware. virtual machine can be implemented using sott walo
Compiler for Macintosh Machine code for
Macintosh

Source Compiler for MS -Windows Machine code for


Program MS - Windows

Compiler for UNIX flavors Machine code for


UNIX flavors

Ordinary Compilation Process

Java Interpreter
for Macintosh

Java Java
Source BYTECODE Java Interpreter for
Program Compiler in class files. MS - Windows

Java Interpreter for


UNIX flavors

Java Compilation Process

Java Byte code: The Java byte-code is the machine instruction for a Java processor
chip called Java Virtual Machine. The byte-code is independent of the platform it has
to run upon. Unike native executable code, Java byte-code is the same on every
platform. First Javasource code is compiled and their byte-codes are produced. Then
the interpreter reads the byte-code ad translates it into native language of the host
environment on the fly.

Java Platform: JVM combined with Java APls makes Java Platfom. The Java APls
are libraries of compiled code that, can be used in our Java applications. In other
words, the Java APls consist of the classes that programmers are allowed to use in
their own classes.

Garbage Collection: Many programming languages permit the memory to be


allocated dynamically at runtime. The process of allocating memory varies base on the
syntax of the language, but always involves returning a pointer to the starting address
of amemory block.

After the allocated memory no longer required (the pointer that reference the memory
has gone out of extent), the program or runtime environment should de-allocate the
memory.
In C, C++, and other languages, yoU are responsible for de-allocating the
This can be difficult exercise at times, because you do not always know in memory.
advance
when memory should be released. Programs that do not de-allocate memory can
cra_h eventually when there is no memory left on the system to allocate. These
programs have said to have memory leaks.
Java programming language removes you from the responsibility of de-alloca
memory. It provides a system-level thread that tracks each memory allocation, Dr
idle cycles in the JVM, the garbage collection thread checks for and frees any memo
that can be freed.
Garbage collection happens automatically during the lifetime of aJava technolonw
program, eliminating the need to de-allocate memory and avoiding memory leaks
However, garbage collection schemes can vary dramatically across
implementations. JVM

The Java Runtime Environment: The following figure illustrates the JRE and how to
enforces code security.
Runtime

Compile Class loader

Load from Bytecode


Test.java hard disk, verifier
network,
or other
javac
SOurces
Interpreter

Test.class Runtime

Hardware

Java software source files are compiled in the sense that they are
of bytecodes from the text format in which you write them. The converted into a set
.class files. bytecodes are stored in

At runtime, the bytecodes that makeup a Java software program are


loaded, checked,
and run in an interpreter. In case of applet (small Java utility programs
WEB page),you can download the bytecodes from server, and then they embedded in a
are
interpreted by the JVM built into the browser.

Jav source code

Java compiler

Applet type Application type

Jaya enabled Java


WEB brow_er Interpreter

OUTPUT
The interpreter has two functions: it executes bytecodes and it makes the appropriate
calls to the underlying hardware.
In some Java technology runtime environments, a portion of the verified bytecode is
compiled to native machine code and executed directly on the hardware platform. This
enables the Java software code to run close to the speed of C or C++ with a small
delay to load time to enable the code to be compiled to the native machine code.

Runtime

ompile Class loader

Load from Bytecode


Test.java hard disk, verifier
network,
or other
javac SOurces
Interpreter JIT
code
generator
Test.class Runtime

Hardware

Operation of the JRE with a Just-in-time (JIT) COmpiler

ASimple Java Program


public class Test{
public static void main(Stringl] args){
System.out.println(" I want to learn Java ...."):
}/ End of main.
}I/ End of class Test

Output
F:ljprglCore Java Intro>javac Testjava
F:jprg\Core Java Intro>java Test
I want tolearn Java

Explanation
public: This keyword is called an access modifier, these modifiers controls how other
parts of the program can access this code. Here itdefines that the method main or the
class Test is accessible from any other classes.
static: It declares the main method as one that belongs to the entire class and it can be
invoked irrespective of any instance of the class Test. main must be declared as static
since the interpreter uses this method before any object is created.
System: It is a standard class that contains objects that encapsulate streams for
standard IO devices for our system. It is contained in the package java.lang, and as all
Java programs automatically import this package, hence it is available to all of them. .

You might also like