0% found this document useful (0 votes)
64 views

Introduction To 2 - OOP

The document provides an introduction to the Java programming language. It discusses that Java is an object-oriented language that runs on a virtual machine and is platform independent. It describes Java's main platforms and editions. It also outlines some key Java features like being object-oriented, platform independent through bytecode, multithreaded, simple, secure, architecture-neutral, and portable. The document provides an overview of Java to introduce students to the programming language.

Uploaded by

Thobius Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Introduction To 2 - OOP

The document provides an introduction to the Java programming language. It discusses that Java is an object-oriented language that runs on a virtual machine and is platform independent. It describes Java's main platforms and editions. It also outlines some key Java features like being object-oriented, platform independent through bytecode, multithreaded, simple, secure, architecture-neutral, and portable. The document provides an overview of Java to introduce students to the programming language.

Uploaded by

Thobius Joseph
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

UNIVERSITY OF IRINGA

FACULTY OF SCIENCE AND EDUCATION


DEPARTMENT OF INFORMATION TECHNOLOGY

LECTURE TWO
INTRODUCTION TO JAVA

Reg, No. Course Year


DIT 206 Introduction to OOP 2019/ 2010

Ass. Lecturer: Thobius Joseph (M.Sc. In Telecom Eng.)


Date: October, 2019

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


CONTENTS

1. Introduction to JAVA

2. Java essentials and JVM

3. Java Features

4. Java local environment setup

5. Java program structure and description

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Required Knowledge

Basic Knowledge of C Programming and C++ will


help you to understand Java Programming
quickly, and If you don't know programming and
you are studying Java, so it's quite complicated.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 Java is an object-oriented programming language with a built-in
Application Programming Interface (API) that can handle Graphical
User Interfaces (GUI) used to creates applications or applets.
 Much of the syntax in java is similar to C and C++. It has obtained
its format from C, and OOP features from C++.
 Java is a high-level programming language originally developed by
Sun Microsystems and released in 1995. Java runs on a variety of
platforms, such as Windows, Mac OS, and the various versions of
UNIX.
 Java is well suited for both standalone and web application
development and is designed to provide solutions to most of the
problems faced by users of the internet era
 Java may have three large difference from other languages
 It does not have pointers
 In java your forced to write object-oriented code

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 Java programs are platform independent which means they can be
run on any operating system with any processor as long as the Java
interpreter is available on that system.
 Java code that runs on one platform does not need to be
recompiled to run on another platform; it's called write once, run
anywhere(WORA).
 Java Virtual Machine (JVM) executes Java code, but it has been
written in platform-specific languages such as C/C++/ASM, etc. JVM
is not written in Java and hence cannot be platform independent,
and Java interpreter is a part of JVM.
 Java has four platforms editions
 Standard Edition (SE)
 Enterprise Edition (EE)
 Micro Edition (ME)
 JavaCard

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 Standard Edition (SE)
is a computing platform for development and deployment of portable code for desktop
and server environments. Java SE was formerly known as Java 2 Platform, Standard Edition
(J2SE). Java SE defines a range of general-purpose APIs—such as Java APIs for the Java Class
Library—and also includes the Java Language Specification and the Java Virtual Machine
Specification.
 Enterprise Edition (EE)
Is a set of specifications, extending Java SE targeting large distributed enterprise or Internet
environments (web services). Java EE applications are run on reference runtimes, that can
be micro services or application servers, which handle transactions, security, scalability,
concurrency and management of the components it is deploying.
 Micro Edition (ME)
is a computing platform for development and deployment of portable code for embedded
and mobile devices (micro-controllers, sensors, gateways, mobile phones, personal digital
assistants, TV set-top boxes, printers).Therefore targeting environments with limited
resources.
 JavaCard
refers to a software technology that allows Java-based applications (applets) to be run
securely on smart cards and similar small memory footprint devices. Java Card is the tiniest
of Java platforms targeted for embedded devices. Java Card gives the user the ability to
program the devices and make them application specific. It is widely used in SIM cards
(used in GSM mobile phones) and ATM cards.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 The naming convention of java has been changed several times over the Java
version history, which dependents on release versions of Java.
 As of 20 March 2018,major release versions of Java

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 From the table of previous slide we can see that the naming and the version
number have been changing over times:
 Versions 1.0 and 1.0 are named as JDK (Java Development Kit).
 From versions 1.2 to 1.4, the platform is named as J2SE (Java 2 Standard Edition).
 From versions 1.5, Sun introduces internal and external versions. Internal version
is continuous from previous ones (1.5 after 1.4), but the external version has a big
jump (5.0 for 1.5), which implies there are biggest changes have been
implemented.
JAVA APPLICATIONS
• Web Application - Java is used to create server-side web applications. Currently,
Servlet, JSP, Struts, JSF, etc. technologies are used.
• Standalone Application - It is also known as the desktop application or window-
based application. An application that we need to install on every machine or
server such as media player, antivirus, etc. AWT and Swing are used in java for
creating standalone applications.
• Enterprise Application - An application that is distributed in nature, such as
banking applications, etc. It has the advantage of the high-level security, load
balancing, and clustering. In Java, EJB is used for creating enterprise applications.
• Mobile Application - Java is used to create application software for mobile
devices. Currently, Java ME is used for building applications for small devices, and
also Java is a programming language for Google Android application development.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
 An API is a set of commands, functions, protocols, and
objects that programmers can use to create software or
interact with an external system. It provides developers with
standard commands for performing common operations so
they do not have to write the code from scratch. For example,
if you're dealing with dates, you'll need to import the Java API
for dates, like the kind you can see below;
import java. Util.Date // name of API
 The classes in the Java APIs are organized into separate
groups called packages. Each package contains a set of
related interfaces, classes, and exceptions.
Example - General purpose packages: java.io and java.math,
Special purpose packages: java.beans and javax.swing

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
JAVA FEATURES
Here we list the basic features that make Java a powerful, object-oriented, and popular
programming language.
• Object-Oriented – its follow object model. Everything in Java (constants, variables, and
methods) are defined inside a class and accessed through objects.
NB: Java also supports primitive data types that are not objects.
• Platform Independent- Java archive this by compile its source code to an intermediate form
called bytecode, this bytecode is a platform-independent code, java use its interpreter to
execute bytecode .

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
JAVA FEATURES
• Its both compiled and interpreted –
Compilation: the program text file is first converted to machine code with
a program called compiler. A linker may be used for connecting together
multiple code files. The output of the compiler is executable code.
Interpretation: an interpreter reads one line of a program convert to
machine code and executes it before going to the next line. Java byte
code is translated on the fly to native machine instructions and is not
stored anywhere.
Multithreaded- With Java's multithreaded feature it is possible to write
programs that can perform many tasks simultaneously. For example,
consider a four-gas burner on which food is cooked. The cook, in order to
save time, puts milk to boil on one gas burner, rice on the other, makes
chapattis on third, and vegetable on the fourth. The cook switches
between all the items to be cooked so that neither of the items are red-
heated to lose their taste. He may he even lower/brigthen up the gas as
and when required. Thread can be loosely defined as a separate stream
of execution that takes place simultaneously and independent of
everything else that might be happening.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
JAVA FEATURES
• Simple − Java is designed to be easy to learn. If you understand the basic concept
of OOP Java, it would be easy to master.
• Secure − With Java's secure feature it enables to develop virus-free, tamper-free
systems. Authentication techniques are based on public-key encryption.
• Architecture-neutral − Java compiler generates an architecture-neutral object file
format, which makes the compiled code executable on many processors, with the
presence of Java runtime system.
• Portable − Being architecture-neutral and having no implementation dependent
aspects of the specification makes Java portable. Compiler in Java is written in
ANSI C with a clean portability boundary, which is a POSIX subset.
• Robust − Java makes an effort to eliminate error prone situations by emphasizing
mainly on compile time error checking and runtime checking.
• High Performance − With the use of Just-In-Time compilers, Java enables high
performance.
• Distributed − Java is designed for the distributed environment of the internet.
• Dynamic − Java is considered to be more dynamic than C or C++ since it is
designed to adapt to an evolving environment. Java programs can carry extensive
amount of run-time information that can be used to verify and resolve accesses to
objects on run-time

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
Bytecode, JAVA VIRTUAL MACHINE (JVM), Bytecode, JIT, JRE and JDK
• Bytecode
 The key advantages of Java programming language is that the
compiled code of java is not machine specific instructions but
rather an intermediate code called as ByteCode.
 Bytecode is the code generated after the Java programs
are compiled. This is the intermediate representations of
Java programs. Bytecode is NOT executable code like “.exe”
but this is java propriety intermediate code. Bytecode is
NOT machine understandable language.
 Bytecode is a highly optimized set of instructions designed to be
executed by the Java run-time system (interpreter) which is
called the Java Virtual Machine (JVM). This provides greater
level of flexibility for the developers to implement the logic
specific to JVM rather to any platform or device.
 Job of JVM is to read this bytecode and convert into machine dependent
instructions. So, JVM’s needs to be platform specific but not the developers code.
JVM is an interpreter for Bytecode

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Bytecode
 So, for any system to support java programs it is mandatory that JVM needs to be
pre-installed on that machine.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Java Virtual Machine (JVM) Definition:
 The Java Virtual Machine (JVM) is an abstract computer, on which the byte code
can be executed. Java Virtual Machine (JVM) interprets the byte code into the
machine code depending upon the underlying operating system and hardware
combination.
 JVM does not know anything about Java program rather it reads the bytecode,
interprets the code and executes the code.

OS + Hardware(intel)

 JVM is platform dependent that means there are different implementation of JVM
on different OS.
 Java code / Bytecode is always the same on different OS. That makes java program
as platform independent.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Just In Time (JIT):
 Just in time (JIT) is a part of Java Virtual Machine (JVM) architecture. The job of JIT
inside JVM is to compile bytecode into machine executable code in real time, on a
piece-by-piece, demand basis.
 When Java programs are executed, JVM does not read the entire Bytecode and
converts it into machine instructions. If JVM tries to do this approach then the
program execution time will be delayed for hours. Java has overcome the latency
of program execution time by interpreting the required bytecode and keep the
rest of the code aside.
 Just in time (JIT) helps to compile code that is only needed and at the same time
boost the program performance. Wheather the Java programs are interpreted
traditional way or on the fly the functionality and features like portability and
security remains the same.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Java Runtime Environment (JRE):
 As we discussed above, Java programs cannot be executed on machine without
the JVM installed on machine. Java Runtime Environment (JRE) is a software
which we can download and install on the any operating system like Windows,
Mac or Linux.
 JRE is combination of JVM and Java Application Programming Interface (Java API).
Java API are set of tools and libraries that is required by the JVM to execute the
java programs. Thus, Java Runtime Environment provides an environment to
execute java programs on the computer.
 JRE = JVM + Java API’s (like util, math, lang, awt, swing etc) + Runtime libraries.

 JRE does NOT contain any development


tools such as compiler, debugger, etc. and
it is NOT for development purpose.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Java Development Kit (JDK):
 Java Development Kit (JDK) is a set of development tools installed on the local machine
to write and compile Java programs.
 JDK = JRE + Java Development Tools + Libraries
• Java Library
– Static - Functions that are required at compile time.
– Dynamic - Functions that are required at runtime and not at compile time

 JDK tools divided in 5 categories


 Basic Tools
 Remote Method Invocation (RMI) Tools
 Internationalization Tools
 Security Tools
 Java IDL Tools
• Basic JDK Tools
• These tools are the foundation of the Java Development Kit.
 javac
javac is the compiler for the Java programming language; it's used to compile .java file. It
creates a class file which can be run by using java command.
Example:
c:javac TestFile.java

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Basic JDK Tools
 java
When a class file has been created, the java command can be used to run the Java
program.
Example:
c:java TestFile.class
 javadoc
JavaDoc is an API documentation generator for the Java language, which generates
documentation in HTML format from Java source code.
 appletviewer
appletviewer run and debug applets without a web browser, its standalone
command-line program to run Java applets.
 jar
The jar is (manage Java archive) a package file format that contains class, text, images
and sound files for a Java application or applet gathered into a single compressed file.

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Summarize:
 Java programs are written in “.java” file.
 Bytecode: Bytecode is the code generated after the java program is compiled.
 Java Virtual Machine (JVM): This is virtual machine which reads the bytecode and
interprets into machine code depending upon the underlying operating system
and hardware combination.
 Just In Time (JIT): Just in time compiler is part of the Java Virtual Machine (JVM)
and it compiles bytecode into executable code in real time, on a piece-by-piece,
demand basis.
 Java Runtime Environment (JRE): Java Runtime Environment provides an
environment to execute java programs on the computer.
 Java Development Kit (JDK): Java development Kit is the development tools and
libraries that are required to develop java programs.
 Java Compiler: This is the compiler tool that compiles and convert the “.java” code
into “.class” bytecode.
 Java Interpreter: The job of interpreter is to read the bytecode and convert into
machine dependent instructions to execute

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724


Introduction to JAVA
• Java local environment setup:

10/22/2019 Thobius Joseph(Msc in Eng.), 0783758724

You might also like