0% found this document useful (0 votes)
31 views7 pages

Introduction to Java Programming Basics

The Java programming language, released by Sun Microsystems in 1995, is known for its simplicity, portability, security, and robustness, making it one of the most popular programming languages today. Java's platform independence is achieved through the use of the Java Virtual Machine (JVM), which allows Java code to be compiled into bytecode that can run on any operating system. The Java Development Kit (JDK) includes the Java Runtime Environment (JRE) and various development tools, enabling developers to create applications using object-oriented programming principles.

Uploaded by

malcolmevelia501
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)
31 views7 pages

Introduction to Java Programming Basics

The Java programming language, released by Sun Microsystems in 1995, is known for its simplicity, portability, security, and robustness, making it one of the most popular programming languages today. Java's platform independence is achieved through the use of the Java Virtual Machine (JVM), which allows Java code to be compiled into bytecode that can run on any operating system. The Java Development Kit (JDK) includes the Java Runtime Environment (JRE) and various development tools, enabling developers to create applications using object-oriented programming principles.

Uploaded by

malcolmevelia501
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 Programming Language

Early in the history of computer programming, resources were incredibly tight.


Computers weren't capable of keeping track of much information at all, and it
became necessary to efficiently use every bit of programming power that computers
had. At the same time, we needed to make that power accessible for humans who
write the programs that make it all work.

In 1995, Sun Microsystems released the Java programming language to tackle these
issues. Since then, Java has been known for being simple, portable, secure, and
robust. Though it was released over twenty years ago, Java remains one of the most
popular programming languages today. Due to its innovative use of a built-in
compiler, Java code can be run on different operating systems and platforms.
Indeed, Sun Microsystems’ slogan for Java was, and largely still is, “write once, run
everywhere”.

As stated earlier in the course, more than 10,000 companies use Java somewhere in
their stack today, and that's why we're going to start by learning about it first.

#Welcome to the world of Java Programming!


As a developer, you will write Java programs. The code that you write will then be
passed into a compiler, which will hand off that code to what's known as a Java
Virtual Machine (JVM). The JVM's job is to act like a universal translator, making your
code available to any operating system that tries to run it, such as Windows,
MacOS, and Linux:
Java programs are passed into a compiler, which then uses a JVM to get that code running on modern
operating systems.

This compilation is why Java is still so useful today. When programs are written to
run on Windows, they generally won't be able to run MacOS or Linux. This is true of
many high-level languages–the ones that we developers write–because they're
usually designed for a specific operating system. When we run a program, the OS
does the work of translating that higher-level language down into a lower-level
language, which eventually leads to the ones and zeroes that the hardware needs to
do its job. With Java, we can write our code wherever we need to because it will be
compiled for us. This makes Java a "Platform Independent Language".
#What is the Java Virtual Machine?
The JVM (Java Virtual Machine) is an abstract machine that enables your computer to
run a Java program. The computer you're using to view this page is a physical
machine running software that has produced this page. You can think of virtual
machines as being implementations of software designed to run like hardware, but
in a way that allows one set of hardware to run many different machines for many
different purposes.

When you run a Java program, the Java compiler first compiles your Java code into
an intermediate step called bytecode. Bytecode is essentially a quick stopover–one
that doesn't depend upon the OS, and can easily be translated out to whatever
language it needs to be. From here, the JVM translates that bytecode into native
machine code, a specific set of instructions that a computer's CPU can execute
directly.

Java is a platform-independent language because when you write Java code, it's
ultimately written for the JVM, not for your physical machine. Since the JVM executes
this platform-independent Java bytecode, anything you write in Java can be run on
any system that wants to run it.

How a Java Program works: from developer to user

#Zooming Out from the JVM


The JVM is just one piece of a larger puzzle when it comes to Java delivery pipeline.
Let's keep zooming out for a moment and see what else is required to get a program
up and running on a user's computer.

#The Java Runtime Environment


The Java Runtime Environment (JRE) is a software package that provides a bunch of
useful tools that we'll be using to get our Java programs running. This includes Java
class libraries, the aforementioned Java Virtual Machine (JVM), and other
components that are required to run Java applications.

You can think of the JRE as a container that holds the JVM.

The JRE is a runtime environment that contains our JVM and some helpful class libraries.

If you only need to run Java programs, but you don't need to develop them, the JRE
is all you need.

#Java Development Kit


The Java Development Kit (JDK) is a software development kit required to develop
applications in Java. When you download a JDK, the JRE described above will be
included in that installation.

In addition to the JRE, the JDK also contains a number of development tools, like
compilers, JavaDoc for documentation purposes, a Java Debugger, and a few other
tools:

The JDK contains our JRE, plus some helpful tools for making sure that our application runs as planned.

#When You Put It All Together:


All together, this is what the JDK ends up looking like:
The Java Development Kit all in one image.

#The Basics: Java and OOP


Now that you understand how a Java program gets from the developer's keyboard
through to the user's screen, we should talk briefly about how we write Java
programs: object-oriented programming (OOP). There are many different ways of
programming, but Java adheres to the OOP paradigm. In OOP, we write our code to
create objects which contain code including variables and methods that they use to
interact with other objects.
For now, let's use a metaphor: think of objects as Lego bricks. Each brick will have its
own specific size and shape, and it can be combined with other bricks to create
larger structures. Some Legos will be more complex than simply interlocking with
other bricks–like having axels, wheels, or hinges–but none of them is particularly
impressive alone. It is only when they come together that they can create something
truly spectacular.

A pile of Legos, care of Nick Nice on Unsplash


Every object in OOP has a purpose to fulfill, but each one is a separate entity that can
be detached from the program as a whole. OOP, therefore, represents a modular
design paradigm where individual entities come together to create complex
programs capable of nearly anything you can imagine a computer doing.

#Summary
These are the basics that make Java work, but remember: this lesson is just a primer
to launch us into writing a bit of code ourselves. We'll dive much deeper into each of
these pieces as we progress through the curriculum, so don't worry about
researching the above for hours on your own. We'll get there.

#Extra Resources
If you'd like more information about how a platform-independent language works,
check out this quick two minute video:
[Link]
Back
Unsubmit
Next

Common questions

Powered by AI

The 'write once, run everywhere' philosophy offers the benefit of platform independence, reducing development and deployment costs as developers do not need to create OS-specific versions of applications. It simplifies maintenance and updates, since changes can be made in one codebase and effective across all platforms. However, this approach may have limitations in environments requiring optimized performance for specific hardware, as Java's abstraction layer might lead to overhead and reduced efficiency. Additionally, while Java is designed to be platform-independent, the integration with platform-specific libraries can pose challenges .

Java simplifies development and execution by being platform-independent, a capability not offered by many other high-level languages. Its built-in compiler translates Java code into bytecode, which the JVM can run on any operating system, eliminating the need for OS-specific source compilations. This 'write once, run everywhere' capability minimizes code repetition and allows developers to focus on functionality. Additionally, Java's object-oriented programming paradigm supports modular, reusable code, making complex software easier to develop and maintain .

The JVM contributes to Java's platform independence by functioning as an abstract machine capable of running Java programs on any operating system. It achieves this by interpreting Java bytecode, which is an intermediate form generated by the Java compiler from Java source code. Bytecode is designed to be OS-independent, allowing the JVM to translate it into native machine code specific to the underlying hardware, thereby enabling the same Java program to execute across different platforms without modification .

Java's status as a 'Platform Independent Language' remains highly relevant in today's technology ecosystem due to the prevalent use of diverse computing environments. It enables application deployment across various operating systems without the need for recompilation, significantly enhancing development efficiency and reducing time-to-market. This attribute is particularly crucial for enterprises operating globally, as it ensures consistent behavior of applications across different user environments. While modern languages also emphasize cross-platform capabilities, Java's mature ecosystem and robust supporting frameworks continue to reinforce its adoption in enterprise solutions, mobile applications, and web services .

The Java compiler first transforms source code into an intermediate form known as bytecode. This process involves parsing the code, verifying syntax, and optimizing the code for performance while preserving its meaning. The bytecode is not tied to any specific machine architecture, making it platform-independent. The JVM subsequently translates this bytecode into native machine code, which consists of CPU-specific instructions that the processor can execute directly. This two-step process facilitates cross-platform compatibility and efficient execution of Java applications .

Bytecode and the JVM enhance Java's security by enabling rigorous code verification before execution. The JVM includes a class loader and a bytecode verifier that check the code for illegal operations, ensuring that it adheres to Java's strict security model. This prevents common security threats like stack overflows and unauthorized memory accesses by enforcing access controls during execution. By compiling code into bytecode and executing it in a controlled environment, Java limits the chances of executing malicious code, contributing to its robustness and security .

The JRE provides the necessary environment to run Java programs, including the JVM and essential class libraries. It is primarily used for executing Java applications by end-users. On the other hand, the JDK includes the JRE as well as development tools required for creating Java applications. These tools include compilers, the Java Debugger, and JavaDoc, making the JDK essential for Java developers who need to write and test applications .

The JDK expands upon the JRE's functionalities by encompassing a comprehensive suite of development tools necessary for creating Java applications. While the JRE provides the foundational environment for running Java applications through the JVM and essential libraries, the JDK includes additional tools such as a compiler, debugger, and documentation generator. These tools are crucial for writing, debugging, and documenting Java code, making the JDK indispensable for developers who need to not only execute but also create and maintain Java programs .

The analogy compares objects in OOP to Lego bricks, where each object, like a brick, has specific attributes and can connect with other objects to form more complex structures. In Java, objects are instances of classes containing data and methods that describe their behavior. Similar to Lego bricks that can create intricate constructions when combined, Java objects interconnect to build sophisticated applications. This modular approach in OOP allows for flexibility and reuse of code within a program .

Java's OOP paradigm promotes software modularity and reuse through encapsulation, inheritance, and polymorphism. Encapsulation allows data and related methods to be bundled into objects, creating a clear separation between an object's interface and implementation. This supports modular design, as objects can be developed and maintained independently. Inheritance enables the creation of new classes based on existing ones, reducing redundancy and allowing functionality extension. Polymorphism allows methods to operate on objects of different classes through a common interface, facilitating code reuse and flexible design. These principles of OOP contribute to the development of scalable and manageable software systems .

You might also like