Java-Basic
Java-Basic
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
Java Interpreter
for Macintosh
Java Java
Source BYTECODE Java Interpreter for
Program Compiler in class files. MS - Windows
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.
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
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
Java compiler
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
Hardware
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. .