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

Chapte 1 Exercises Unit II Introduction to JAVA

The document provides an introduction to Java, including true/false questions, fill-in-the-blank exercises, and detailed explanations of Java concepts such as compilers, interpreters, and the Java Virtual Machine (JVM). It also covers the historical development of Java, its features, and the significance of keywords in Java programming. Additionally, the document includes sample Java programs and guidelines for naming classes.

Uploaded by

Agam Stories
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Chapte 1 Exercises Unit II Introduction to JAVA

The document provides an introduction to Java, including true/false questions, fill-in-the-blank exercises, and detailed explanations of Java concepts such as compilers, interpreters, and the Java Virtual Machine (JVM). It also covers the historical development of Java, its features, and the significance of keywords in Java programming. Additionally, the document includes sample Java programs and guidelines for naming classes.

Uploaded by

Agam Stories
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Unit II INTRODUCTION TO JAVA

Write True or False

Question 1
Java application is a Java program which is developed by users.
True

Question 2
James Gosling developed Java programming language.
True
Question 3
Machine codes are expressed using alphanumeric characters.
False

Question 4
Byte code is the program in binary form.
True
Question 5
JVM is Java Visual Management.
False

Page | 1
UMESH COMPUTER KENDRA (PH : 9897188951)
Fill in the blanks with appropriate words

Question 1

Java is a case sensitive language.

Question 2
In Java, the package used to find power raised to any base
is java.lang.

Question 3
The words which are preserved with the system are
called keywords/reserved words, that cannot be used as variable
names in Java programming.

Question 4
A single line comment is represented by the symbol // in Java
programming.

Question 5

BlueJ is a window-based platform to operate Java program.

Answer the following questions

Question 1

Who developed Java? What was it initially called?


James Gosling developed Java programming language. It was
initially called Oak.

Page | 2
UMESH COMPUTER KENDRA (PH : 9897188951)
Question 2
Give a brief historical development of Java.
In 1991, at Sun Microsystems, Green team led by James Gosling
started working on a new technology for consumer electronic
devices. Over the next 18 months, in 1992 the team created a new
programming language which they called “Oak”. Oak was
renamed to Java and on 23rd of May 1995, Sun microsystems
made its first public release.

Question 3

Mention at least four features of Java.


Four features of Java are:

1. It is an Object-Oriented Programming Language.


2. It is platform independent. It provides us Write Once, Run
Anywhere (WORA) feature.
3. It uses a compiler as well as an interpreter.
4. It is case sensitive.

Question 4

Define the following:

(a) A compiler
A compiler is a program that translates a source program written
in some high-level programming language into a target program
in another low-level programming language without changing the
meaning of the program. The compiler processes the complete

Page | 3
UMESH COMPUTER KENDRA (PH : 9897188951)
source program at once and if there are compilation errors, they
are all reported together at once.

(b) An interpreter
An interpreter is a program that reads a source program line by
line, converts each line into its equivalent machine code and
executes it. As it reads the program line by line so the errors are
reported one by one.
(c) Byte code

Java compiler converts Java source code into an intermediate


binary code called Bytecode. Bytecode can't be executed directly
on the processor. It needs to be converted into Machine Code first.

Question 5
What is Java Virtual Machine (JVM)?
Java Virtual Machine (JVM) is a software that takes Bytecode as
input, converts it into Machine code of the specific platform it is
running on and executes it.

Question 6

Name three packages of Java Class Library.


Three packages of Java Class Library are:

1. java.lang
2. java.io
3. java.util

Question 7
Page | 4
UMESH COMPUTER KENDRA (PH : 9897188951)
What are Java reserved words? Name any five.
In Java, a reserved word is a word that has a predefined meaning
in the language. Due to this, reserved words can’t be used as
names for variables, methods, classes or any other identifier.
Reserved words are also known as keywords. Five commonly used
Java reserved words are: public, class, int, double, char

Question 8
Distinguish between:

(a) Source code and Object code

Source code Object code

It is a set of statements in a High- It is a set of statements


Level programming language. in Machine Language.

It is understood by It is understood by the


human/programmer. processor.

(b) Compiler and Interpreter

Compiler Interpreter

It translates the whole source It translates the source program


program into target program at into target program one line at a
once. time.

Page | 5
UMESH COMPUTER KENDRA (PH : 9897188951)
Compiler Interpreter

All the errors found during Errors are displayed line by line
compilation are displayed as each line is translated and
together at once. executed.

(c) JDK 1.3 and BlueJ

JDK 1.3 BlueJ

JDK or Java Development Kit is BlueJ is an IDE or Integrated


the set of tools required to Development Environment for
compile and run Java programs developing Java programs.

JDK includes tools like BlueJ provides tools like Code


Compiler, Interpreter, Java Editor, Debugger, Syntax
libraries, etc. Highlighting, etc.

IDE isn't essential for developing


JDK is essential for developing
Java programs but it makes the
Java programs.
process easier and efficient.

Question 9

A compiler is specific to a language. Give your comments.


A compiler translates a source program written in some high-level
programming language into a target program in another low-level
programming language. As low-level programming languages are
platform specific hence a compiler is specific to a language.
Page | 6
UMESH COMPUTER KENDRA (PH : 9897188951)
Question 10
What is the basic format of a Java Program? Explain with an example.
The basic format of a Java program is entirely different from
other languages. So, it is essential to know the following points
while writing a java program.
1. Declaration of class: To declare a class a keyword ‘class’ is
used along with the meaningful class name.
2. Declaration of main method: The main function encloses the
programming statements within opening and closing curly
braces { }.
3. Termination of each statement must be indicated with a
semi-colon.
4. Closing of curly braces indicates the closing of main function
and class.
class Sample
{
void main()
{
Int n1=10, n2=15, s;
S=n1+n2;
System.out.println(“Sum is “+s);
}
}

Question 11
What is BlueJ?

Page | 7
UMESH COMPUTER KENDRA (PH : 9897188951)
BlueJ is an integrated development environment for Java. It was
created for teaching Object Oriented programming to computer
science students.

Question 12

Mention five features of BlueJ.


Five features of BlueJ are:
1. The compilation and execution of program is comparatively easier.
2. It provides window approach.
3. It provides a sample program in window after making a class.
4. It highlights the error in the lower pane of window.
5. It displays a graphical representation of the class in the program.

Question 13
Name a package that is invoked by default.

java.lang

Question 14
What are the points to be taken care while naming a class in a Java
program?
A class name should be a valid Java identifier i.e. it should follow
the below three rules:

1. Name of the class should be a sequence of alphabets, digits,


underscore and dollar sign characters only.
2. It should not start with a digit.
3. It should not be a keyword.
Page | 8
UMESH COMPUTER KENDRA (PH : 9897188951)
Question 15
Java is a case sensitive. Explain.
Java is case sensitive means that it distinguishes between upper
case and lower-case characters. Consider the below code :
int marks;
Marks = 85;
This will give a compilation error as Java will treat marks and
Marks as two different variables because the case of the
characters is not same in both.

Question 16
The main function in a Java program is declared as:
public static void main (String args[])
What is the significance of the words public, static and void?
public — The public keyword is an access specifier. It controls the
visibility of class members. We can access public class members
outside the class where we declare them.

static — When we declare a method inside a class as static, we can


call it without creating the object of that class. We need to make
the main method static because we will call without creating an
object.
void — The void keyword tells the compiler that the main method
will not return any value.

Question 17

What does the term 'Compilation' mean?

Page | 9
UMESH COMPUTER KENDRA (PH : 9897188951)
The process of converting a source program written in some high-
level programming language into a target program in another low-
level programming language without changing the meaning of the
program is called Compilation.

Question 18
Java program uses compiler as well as interpreter. Explain.
Java compiler, compiles Java source code to Bytecode. Bytecode
cannot run on the processor directly as processor only understands
Machine Code. Java Virtual Machine (JVM) takes this Bytecode as
input and converts it into Machine Code line by line. So, JVM acts
as an interpreter for converting Bytecode to Machine Code. In this
way, a Java program uses both a Compiler as well as an Interpreter
to get executed on the processor.

Question 19
Design a program in Java to display the following information on the
output screen:
Name:
Class:
Roll No.:
Subject:
School:

Answer
class Info
{
public static void main()
{
Page | 10
UMESH COMPUTER KENDRA (PH : 9897188951)
System.out.println("Name: Mudit Garg");
System.out.println("Class: 9");
System.out.println("Roll No.: 5");
System.out.println("Subject: Computer");
System.out.println("School: St. Peter College");
}
}

Question 20
You want to display your bio-data on the output screen. Write a
program in Java to perform the task in the given format:
Name:
Father's Name:
Date of birth:
Blood Group:
Aadhar Card No.:
State:

Answer
class BioData
{
void main()
{
System.out.println("Name: Amit Sharma");
System.out.println("Father's Name:Yash Sharma");
System.out.println("Date of birth: 12/12/2005");
System.out.println("Blood Group: B+");
System.out.println("Aadhar Card No:432187569978");
System.out.println("State: Uttar Pradesh");
}
}

Page | 11
UMESH COMPUTER KENDRA (PH : 9897188951)

You might also like