Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CHAPTER 2

Introduction to Java
Section 3: Assignment Questions

1. Write a short note on types of Java programs.


Ans. There are two types of Java programs:
a. Standalone : Stand alone Java application refers to Java program that can run independently on a computer.
b. Applets : Java applications that run within a web browser.

2. How is Java platform independent?


Ans. Java applications are platform independent, which means that Java applications can run on any platform.
After Java source code is compiled, it is converted into byte code. The byte code is then interrupted by the
JVM. JVM can be installed on several operating systems such as Windows, UNIX, Machintosh, etc .JVM allows
Java programs to run on almost any computer regardless of its hardware configuration. Due to the factor, Java
is considered as a platform independent language.

3. Describe the traditional compilation process with a suitable diagram.


Ans. In traditional compilation process, the machine language version (object code) generated by the
compilation process is specific to the platform one is compiling on, as shown in the figure. For example, if you
were to compile your code on a Windows platform, the resulting program would run only on Windows
platform. To use the same program on any other platform, for example, Macintosh, you need to compile the
original source code with a compiler suitable for Macintosh.

www.bhuvantechs.com

Introduction to Java ~1~


4. Describe Java compilation process with a suitable diagram.
Ans. On compiling the Java source code, you get a bytecode which cannot be directly executed by the
machine. This bytecode needs a Java interpreter to convert it into the machine code of the computer on which
it is to be executed. This interpreter is a part of the Java Virtual Machine or JVM as shown in the figure.

5. How is traditional compilation process different from Java compilation process?


Ans. In the traditional compilation process, an equivalent machine code is generated for that particular
platform however, on compiling the Java source code, you get a bytecode which cannot be directly executed
by the machine. This bytecode needs a Java interpreter to convert it into the machine code of the computer on
which it is to be executed. This interpreter is part of the Java Virtual Machine or JVM.

6. What are JVM and JIT?


Ans. A Java Virtual Machine (JVM) is a virtual machine that enables a computer to run Java program. The JVM
includes a Just-In-Time (JIT) compiler that compiles selected portions of bytecode into executable code.

7. Distinguish between:

a. Source code and Object code


Ans. A set of instructions written in a high-level programming language is called the source code. www.bhuvantechs.com
A compiler generated machine language version of the source code is called the object code.

b. Compiler and Interpreter.


Ans. A compiler is a program that translates the code written in a high-level language into machine code.
An Interpreter translates the source code instructions into machine code one-by-one.

c. “.Java” file and “.class” file.


Ans. The source code is written using the Java language. The files are saved with the “.Java” extension. The
“.Java” files are compiled using the Java compiler. The compilation process generates bytecode files with the
“.class” extension.

Introduction to Java ~2~


8. What is the Java bytecode?
Ans. The programs written in Java are compiled into a machine language for a virtual computer called Java
Virtual Machine (JVM). The machine language for this special Java Virtual Machine is called Java bytecode. The
bytecode files are generated with the “.class” extension.

9. Describe the slogan “Write once, run anywhere” in relation to Java.


Ans. The concept of “Write once, run anywhere”, is one of the most important features of Java, which makes it
a very powerful language. It means you write the source code once and the code can be executed on any
platform that has the JVM installed.

10. Describe four features of Java.


Ans. Following are the features of Java:

Simple – Java is a simple and easy to learn programming language. The removal of many unreliable features of
C and C++ (its predecessors) has simplified its understanding and implementation.

Robust – Java is a robust and reliable programming language. Its powerful compiler checks for early errors
during compilation and the interpreter checks for any runtime errors thus, eliminating situations that are
error-prone.

Secure – Java is secure because it allows Applets to confine to the Java runtime environment only. Applets
cannot access any other part of the computer when downloaded on the web browser. This helps to eliminate
any damage due to malicious software. For example, accessing passwords, or finding your bank details by
searching the contents of your computer.

Object Oriented – Java is a true object-oriented programming language because it treats everything as an
object. This enables us to take full advantage of the object-oriented paradigm and its capabilities of creating
flexible and modular programs.

www.bhuvantechs.com

Introduction to Java ~3~

You might also like