0% found this document useful (0 votes)
3 views30 pages

Java 2

The Java Development Kit (JDK) is essential for developing Java applications, comprising the Java Compiler (javac), Java Virtual Machine (JVM), and Java Runtime Environment (JRE). The JDK facilitates the writing, compiling, and execution of Java code, while the JVM ensures platform independence and manages memory. Java is a versatile, object-oriented, and secure programming language that supports various data types and development frameworks.

Uploaded by

wijisim538
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)
3 views30 pages

Java 2

The Java Development Kit (JDK) is essential for developing Java applications, comprising the Java Compiler (javac), Java Virtual Machine (JVM), and Java Runtime Environment (JRE). The JDK facilitates the writing, compiling, and execution of Java code, while the JVM ensures platform independence and manages memory. Java is a versatile, object-oriented, and secure programming language that supports various data types and development frameworks.

Uploaded by

wijisim538
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

• The Java Development Kit (JDK) is a software

development environment used for


developing Java applications and applets. It
provides tools and libraries required for Java
development, as well as the runtime
environment for running Java programs.
• Core Components of the JDK
• Java Compiler
• Java Virtual Machine (JVM)
• Java Runtime Environment (JRE)
• Java Compiler (javac)
• javac is the Java Compiler that translates Java
source code written in .java files into Java
bytecode, which is stored in .class files.
• Key Features of javac:
• Input:
– Takes .java source files as input.
• Output:
– Produces .class files containing platform-independent
bytecode.
• Command Syntax:
– Basic: javac [Link]
– Compile all .java files in a directory: javac *.java
– Specify output directory: javac -d <output-dir>
[Link]
• Error Reporting:
– Highlights syntax and compilation errors during
the process.
• Java Virtual Machine(JVM )
• The Java Virtual Machine (JVM) is a key
component of the Java platform that executes
Java bytecode. It acts as an interpreter between
the bytecode and the underlying hardware/OS.
• Key Features of the JVM:
• Platform Independence:
– JVM abstracts hardware and OS differences, allowing
the same bytecode to run on any platform with a
compatible JVM.
• Execution:Converts bytecode to native
machine code at runtime.
• Memory Management:Manages memory
allocation and garbage collection (automatic
cleanup of unused objects).
• Security:Includes a security manager to
enforce restrictions (e.g., accessing the file
system).
• Execution:Converts bytecode to native
machine code at runtime.
• Memory Management:Manages memory
allocation and garbage collection (automatic
cleanup of unused objects).
• Security:Includes a security manager to
enforce restrictions (e.g., accessing the file
system).
• Lifecycle of JVM Execution:
• Class Loading: The JVM loads .class files into
memory.
• Bytecode Verification: Ensures the bytecode
adheres to Java's security and structure rules.
• Execution: Bytecode is interpreted or
compiled to native machine code by the JIT
compiler.
• Components of the JVM:
• Class Loader:
– Dynamically loads Java classes.
• Bytecode Interpreter:
– Executes bytecode instructions line by line.
• Heap:
– Memory area for objects and class instances.
• Method Area:
– Stores class-level data (e.g., method metadata, static
variables).
• Stack:Memory for method execution (local
variables, call frames).
• Garbage Collector:Automatically deallocate
unused memory
• JRE (Java Runtime Environment)
• The Java Runtime Environment (JRE) is the
runtime environment required to run Java
applications. It includes the JVM and Java
class libraries but does not include
development tools like the compiler.
• Key Features of the JRE:
• Includes the JVM:Enables execution of .class
files.
• Java Libraries:Includes core Java APIs
([Link], [Link], etc.) for building
applications.
• Platform-Specific:The JRE is tailored to
specific operating systems and architectures.
• Relationship Between javac, JVM, and JRE
• Write Code:
– Developers write Java code in .java files.
• Compile (javac):
– The javac compiler converts the source code into
bytecode (.class files).
• Run (JVM via JRE):
– The JVM, part of the JRE, loads and executes the
bytecode
Features of java
• Java is a versatile and powerful programming
language widely used for developing various
types of applications.
• Object-Oriented
• Java is based on the object-oriented
programming (OOP) paradigm. Core concepts
like objects, classes, inheritance,
encapsulation, polymorphism, and abstraction
are integral to Java.
• Platform-Independent
• Java is platform-independent due to its "Write
Once, Run Anywhere" (WORA) capability. The
code is compiled into bytecode, which can run on
any device equipped with a Java Virtual Machine
(JVM)
• Simple
• Java is designed to be easy to learn and use. Its
syntax is straightforward and similar to C++, but
without complexities like pointers and operator
overloading.
• Secure
• Java provides a secure environment by avoiding
direct memory access and offering built-in
security features such as bytecode verification,
class loaders, and a robust security manager.
• Robust
• Java emphasizes reliability with features like
exception handling, automatic garbage
collection, and strong memory management to
avoid errors and crashes.
• Multithreading
• Java supports multithreading, allowing
developers to build applications capable of
performing multiple tasks simultaneously for
better performance and efficiency.
• Portable
• Java's platform independence and the uniform
behavior of its runtime environment make Java
applications portable across operating systems
and hardware.
• High Performance
• While Java is not as fast as lower-level languages
like C++, its Just-In-Time (JIT) compiler and
optimized runtime performance make it highly
efficient for most use cases.
• Distributed
• Java facilitates the development of distributed
systems through built-in APIs like RMI (Remote
Method Invocation) and CORBA. It supports
networking and internet-based applications
seamlessly.
• Scalable
• Java is suitable for building small applications
to large, enterprise-level systems due to its
scalability and robustness.
• Supports Development Frameworks
• Java works with various frameworks like
Spring, Hibernate, and Struts, making it easier
to build complex and efficient applications.
• Java is statically typed and also a strongly
typed language because, in Java, each type of
data (such as integer, character, hexadecimal,
packed decimal, and so forth) is predefined as
part of the programming language and all
constants or variables defined for a given
program must be described with one of the
Java data types.
• Data types in JAVA are of different sizes and
values that can be stored in the variable that is
made as per convenience and circumstances to
cover up all test cases. Java has two categories in
which data types are segregated
• Primitive Data Type: such as boolean, char, int,
short, byte, long, float, and double. The Boolean
with uppercase B is a wrapper class for the
primitive data type boolean in Java.
• Non-Primitive Data Type or Object Data
type: such as String, Array, etc.
• Non-Primitive (Reference) Data Types
• The Non-Primitive (Reference) Data
Types will contain a memory address of
variable values because the reference types
won’t store the variable value directly in
memory. They are strings, objects, arrays, etc.
• 1. Strings
• Strings are defined as an array of characters.
The difference between a character array and
a string in Java is, that the string is designed to
hold a sequence of characters in a single
variable whereas, a character array is a
collection of separate char-type entities.
Unlike C/C++, Java strings are not terminated
with a null character.
• 2. Class
• A Class is a user-defined blueprint or
prototype from which objects are created. It
represents the set of properties or methods
that are common to all objects of one type.
• Object
• An Object is a basic unit of Object-Oriented
Programming and represents real-life entities. A typical
Java program creates many objects, which as you know,
interact by invoking methods. An object consists of :
• State : It is represented by the attributes of an object. It
also reflects the properties of an object.
• Behavior : It is represented by the methods of an object. It
also reflects the response of an object to other objects.
• Identity : It gives a unique name to an object and enables
one object to interact with other objects.
• Interface
• Like a class, an Interface can have methods and variables,
but the methods declared in an interface are by default
abstract (only method signature, no body).
• Interfaces specify what a class must do and not how. It is
the blueprint of the class.
• An Interface is about capabilities like a Player may be an
interface and any class implementing Player must be able
to (or must implement) move(). So it specifies a set of
methods that the class has to implement.
• If a class implements an interface and does not provide
method bodies for all functions specified in the interface,
then the class must be declared abstract.
• Array
• An Array is a group of like-typed variables that are
referred to by a common name.
• Since arrays are objects in Java, we can find their length
using member length. This is different from C/C++ where
we find length using size.
• A Java array variable can also be declared like other
variables with [] after the data type.
• The variables in the array are ordered and each has an
index beginning with 0.
• The size of an array must be specified by an int value and
not long or short.
• The direct superclass of an array type is Object.

You might also like