COS201 Lecture 3
COS201 Lecture 3
LECTURE 3
JAVA PROGRAMMING
Introduction
Java is a high-level, class-based, object-oriented programming language that is designed to have
as few implementation dependencies as possible. It is a general-purpose programming language
intended to let programmers write once, run anywhere (WORA), meaning that compiled Java
code can run on all platforms that support Java without the need to recompile. Java applications
are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of
the underlying computer architecture. The syntax of Java is similar to C and C++, but has fewer
low-level facilities than either of them. The Java runtime provides dynamic capabilities (such as
reflection and runtime code modification) that are typically not available in traditional compiled
languages.
Brief history
Java gained popularity shortly after its release, and has been a very popular programming
language since then. Java was the third most popular programming language in 2022 according
to GitHub. Although still widely popular, there has been a gradual decline in use of Java in
recent years with other languages using JVM gaining popularity.
Java was originally developed by James Gosling at Sun Microsystems. It was released in May
1995 as a core component of Sun's Java platform. The original and reference implementation
Java compilers, virtual machines, and class libraries were originally released by Sun under
proprietary licenses. As of May 2007, in compliance with the specifications of the Java
Community Process, Sun had relicensed most of its Java technologies under the GPL-2.0-only
license. Oracle offers its own HotSpot Java Virtual Machine, however the official reference
implementation is the OpenJDK JVM which is free open-source software and used by most
developers and is the default JVM for almost all Linux distributions.
As of September 2024, Java 23 is the latest version (Java 22, and 20 are no longer maintained).
Java 8, 11, 17, and 21 are previous LTS versions still officially supported.
Java software runs on everything from laptops to data centers, game consoles to scientific
supercomputers.
Principles
There were five primary goals in creating the Java language:
1. It must be simple, object-oriented, and familiar.
2. It must be robust and secure.
3. It must be architecture-neutral and portable.
4. It must execute with high performance.
5. It must be interpreted, threaded, and dynamic.
Uses of Java
Java is a popular programming language owned by Oracle, and more than 3 billion devices run
Java. It is used for:
1. Mobile applications (specially Android apps)
2. Desktop applications
3. Web applications
4. Web servers and application servers
5. Games
6. Database connection
Benefits of Java
1. Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)
2. It is one of the most popular programming languages in the world
3. It has a large demand in the current job market
4. It is easy to learn and simple to use
5. It is open-source and free
6. It is secure, fast and powerful
7. It has huge community support (tens of millions of developers)
8. Java is an object oriented language which gives a clear structure to programs and allows
code to be reused, lowering development costs.
9. As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or
vice versa
2. JRE (Java Runtime Environment): JRE contains the parts of the Java libraries required to
run Java programs and is intended for end-users. JRE can be viewed as a subset of JDK. JDK
(Java Development Kit): JDK is intended for software developers and includes development
tools such as the Java compiler, Javadoc, Jar, and a debugger. JVM: JVM (Java Virtual
Machine) is an abstract machine. It is a specification that provides a runtime environment in
which java bytecode can be executed. JVMs are available for many hardware and software
platforms.
Some PCs might have Java already installed. To check if you have Java installed on a Windows
PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):
C:\Users\Your Name>java -version
If Java is installed, you will see something like this (depending on version):
java version "22.0.0" 2024-08-21 LTS
Java(TM) SE Runtime Environment 22.9 (build 22.0.0+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 22.9 (build 22.0.0+13-LTS, mixed mode)
If you do not have Java installed on your computer, you can download it for free at oracle.com
ASSIGNMENT
1) Enumerate tools required for writing, compiling and running Java programs.
2) Describe how you’ve installed the Java SE (Standard Edition) on any available computer
system.