SlideShare a Scribd company logo
6
Most read
1. THE JAVA PROGRAMMING LANGUAGE
What is Java?
Java programming language is a high-level language that can be characterized by all of the
following buzzwords:
• Compiled and Interpreted

• Architecture neutral

• Distributed

• Object oriented

• Robust

• Secure

• Multithreaded

• Dynamic

• Extensible

• High performance

• Easy to learn

Java features elaborated:
1. Compiled and Interpreted
Usually a computer language is either compiled or interpreted. Java combines both these
features and thus there are two stages involved in a Java program. First, Java translates
the source code into bytecode instructions. Bytecodes are not machine instructions. So in
the next stage, the Java interpreter generates the machine code that can be directly
executed by the machine that is running the Java program. This interpretation is done by
the Java virtual machine.
2. Platform-independent and portable
Java programs can be easily moved from one computer system to another. If there are any
changes in the OS, processor, and other system resources, there is no need to change the
Java program. This portability is achieved in two ways: first Java generates the bytecode
instructions that can be run on any machine. Also, the size of the primitive data types are
machine independent. This portability is the reason behind the huge success of Java in the
networking domain, especially the Internet. We can download an applet from a remote
computer to our computer system and execute it locally.
3. Distributed
Java was designed with networking in mind. Java programs can share data across
networks. Java programs can open and access objects on network devices.
4. Object-oriented
Java is object oriented. No coding is permitted outside class definitions. An extensive
class library can be used by the programmer
5. Robust
Java is a robust language. All local variables must be initialized. There is strong typechecking. That is, all data must be declared explicitly. It has garbage-collection features
which means that memory management is no longer something the programmer needs to
Java - Chapter 1

Page 1 of 6
The Java Programming Language

be worried about. Java also does exception handling – serious errors are captured and the
risk of crashing the system is minimized.
6. Secure
Since Java has been designed for networked environments, security is an important
feature of this language. Java systems verify all memory accesses. The absence of
pointers in Java ensures that programs do not have access to all memory locations.
7. Multithreaded
Multithreading means handling many (multiple) tasks simultaneously. Java handles
multithreaded programs. It means that we need not wait for one task to be completed
before starting the next task. Such systems are very useful for graphical interactive
environments.
8. Dynamic and extensible
The linking of data and methods to where they are located, is done at run-time. New
classes can be loaded while a program is running. Linking is done on the fly. Even if
libraries are recompiled, there is no need to recompile code that uses classes in those
libraries. This differs from C++, which uses static binding.
By extensible we mean that Java programs can support functions written in other
languages such as C or C++. These functions are called native methods. Such functions
are linked dynamically at runtime.
9. High performance
Even though Java is interpreted (in the second stage), its speed is impressive compared to
other interpreted languages. This is due to the use of the intermediate bytecode. Also, the
multithreading feature further increases the speed of execution of Java programs.
10. Simple to learn
Java is a simple and small language. Many features of C / C++ have been removed from
Java. For example, pointers, preprocessor header files (e.g., #include <stdio.h>), goto
statement, operator overloading, multiple inheritance, etc have been eliminated from Java.

Differences between Java and C:
Although Java syntax is in many ways including operators and statements, there are many
significant differences in these languages.
No preprocessor
Java does not include a preprocessor(C and C++ both have the #include
preprocessor directive). Also #define, #ifdef are missing from Java.
No macro definitions
Java does not support macros (#define in C).
Page 2 of 6

Java - Chapter 1
The Java Programming Language

No global variables
There are no global variables in Java. Packages contain classes, classes contain fields
and methods, and methods contain local variables.
Well-defined primitive data types
All primitive data types in Java have well-defined sizes. In C, the size of short,
int, and long data types is platform-dependent. This hampers portability.
No pointers
Java does not support the concept of pointers. There is no address-of operator like &,
dereference operator like * or −>, or sizeof operator. Pointers are a source of bugs.
No goto statement
Java doesn't support a goto statement. Use of goto is regarded as poor
programming practice. Java adds labeled break and continue statements to the
flow-control statements offered by C. These are a good substitute for goto.
Garbage collection
The Java Virtual Machine performs garbage collection so that Java programmers do
not have to explicitly manage the memory used by all objects and arrays. This feature
eliminates another entire category of common bugs. It also eliminates memory leaks
from Java programs.
Variable declarations anywhere
C requires local variable declarations to be made at the beginning of a method or
block, while Java allows them anywhere in a method or block.
Forward Reference
In C, functions must be declared in a header file before defining them. The Java
compiler allows methods (functions) to be invoked before they are defined.
Miscellaneous Features
Java does not support the following features of C: typedef, variable-length argument
lists (e.g., used in printf () statement ), bitfields, enumerated types, structure and union
types.

Java Environment
.

In Java programming language, all source code is first written in plain text files ending with
the .java extension. Those source files are then compiled into .class files by the javac
compiler. A .class file does not contain code that is native to your processor; it instead
Prof. Mukesh N Tekwani

Page 3 of 6
The Java Programming Language

contains bytecodes — the machine language of the Java Virtual Machine (Java VM). The
java launcher tool then runs your application with an instance of the Java Virtual Machine.
Because the Java VM is available on many different operating systems, the same .class files
are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS),
Linux, or Mac OS.

Java environment includes many tools and classes. The development tools are part the Java
Development Kit (JDK) and the classes and methods are part of the Java Standard Library
(JSL).

Java Development Kit
The JDK includes:
javac –

Java compiler which translates the Java source code into bytecode.

java

–

Java interpreter which runs applications by reading the bytecode files.

jdb

–

Java debugger, which helps in debugging Java code

javap –

Java disassembler, which converts bytecode files into a program description

appletviewer – for viewing Java applets without using a Java-enabled browser

The Java Platform
A platform is the hardware or software environment in which a program runs. Some of the
most popular platforms are Microsoft Windows, Linux, Solaris OS, and Mac OS. Most
platforms can be described as a combination of the operating system and underlying
Page 4 of 6

Java - Chapter 1
The Java Programming Language

hardware. The Java platform differs from most other platforms in that it's a software-only
platform that runs on top of other hardware-based platforms.
The Java platform has two components:
•
•

The Java Virtual Machine
The Java Application Programming Interface (API)

Java Virtual Machine:
Java Virtual Machine is the base for the Java platform and is ported onto various hardwarebased platforms. A Virtual Machine is a software that that creates a virtualized environment
between the computer platform so that the end-user can operate software. Computer platform
includes computer’s hardware, operating system, and programming languages.
The Java Virtual Machine (JVM) is key to the independence of the underlying operating
system and hardware - it is a platform that hides the underlying operating system from Javapowered applets and applications.
1. The Java Virtual Machine, or JVM, is an abstract computer that runs compiled Java
programs.
2. The JVM is "virtual" because it is generally implemented in software on top of a
"real" hardware platform and operating system.
3. All Java programs are compiled for the JVM. Therefore, the JVM must be
implemented on a particular platform before compiled Java programs will run on that
platform.
Compiled Java Programs
Java Virtual Machine
Hardware Platform and Operating System
4. Virtual Machine defines a machine-independent format for binary files called the
class (.class) file format. This format includes instructions for a virtual computer in
the form of bytecodes.

The API
The API is a large collection of ready-made software components that provide many useful
capabilities. It is grouped into libraries of related classes and interfaces; these libraries are
known as packages. The API and Java Virtual Machine insulate the program from the
underlying hardware.

Prof. Mukesh N Tekwani

Page 5 of 6
The Java Programming Language

Advantages of Java
1.
2.
3.
4.
5.
6.

Easy to learn especially for those familiar with C or C++
Programs written in Java are usually smaller than in other languages.
Automatic garbage collection – avoids memory leaks.
Program development time is less in Java.
Platform dependencies can be avoided.
Applications written in Java are complied into machine-independent bytecode, and so
they run consistently on any Java platform.

QUESTIONS
1. Why is Java known as platform-independent language?
2. Explain the term bytecode. Why is Java said to be compiled as well as interpreted?
3. In what way is Java a robust language?
4. Which features of C language are missing from Java? Give at least 5 features.
5. List the components of the JDK. State the function of each of these components.
6. Java is multithreaded, dynamic and extensible. What does this mean for the programmer?
7. In the context of programming languages, define the term “platform”. Elaborate on the
two components of Java platform.

Page 6 of 6

Java - Chapter 1

More Related Content

What's hot (20)

PPTX
Procedural programming
Ankit92Chitnavis
 
PPT
Shell programming
Moayad Moawiah
 
PPTX
And or graph
Ali A Jalil
 
PPTX
Loops Basics
Mushiii
 
PPTX
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
PPTX
Use case diagram
City University
 
PPTX
Cohesion and coupling
Aprajita (Abbey) Singh
 
PPTX
Demand paging
Trinity Dwarka
 
PPT
File handling in c
David Livingston J
 
PPT
Shell and its types in LINUX
SHUBHA CHATURVEDI
 
PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
PPTX
CPU scheduling algorithms in OS
harini0810
 
PPTX
Python Exception Handling
Megha V
 
PPTX
Bash shell scripting
VIKAS TIWARI
 
PPTX
Shell scripting
simha.dev.lin
 
PPTX
I/O Management
Keyur Vadodariya
 
PPTX
Abstract class in c++
Sujan Mia
 
PPTX
Realibity design
Abhishek Tiwari
 
PPT
deadlock avoidance
wahab13
 
Procedural programming
Ankit92Chitnavis
 
Shell programming
Moayad Moawiah
 
And or graph
Ali A Jalil
 
Loops Basics
Mushiii
 
Introduction to Dynamic Programming, Principle of Optimality
Bhavin Darji
 
Use case diagram
City University
 
Cohesion and coupling
Aprajita (Abbey) Singh
 
Demand paging
Trinity Dwarka
 
File handling in c
David Livingston J
 
Shell and its types in LINUX
SHUBHA CHATURVEDI
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
CPU scheduling algorithms in OS
harini0810
 
Python Exception Handling
Megha V
 
Bash shell scripting
VIKAS TIWARI
 
Shell scripting
simha.dev.lin
 
I/O Management
Keyur Vadodariya
 
Abstract class in c++
Sujan Mia
 
Realibity design
Abhishek Tiwari
 
deadlock avoidance
wahab13
 

Viewers also liked (19)

PDF
Html tables examples
Mukesh Tekwani
 
PDF
Python reading and writing files
Mukesh Tekwani
 
PDF
Jdbc 1
Mukesh Tekwani
 
PDF
Java chapter 3
Mukesh Tekwani
 
PDF
Java chapter 5
Mukesh Tekwani
 
PDF
Digital signal and image processing FAQ
Mukesh Tekwani
 
PDF
Java misc1
Mukesh Tekwani
 
PDF
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
PDF
Java 1-contd
Mukesh Tekwani
 
PDF
Java swing 1
Mukesh Tekwani
 
PDF
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
PDF
Java chapter 3 - OOPs concepts
Mukesh Tekwani
 
DOCX
Python - Regular Expressions
Mukesh Tekwani
 
PDF
Html graphics
Mukesh Tekwani
 
PDF
Data Link Layer
Mukesh Tekwani
 
PDF
Data communications ch 1
Mukesh Tekwani
 
PDF
Chap 3 data and signals
Mukesh Tekwani
 
PPT
Chapter 26 - Remote Logging, Electronic Mail & File Transfer
Wayne Jones Jnr
 
PDF
Introduction to systems programming
Mukesh Tekwani
 
Html tables examples
Mukesh Tekwani
 
Python reading and writing files
Mukesh Tekwani
 
Java chapter 3
Mukesh Tekwani
 
Java chapter 5
Mukesh Tekwani
 
Digital signal and image processing FAQ
Mukesh Tekwani
 
Java misc1
Mukesh Tekwani
 
Phases of the Compiler - Systems Programming
Mukesh Tekwani
 
Java 1-contd
Mukesh Tekwani
 
Java swing 1
Mukesh Tekwani
 
Java chapter 6 - Arrays -syntax and use
Mukesh Tekwani
 
Java chapter 3 - OOPs concepts
Mukesh Tekwani
 
Python - Regular Expressions
Mukesh Tekwani
 
Html graphics
Mukesh Tekwani
 
Data Link Layer
Mukesh Tekwani
 
Data communications ch 1
Mukesh Tekwani
 
Chap 3 data and signals
Mukesh Tekwani
 
Chapter 26 - Remote Logging, Electronic Mail & File Transfer
Wayne Jones Jnr
 
Introduction to systems programming
Mukesh Tekwani
 
Ad

Similar to Java chapter 1 (20)

PPTX
Java ms harsha
Harsha Batra
 
PPTX
Unit1 introduction to Java
DevaKumari Vijay
 
PPTX
Unit1 JAVA.pptx
RahulAnand111531
 
PDF
OOPS JAVA.pdf
DeepanshuMidha5140
 
PPTX
JAVA ALL 5 MODULE NOTES.pptx
DrPreethiD1
 
PPTX
2 22CA026_Advance Java Programming_Data types and Operators.pptx
dolphiverma80
 
PPT
Java features
Madishetty Prathibha
 
PDF
Top 10 Important Core Java Interview questions and answers.pdf
Umesh Kumar
 
PPTX
JAVA PROGRAMMING-Unit I - Final PPT.pptx
SuganthiDPSGRKCW
 
PDF
0f0cef_1dac552af56c4338ab0672859199e693.pdf
DeepakChaudhriAmbali
 
DOCX
Notes of java first unit
gowher172236
 
PPTX
Java Lecture 1
Qualys
 
PDF
Sybsc cs sem 3 core java
WE-IT TUTORIALS
 
PPTX
Iintroduction to java , Java Coding , basics of java.pptx
MayankParashar31
 
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
PDF
Java unit 1
Shipra Swati
 
DOCX
java introduction.docx
vikasbagra9887
 
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Java ms harsha
Harsha Batra
 
Unit1 introduction to Java
DevaKumari Vijay
 
Unit1 JAVA.pptx
RahulAnand111531
 
OOPS JAVA.pdf
DeepanshuMidha5140
 
JAVA ALL 5 MODULE NOTES.pptx
DrPreethiD1
 
2 22CA026_Advance Java Programming_Data types and Operators.pptx
dolphiverma80
 
Java features
Madishetty Prathibha
 
Top 10 Important Core Java Interview questions and answers.pdf
Umesh Kumar
 
JAVA PROGRAMMING-Unit I - Final PPT.pptx
SuganthiDPSGRKCW
 
0f0cef_1dac552af56c4338ab0672859199e693.pdf
DeepakChaudhriAmbali
 
Notes of java first unit
gowher172236
 
Java Lecture 1
Qualys
 
Sybsc cs sem 3 core java
WE-IT TUTORIALS
 
Iintroduction to java , Java Coding , basics of java.pptx
MayankParashar31
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Java unit 1
Shipra Swati
 
java introduction.docx
vikasbagra9887
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Nithin Kumar,VVCE, Mysuru
 
Ad

More from Mukesh Tekwani (20)

PDF
The Elphinstonian 1988-College Building Centenary Number (2).pdf
Mukesh Tekwani
 
PPSX
Circular motion
Mukesh Tekwani
 
PPSX
Gravitation
Mukesh Tekwani
 
PDF
ISCE-Class 12-Question Bank - Electrostatics - Physics
Mukesh Tekwani
 
PPTX
Hexadecimal to binary conversion
Mukesh Tekwani
 
PPTX
Hexadecimal to decimal conversion
Mukesh Tekwani
 
PPTX
Hexadecimal to octal conversion
Mukesh Tekwani
 
PPTX
Gray code to binary conversion
Mukesh Tekwani
 
PPTX
What is Gray Code?
Mukesh Tekwani
 
PPSX
Decimal to Binary conversion
Mukesh Tekwani
 
PDF
Video Lectures for IGCSE Physics 2020-21
Mukesh Tekwani
 
PDF
Refraction and dispersion of light through a prism
Mukesh Tekwani
 
PDF
Refraction of light at a plane surface
Mukesh Tekwani
 
PDF
Spherical mirrors
Mukesh Tekwani
 
PDF
Atom, origin of spectra Bohr's theory of hydrogen atom
Mukesh Tekwani
 
PDF
Refraction of light at spherical surfaces of lenses
Mukesh Tekwani
 
PDF
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
Mukesh Tekwani
 
PPSX
Cyber Laws
Mukesh Tekwani
 
PPSX
Social media
Mukesh Tekwani
 
The Elphinstonian 1988-College Building Centenary Number (2).pdf
Mukesh Tekwani
 
Circular motion
Mukesh Tekwani
 
Gravitation
Mukesh Tekwani
 
ISCE-Class 12-Question Bank - Electrostatics - Physics
Mukesh Tekwani
 
Hexadecimal to binary conversion
Mukesh Tekwani
 
Hexadecimal to decimal conversion
Mukesh Tekwani
 
Hexadecimal to octal conversion
Mukesh Tekwani
 
Gray code to binary conversion
Mukesh Tekwani
 
What is Gray Code?
Mukesh Tekwani
 
Decimal to Binary conversion
Mukesh Tekwani
 
Video Lectures for IGCSE Physics 2020-21
Mukesh Tekwani
 
Refraction and dispersion of light through a prism
Mukesh Tekwani
 
Refraction of light at a plane surface
Mukesh Tekwani
 
Spherical mirrors
Mukesh Tekwani
 
Atom, origin of spectra Bohr's theory of hydrogen atom
Mukesh Tekwani
 
Refraction of light at spherical surfaces of lenses
Mukesh Tekwani
 
ISCE (XII) - PHYSICS BOARD EXAM FEB 2020 - WEIGHTAGE
Mukesh Tekwani
 
Cyber Laws
Mukesh Tekwani
 
Social media
Mukesh Tekwani
 

Recently uploaded (20)

PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
PPTX
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PPTX
Controller Request and Response in Odoo18
Celine George
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PDF
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
PPTX
Difference between write and update in odoo 18
Celine George
 
PDF
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PPTX
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
PPTX
Introduction to Indian Writing in English
Trushali Dodiya
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
EDUCATIONAL MEDIA/ TEACHING AUDIO VISUAL AIDS
Sonali Gupta
 
How to Create a Customer From Website in Odoo 18.pptx
Celine George
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
Week 2 - Irish Natural Heritage Powerpoint.pdf
swainealan
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Controller Request and Response in Odoo18
Celine George
 
Horarios de distribución de agua en julio
pegazohn1978
 
AI-Powered-Visual-Storytelling-for-Nonprofits.pdf
TechSoup
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Difference between write and update in odoo 18
Celine George
 
Is Assignment Help Legal in Australia_.pdf
thomas19williams83
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
Introduction presentation of the patentbutler tool
MIPLM
 
PPT-Q1-WEEK-3-SCIENCE-ERevised Matatag Grade 3.pptx
reijhongidayawan02
 
Introduction to Indian Writing in English
Trushali Dodiya
 

Java chapter 1

  • 1. 1. THE JAVA PROGRAMMING LANGUAGE What is Java? Java programming language is a high-level language that can be characterized by all of the following buzzwords: • Compiled and Interpreted • Architecture neutral • Distributed • Object oriented • Robust • Secure • Multithreaded • Dynamic • Extensible • High performance • Easy to learn Java features elaborated: 1. Compiled and Interpreted Usually a computer language is either compiled or interpreted. Java combines both these features and thus there are two stages involved in a Java program. First, Java translates the source code into bytecode instructions. Bytecodes are not machine instructions. So in the next stage, the Java interpreter generates the machine code that can be directly executed by the machine that is running the Java program. This interpretation is done by the Java virtual machine. 2. Platform-independent and portable Java programs can be easily moved from one computer system to another. If there are any changes in the OS, processor, and other system resources, there is no need to change the Java program. This portability is achieved in two ways: first Java generates the bytecode instructions that can be run on any machine. Also, the size of the primitive data types are machine independent. This portability is the reason behind the huge success of Java in the networking domain, especially the Internet. We can download an applet from a remote computer to our computer system and execute it locally. 3. Distributed Java was designed with networking in mind. Java programs can share data across networks. Java programs can open and access objects on network devices. 4. Object-oriented Java is object oriented. No coding is permitted outside class definitions. An extensive class library can be used by the programmer 5. Robust Java is a robust language. All local variables must be initialized. There is strong typechecking. That is, all data must be declared explicitly. It has garbage-collection features which means that memory management is no longer something the programmer needs to Java - Chapter 1 Page 1 of 6
  • 2. The Java Programming Language be worried about. Java also does exception handling – serious errors are captured and the risk of crashing the system is minimized. 6. Secure Since Java has been designed for networked environments, security is an important feature of this language. Java systems verify all memory accesses. The absence of pointers in Java ensures that programs do not have access to all memory locations. 7. Multithreaded Multithreading means handling many (multiple) tasks simultaneously. Java handles multithreaded programs. It means that we need not wait for one task to be completed before starting the next task. Such systems are very useful for graphical interactive environments. 8. Dynamic and extensible The linking of data and methods to where they are located, is done at run-time. New classes can be loaded while a program is running. Linking is done on the fly. Even if libraries are recompiled, there is no need to recompile code that uses classes in those libraries. This differs from C++, which uses static binding. By extensible we mean that Java programs can support functions written in other languages such as C or C++. These functions are called native methods. Such functions are linked dynamically at runtime. 9. High performance Even though Java is interpreted (in the second stage), its speed is impressive compared to other interpreted languages. This is due to the use of the intermediate bytecode. Also, the multithreading feature further increases the speed of execution of Java programs. 10. Simple to learn Java is a simple and small language. Many features of C / C++ have been removed from Java. For example, pointers, preprocessor header files (e.g., #include <stdio.h>), goto statement, operator overloading, multiple inheritance, etc have been eliminated from Java. Differences between Java and C: Although Java syntax is in many ways including operators and statements, there are many significant differences in these languages. No preprocessor Java does not include a preprocessor(C and C++ both have the #include preprocessor directive). Also #define, #ifdef are missing from Java. No macro definitions Java does not support macros (#define in C). Page 2 of 6 Java - Chapter 1
  • 3. The Java Programming Language No global variables There are no global variables in Java. Packages contain classes, classes contain fields and methods, and methods contain local variables. Well-defined primitive data types All primitive data types in Java have well-defined sizes. In C, the size of short, int, and long data types is platform-dependent. This hampers portability. No pointers Java does not support the concept of pointers. There is no address-of operator like &, dereference operator like * or −>, or sizeof operator. Pointers are a source of bugs. No goto statement Java doesn't support a goto statement. Use of goto is regarded as poor programming practice. Java adds labeled break and continue statements to the flow-control statements offered by C. These are a good substitute for goto. Garbage collection The Java Virtual Machine performs garbage collection so that Java programmers do not have to explicitly manage the memory used by all objects and arrays. This feature eliminates another entire category of common bugs. It also eliminates memory leaks from Java programs. Variable declarations anywhere C requires local variable declarations to be made at the beginning of a method or block, while Java allows them anywhere in a method or block. Forward Reference In C, functions must be declared in a header file before defining them. The Java compiler allows methods (functions) to be invoked before they are defined. Miscellaneous Features Java does not support the following features of C: typedef, variable-length argument lists (e.g., used in printf () statement ), bitfields, enumerated types, structure and union types. Java Environment . In Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class files by the javac compiler. A .class file does not contain code that is native to your processor; it instead Prof. Mukesh N Tekwani Page 3 of 6
  • 4. The Java Programming Language contains bytecodes — the machine language of the Java Virtual Machine (Java VM). The java launcher tool then runs your application with an instance of the Java Virtual Machine. Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows, the Solaris TM Operating System (Solaris OS), Linux, or Mac OS. Java environment includes many tools and classes. The development tools are part the Java Development Kit (JDK) and the classes and methods are part of the Java Standard Library (JSL). Java Development Kit The JDK includes: javac – Java compiler which translates the Java source code into bytecode. java – Java interpreter which runs applications by reading the bytecode files. jdb – Java debugger, which helps in debugging Java code javap – Java disassembler, which converts bytecode files into a program description appletviewer – for viewing Java applets without using a Java-enabled browser The Java Platform A platform is the hardware or software environment in which a program runs. Some of the most popular platforms are Microsoft Windows, Linux, Solaris OS, and Mac OS. Most platforms can be described as a combination of the operating system and underlying Page 4 of 6 Java - Chapter 1
  • 5. The Java Programming Language hardware. The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms. The Java platform has two components: • • The Java Virtual Machine The Java Application Programming Interface (API) Java Virtual Machine: Java Virtual Machine is the base for the Java platform and is ported onto various hardwarebased platforms. A Virtual Machine is a software that that creates a virtualized environment between the computer platform so that the end-user can operate software. Computer platform includes computer’s hardware, operating system, and programming languages. The Java Virtual Machine (JVM) is key to the independence of the underlying operating system and hardware - it is a platform that hides the underlying operating system from Javapowered applets and applications. 1. The Java Virtual Machine, or JVM, is an abstract computer that runs compiled Java programs. 2. The JVM is "virtual" because it is generally implemented in software on top of a "real" hardware platform and operating system. 3. All Java programs are compiled for the JVM. Therefore, the JVM must be implemented on a particular platform before compiled Java programs will run on that platform. Compiled Java Programs Java Virtual Machine Hardware Platform and Operating System 4. Virtual Machine defines a machine-independent format for binary files called the class (.class) file format. This format includes instructions for a virtual computer in the form of bytecodes. The API The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages. The API and Java Virtual Machine insulate the program from the underlying hardware. Prof. Mukesh N Tekwani Page 5 of 6
  • 6. The Java Programming Language Advantages of Java 1. 2. 3. 4. 5. 6. Easy to learn especially for those familiar with C or C++ Programs written in Java are usually smaller than in other languages. Automatic garbage collection – avoids memory leaks. Program development time is less in Java. Platform dependencies can be avoided. Applications written in Java are complied into machine-independent bytecode, and so they run consistently on any Java platform. QUESTIONS 1. Why is Java known as platform-independent language? 2. Explain the term bytecode. Why is Java said to be compiled as well as interpreted? 3. In what way is Java a robust language? 4. Which features of C language are missing from Java? Give at least 5 features. 5. List the components of the JDK. State the function of each of these components. 6. Java is multithreaded, dynamic and extensible. What does this mean for the programmer? 7. In the context of programming languages, define the term “platform”. Elaborate on the two components of Java platform. Page 6 of 6 Java - Chapter 1