Вы находитесь на странице: 1из 17

1

Subject Code : 4639302


Subject Name : Programming in Java
Unit 1 – Introduction
2

 Java is an object oriented programming language developed


by James Gosling at Sun Microsystems in the early 1990s.
3
Properties/Features of Java

1. Compiled and Interpreted


2. Platform Independent & Portable
3. Object Oriented
4. Robust & Secure
5. Distributed
6. Familiar, Simple & Small
7. High Performance
8. Dynamic & Extensible
9. Multithreaded & Interactive
4

Complied and Interpreted (A two stage system)


All computer languages are either compiled or interpreted. Java
combines both these approaches thus making java a two stage
system.
First java compiler translates source code into byte code instructions.
Byte code are not machine instructions and therefore in the second
stage, java interpreter generates machine code that can be directly
executed by the machine that is running the java program.
Thus java is both compiled and an interpreted language.
5

Platform Independent and Portable


Platform Independent (Machine Independent):
Program exists into two forms: source code and object code. Source
code is the textual version of the program that you write using a
text editor. The executable form of a program is object code.
Object code can be executed by the computer. Typically object is
specific particular to CPU.
Therefore it cannot be executed on a different platform. Java
removes this restriction in a very elegant manner. Like all computer
program java program begins with its source code. But the
difference is what happened when a java program is compiled.
Instead of producing executable code, the java compiler produces
an object file that contains byte code.
6

Byte codes are not for any specific CPU. Instead, they are designed
to be interpreted by a JVM (Java Virtual Machine). Platform
independence comes from the fact that the same byte codes be
executed by any JVM on any platform.

Portability (Write once run any where):


Java programs can be easily moved from one computer system to
other. Changes and upgrades in OS, processor and system resources
will not force any changes in java program. This is the reason why
java has become a popular language for programming on internet,
which interconnects different kinds of systems worldwide. Java
ensures portability in two ways:
7

1. First, java compiler generates byte code instructions that can be


implemented on any machine.
2. Secondly, the size of primitive data types is machine
independent.
8

Object Oriented
Almost everything in java is an object. All program code and data reside
within the objects and classes. Java comes with extensive set of classes,
arranged in packages that we can use in our program by inheritance.
Robust and Secure
Java is robust language. It provides many safeguards to ensure reliable
code. It has strict compile time and run time checking for data types.
Security becomes an important issue for a language that used for
programming on internet. Java systems not only verify all memory access
but also ensure that no viruses are communicated with an applet. The
absence of pointers in java ensures that programs cannot gain access to
memory locations without proper authorization.
9

Distributed
Java is designed as distributed language for creating applications
on network. It has the ability to share both data and programs.
Java applications can open and access remote objects on internet
as easily as they can do with local system. This enables multiple
programmers at multiple remote locations to collaborate and work
together on a single network.
10

Familiar, simple and small


Java is a small and simple language. Many features of C and C++
that are either redundant or sources of unreliable code are not part
of java. For example, java does not use pointers, pre-processor
header files, goto statements and many others. It also eliminates
operator overloading and multiple inheritance.
Familiarity is another feature of java. To make the language look
familiar to the existing programmers, it was modelled in C and C++
languages. Java uses many constructs of C and C++ and therefore,
java code looks like a C++ code. In fact java is a simplified version
of C++.
11

High performance
Java performance is impressive for an interpreted language, mainly due
to the use of intermediate byte code. Java architecture is also designed
to reduce overheads during runtime. Furthermore, the incorporation of
multithreading enhances the overall execution speed of java programs.
Dynamic and extensible
Java is capable of dynamically linking in new class libraries, methods and
objects. Java can also determine the type of class through a query,
making it possible to either dynamically link or abort the program,
depending on the response. Java program supports functions written in
other languages such as C and C++. These functions are called native
methods. Native methods are linked dynamically at runtime.
12

Multithreaded and interactive


Multithreaded means handling simple task simultaneously. Java
supports multithreaded programs. This means we need not wait for
the application to finish one task before beginning of other. For
example, we can be listening an audio clip while scrolling a page
and at the same time download a file from internet. This feature
greatly improves the interactive performance of graphical
applications.
Comparison of java with c++
13

 C++ was designed mainly for systems programming, extending


the C programming language. To this procedural programming
language designed for efficient execution, C++ has added
support for statically typed object oriented programming,
exception handling, resource management and generic
programming in particular.
 Java was created initially to support network computing. It
relies on a virtual machine to be secure and highly portable. It
is bundled with an extensive library designed to provide a
complete abstraction of the underlying platform.
14

 The biggest difference between Java and C++ is that Java


does not support pointers. Pointer is one of the most powerful
features of C++ language. It is also one of its most dangerous
when used improperly. Pointers are inherently insecure because
using pointer it is possible to gain access to memory address
outside a program code and data. Since pointer don’t exist in
Java neither does the operator.
 For passing parameters to functions, C++ supports both pass
by reference and pass by value. In Java, parameters are
always passed by value. Objects are not value in Java.
15

 C++ features programmer-defined operator overloading


which is not supported in Java. The only overloaded operator
in Java are the “+” and “+=” operators, which concatenate
strings as well as performing addition.
 Java offers automatic garbage collection. Memory
management in C++ is usually done through constructors and
destructors.
 C++ supports multiple inheritance. Java does not directly
implement multiple inheritance. However multiple inheritance is
implemented using a secondary inheritance path in the form of
interface.
16

 Like C++ Java supports constructors, but is does not have


destructors. It does however, add the finalize() method.
 Java does not include structure and unions. Java does not
have the delete operator.
 C++ is normally compiled directly to machine code which
is then executed directly by the operating system. Java is
normally compiled to byte code which the Java Virtual
Machine (JVM) then either interprets or JIT compiles to
machine code and then executes.
17

 Java has considerably larger and richer standard library


than C++. The C++ standard library provides components
that are relatively general purpose such as strings,
containers and I/O streams. The Java standard Library
includes components for networking graphical user
interfaces, database access, cryptography and many other
areas.
 Java does not have header files.
 Java does not support global variables. Every variables
and method is declared within a class.

Вам также может понравиться