Anda di halaman 1dari 7

MODULE OF INSTRUCTION

Introduction to Java

This is the first module of the course Computer Programming 2 and it


is about introducing Java. In this module we will be discussing the
background of Java and the Java technology. We will also discuss the
features and phases of Java.

Java Background
Java was developed in 1991 by a team of engineers called the Green
Team led by James Gosling and released in 1995 by Sun
Microsystems. It was initially called oak after an oak tree that stood
outside his office. Java was originally designed to use in embedded
chips in various consumer electronic appliances such as toasters and
refrigerators. In 1995 its name was changed to Java because a
trademark search revealed that Oak was used by Oak Technology and
it was also redesigned for developing Web applications. All the Java
releases since 2010 is owned by Oracle because they acquire Sun
Microsystems in that year.

Today Java is everywhere, in any devices and platform, in the Internet


and local device, from smart phones to computers, games to business
solutions. You can find Java anywhere and Java helps us to have a
better future.

What is Java Technology?

A programming language, Java is a general-purpose programming


language that can be used to create all kinds of applications on your
computer. Java syntax is mostly derived from C and C++, therefore if
you know how to write in C or C++ you could easily write Java
programs.

A Java platform, it is a software environment where the Java program


runs. There are four platforms that Java offers, these are:

Java Standard Edition (Java SE), it is used to develop client-


side applications or an application that can run standalone.
Java Enterprise Edition (Java EE), it is used to develop server-
side or network applications. There are several technologies

Computer Programming 2 1
Week 3-4 Introduction to Java

that JavaEE offers, such as Java servlets, JavaServer Pages


(JSP), and JavaServer Faces (JSF).
Java Micro Edition (Java ME), it is used to develop
applications for small devices, such as cell phones, PDA and
smart phones.
JavaFX is a platform for creating desktop applications and rich
internet applications that run across a wide variety of devices.

Phases of Java Program

The first phase of a java program is writing your source code in a text
editor or IDE (Integrated Development Environment). The text editors
that can be used are notepad, vi, sublime, etc. and for the IDE are
NetBeans, Eclipse, BlueJ, etc. The written code should be saved with
the .java extension.

After creating the source file, you need to compile it using the javac
compiler. This process will produce a compiled file containing
bytecodes and with the extension name of .class. Normally the
compiler (other programming language like C, C++, etc.) should
produce object code (executable program) that is understandable by
the processor, however in Java the compiled object is a .class file
which contains bytecode that is not readable by your processor.

The Java Virtual Machine is responsible in interpreting your .class file.


It converts the bytecodes into another code that can be understood by
your processor. Since it is interpreted, the code will only be translated
every time you perform operation of you program, unlike compiler all
your code will be translated at once.

2
MODULE OF INSTRUCTION

Java Features
The main reason why they created Java was to deliver a portable and
secured programming language. In addition to these major features,
other Java features are the following:

1. Simple
2. Object-Oriented
3. Platform independent
4. Secured
5. Robust
6. Architecture neutral
7. Portable
8. Dynamic
9. High Performance
10. Multithreaded
11. Distributed

Simple

Java is simple because of the following:

It is easy to learn and the syntax is easy to understand, clean


and user-friendly.

The syntax is mostly derived from C and C++ therefore it is


easier to learn Java after C or C++. The confusing features of
C++ were removed such as pointers, operator overloading etc.

It has Garbage Collector that automatically removed


unreferenced or unused objects. One of the problems
encountered when writing a program is memory leak or the
program consumes too much available memory because the
programmer forget to deallocate memory. In Java, you no
longer need to deallocate the memory the garbage collection
thread is responsible for cleaning your memory.

Computer Programming 2 3
Week 3-4 Introduction to Java

Object Oriented

In Java, program focuses on Object that may contain data or


attributes and behaviour or methods. Java programs are made out
of objects that interact with one another, and it can be easily
extended since it is based on Object model.

Platform Independent

A Java program is platform independent, which means you just


need to write a program once and run it on many different operating
systems. Unlike other programming languages such as C, C++, etc.,
they are compiled on a specific platform. The Java Virtual Machine or
JVM is responsible for making the same program capable of running
on multiple platforms.

Code Security

Java is secured which allow us to develop a program that is


free from virus or tampering. Java is secured because of the following
features:

4
MODULE OF INSTRUCTION

Java programs run inside a virtual machine (JVM). The Java


Virtual Machine is an abstract machine that is implemented by
emulating software on a real machine. Typically the program
(created from another language like C) directly interacts with
the operating system and if the program is infected with virus,
it will definitely affect the operating system, unlike in Java
program will not directly run though the operating system.

The Class Loader is responsible for loading classes into Java


Virtual Machine. It adds security by separating the package for
the classes of the local file system from those that are imported
from network sources and classes are verified before it is
loaded to JVM.

The Bytecode Verifier is responsible for traversing the


bytecode and checking the code fragments for illegal code that
can violate access right to object. It checks the bytecodes for
the correct number and type of operands, data types are not
accessed illegally, the stack is not over or underflowed and that
methods are called with the appropriate parameter types.

Robust

Robust means strong and effective in all or most situations and


condition. Java uses strong memory management and automatic
garbage collection mechanism. It has no pointers that avoids
security problem. There is an exception handling and type
checking mechanism. The Java Compiler checks the program for
any errors and interpreter checks any run time error.

Architecture-neutral

Architecture refers to the processor (CPU Architecture), Java


programs can run on any processors without considering the
architecture or vendor (providers). The languages like C or C++ is
architecture dependent which means you need to have a separate
program for 32-bit and 64-bit Operating System.

Portable

According to Sun Microsystem:

Computer Programming 2 5
Week 3-4 Introduction to Java

Portability = Platform Independent + Architecture Neutral

Language Portability is when you can do the WORA ("Write


once, run anywhere") program. Java bytecode can be ported to
any platform regardless its architecture. It's a combination of
platform independence and architectural neutral that makes Java
portable.

Dynamic

Byte code makes Java become dynamic and can adapt to an


evolving environment. New features can be easily integrated or
the software can be easily extended without creating a new
version.

High Performance

Even though Java is an interpreted language the execution speed


of Java programs improved significantly because of just-in-time
compilation (JIT). Java is also faster compared to any interpreted
language because it uses byte code that is close to native code.

Multithreaded

Multithreading is a capability of a single program to execute


several tasks independently and continuously. Playing music
while downloading the video file in one program is an example of
multithreading. Multithreading is important for multimedia,
network programming etc.

Distributed

Distributed computing is a model wherein the components of a


software are located in multiple networked computers working
together to achieve common goals. In this way, it will improve the
efficiency and performance of the software. For example, in a 3-
tier model, rendering user interface is performed in one computer,
another computer conducts reading and writing to the database

6
MODULE OF INSTRUCTION

and business logic is done in another computer. Java allows you to


create distributed software, since networking capability is
integrated into it.

LESSON SUMMARY:

In this lesson, you should have been introduced to Java.

Java was developed in 1991 by James Gosling.

Java is a programming language and a platform.

Java code generates bytecodes after compilation and


interpreted by JVM.

Java is simple, object-oriented, platform independent, secured,


robust, architecture neutral, portable, dynamic, high
Performance, multithreaded and distributed.

Computer Programming 2 7

Anda mungkin juga menyukai