Introduction to Java lesson 2
PART 1: FILL IN THE BLANK
1. Java applications are stand-alone programs that do not require use of a web browser
2. Web application are used to develop and maintain large complex websites.
3. Bytecode is the intermediate code between source code and machine code.
4. Machine language refers to a set of instruction codes that is understood by a
computer at the lowest hardware level.
5. Java program can be run on any operating system.
6. BlueJ is specifically designed for teaching Java language at introductory level.
PART 2: SHORT ANSWER TYPE QUESTIONS
1. What is Java?
Java is a high-level, object-oriented programming language developed by Sun
Microsystems in 1995. It is platform-independent, secure, and used to create
applications that can run on any device with JVM.
2. What is bytecode in Java programming language?
Bytecode is the intermediate code generated by the Java compiler after compiling the
source code. It is a machine-independent code with `.class` extension that is
understood by the JVM, not directly by the computer.
3. How does bytecode differ from source code?
Source Code
Written by programmer in Java language
Human readable
Platform independent
Cannot be executed directly by computer
Bytecode
Generated by Java compile
Not human readable
Platform independent
Executed by JVM
4. Describe the compiling and execution process of a Java program with example.
Step 1: Compilation – Java source code `[Link]` is compiled using `javac`
compiler. It creates bytecode `[Link]`.
`javac [Link]` → `[Link]`
Step 2: Execution– JVM reads the bytecode and converts it to machine code using
interpreter and runs it.
`java Example` → Output
Example: For a program `[Link]` that prints "Hello", first compile it, then run the
class file.
5. What is JVM? How does it work?
JVM stands for Java Virtual Machine. It is a virtual machine that provides a runtime
environment to execute Java bytecode.
Working: JVM loads the `.class` file, verifies bytecode, and then converts bytecode into
machine code using an interpreter /compiler so the OS can execute it. This makes Java
platform-independent.
6. What do you understand by each of the following:
A. Compiler– A program that translates entire Java source code `.java` into bytecode
`.class` at once. Example: `javac`.
B. JVM – Java Virtual Machine that runs the bytecode and makes Java platform-
independent.
C. JRE – Java Runtime Environment. It includes JVM + libraries needed to _run_ Java
programs.
D. JDK – Java Development Kit. It includes JRE + development tools like compiler,
debugger to _develop_ Java programs.
7. Describe any two features of Java.
1. Platform Independent : Java’s "Write Once, Run Anywhere" feature. Bytecode can run
on any OS having JVM.
2. Object Oriented: Java is based on objects and classes. It supports concepts like
Inheritance, Encapsulation, Polymorphism.
8. Give any four features of BlueJ that allow it to be used for teaching Java.
1. Simple Interface: Easy to use IDE with less complexity for beginners.
2. Object Bench: Allows creating and testing objects interactively without writing a main
method.
3. Class Diagram: Shows visual representation of classes and relationships.
4. Direct Method Calling: You can call methods on objects directly to see results
immediately.