0% found this document useful (0 votes)
17 views2 pages

Overview of Java Programming

Uploaded by

chakkushah1116
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Overview of Java Programming

Uploaded by

chakkushah1116
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

What is Java?

Developed by Sun Microsystems in 1995, Java is a highly popular, object-oriented


programming language. This platform independent programming language is utilized
for Android development, web development, artificial intelligence, cloud
applications, and much more.

// A Java program to print "Hello World"


public class Java {
public static void main(String args[])
{
[Link]("Hello World");
}
}

Java is a class-based, object-oriented programming language that is designed to


have as few implementation dependencies as possible. It is intended to let
application developers write once, and run anywhere (WORA).

Java was designed with core principles: simplicity, robustness, security, high
performance, portability, multi-threading, and dynamic interpretation.

Features of Java

Java is Object Oriented. However, it is not considered as pure object-oriented as


it provides support for primitive data types (like int, char, etc)

The Java codes are first compiled into byte code (machine-independent code). Then
the byte code runs on Java Virtual Machine (JVM) regardless of the underlying
architecture.

Java syntax is similar to C/C++. But Java does not provide low-level programming
functionalities like pointers. Also, Java codes are always written in the form of
classes and objects.

Java is used in all kinds of applications like Mobile Applications (Android is


Java-based), desktop applications, web applications, client-server applications,
enterprise applications, and many more.

For example, non-primitives are always references in Java. So we cannot pass large
objects (like we can do in C++) to functions, we always pass references in Java.
One more example, since there are no pointers, bad memory access is also not
possible.

When compared with Python, Java kind of fits between C++ and Python. The programs
are written in Java typically run faster than corresponding Python programs and
slower than C++. Like C++, Java does static type checking, but Python does not.

Execution of the java Program =>

The Java compiler (javac) converts the source code into bytecode, which is stored
in a .class file. This bytecode is platform-independent and can be executed on any
machine with a JVM.

JDK=JRE+Development Tools
if you are only interested in running Java programs on your machine then you can
easily do it using Java Runtime Environment. However, if you would like to develop
a Java-based software application then along with JRE you may need some additional
necessary tools, which is called JDK.

Execution Engine

Execution engine executes the “.class” (bytecode). It reads the byte-code line by
line, uses data and information present in various memory area and executes
instructions. It can be classified into three parts:

Interpreter: It interprets the bytecode line by line and then executes. The
disadvantage here is that when one method is called multiple times, every time
interpretation is required.
Just-In-Time Compiler(JIT) : It is used to increase the efficiency of an
interpreter. It compiles the entire bytecode and changes it to native code so
whenever the interpreter sees repeated method calls, JIT provides direct native
code for that part so re-interpretation is not required, thus efficiency is
improved.
Garbage Collector: It destroys un-referenced objects. For more on Garbage
Collector, refer Garbage Collector.

Common questions

Powered by AI

The primary limitation of Java's execution model is the initial interpretation overhead. Methods are interpreted line by line, which can slow down execution if the same method is called repeatedly. This is mitigated by the Just-In-Time Compiler, which caches native code translations for repeated method calls, speeding up execution but requiring additional resources. Furthermore, the JIT optimization may not always perfectly translate code for every architecture, potentially resulting in suboptimal performance compared to natively compiled languages .

The Just-In-Time Compiler (JIT) enhances efficiency by converting bytecode into native machine code, thereby eliminating the need for repeat interpretation during method calls, which improves performance. The Garbage Collector, on the other hand, automatically manages memory by destroying objects that are no longer referenced, thus freeing up resources and preventing memory leaks .

Java's lack of pointers enhances security and robustness by preventing direct memory access, which reduces risks like buffer overflow vulnerabilities and memory corruption. This safeguards against malicious exploits and unintended memory errors, facilitating a more reliable environment for application development and execution. The JVM's automatic memory management further compounds this by handling allocation and deallocation, preventing critical memory leaks and enhancing application stability .

"Write once, run anywhere" (WORA) is achieved in Java through the compilation of source code into platform-independent bytecode, which can be executed on any machine equipped with a Java Virtual Machine (JVM). This eliminates the need for platform-specific adaptions and recompilations, significantly enhancing software portability. The JVM abstracts the underlying hardware specifics, allowing developers to focus on application logic without being constrained by environmental differences across deployment targets, thereby reducing development time and cost .

Java balances performance between C++ and Python by offering a middle ground in terms of execution speed. Java programs typically run faster than their Python counterparts due to static typing and compiled bytecode, while they are slower than C++ programs due to overhead from the JVM and garbage collection. This balance makes Java suitable for a wide range of applications, from intensive backend systems to more rapid development environments like mobile app development .

Java's multi-threading enables concurrent execution of code segments, which enhances application performance by making efficient use of CPU resources. It allows processes like I/O operations to run in parallel with other program tasks, thus improving application responsiveness and user experience. This capability is crucial in real-time systems and applications like web servers, where timely processing is essential .

By incorporating primitive data types, Java gains performance benefits and a simplified syntax for basic operations, as handling primitives are less computationally expensive than objects. However, this leads to a trade-off where Java deviates from pure object-oriented principles, potentially complicating processes like polymorphism and inheritance. This dual system can introduce complexities when integrating object-oriented design patterns, as developers must manage conversions between primitives and their corresponding wrapper classes .

Java employs static type checking, which means that type errors are caught at compile time. This reduces runtime errors and can lead to more robust and optimized code, particularly in large projects, as issues are detected early. In contrast, Python's dynamic typing allows variables to change types, enabling more flexible coding but potentially introducing type-related runtime errors. This dynamic typing can speed up development in smaller projects but may complicate debugging in larger systems .

The Java Virtual Machine (JVM) contributes to Java's platform independence by allowing Java bytecode, which is platform-independent, to run on any device or operating system that has the JVM installed. The JVM interprets the compiled Java bytecode into native machine code specific to the host machine, thus enabling the same Java program to be executed across different systems without modification .

Java is not considered purely object-oriented because it supports primitive data types like int and char, which are not objects. This design choice allows Java to achieve higher performance and simpler syntax in certain contexts since primitives are less resource-intensive than objects. However, this deviates from the strict object-oriented paradigm where everything should be an object, which can affect consistency in code design .

You might also like