std 9 unit 2 Introduction to Java
std 9 unit 2 Introduction to Java
Introduction to Java
Question 1
Question 2
Question 3
Question 4
Question 5
Question 1
Question 2
In Java, the package used to find power raised to any base is java.lang.
Clarification: Math class inside java.lang package contains Math.pow that is used to find power
raised to any base. The official documentation is provided here.
It should not be confused with java.math package which contains BigDecimal, BigInteger and
MathContext classes.
Question 3
The words which are preserved with the system are called keywords/reserved words, that can not
be used as variable names in Java programming.
Question 4
Question 5
Question 1
James Gosling developed Java programming language. It was initially called Oak.
Question 2
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”. By 1994 the team
refocussed their efforts towards internet programming with Oak as it didn't find much
traction in consumer electronics space. Oak was renamed to Java and on 23rd of May
1995, Sun microsystems made its first public release.
Question 3
Question 4
(a) A compiler
(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.
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
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. JVM is platform
specific, each platform has its own JVM.
Question 6
1. java.lang
2. java.io
3. java.util
Question 7
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:
1. public
2. class
3. int
4. double
5. char
Question 8
Distinguish between:
Compiler Interpreter
It translates the whole source program into target It translates the source program into target program
program at once. one line at a time.
All the errors found during compilation are Errors are displayed line by line as each line is
displayed together at once. translated and executed.
JDK or Java Development Kit is the set of tools BlueJ is an IDE or Integrated Development
required to compile and run Java programs Environment for developing Java programs.
JDK includes tools like Compiler, Interpreter, Java BlueJ provides tools like Code Editor, Debugger,
libraries, etc. Syntax Highlighting, etc.
Question 9
Question 10
Question 11
What is BlueJ?
BlueJ is an integrated development environment for Java. It was created for teaching
Object Oriented programming to computer science students.
Question 12
Question 13
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 or a boolean or null literal.
Question 15
Java is case sensitive means that it distinguishes between upper case and lower case
characters. Consider the below code snippet:
int studentMarks;
StudentMarks = 85;
This will give a compilation error as Java will treat studentMarks and StudentMarks as
two different variables because the case of the characters is not same in both.
Question 16
void — The void keyword tells the compiler that the main method will not return any
value.
Question 17
Question 18
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 StudentInfo {
public static void main(String args[]) {
System.out.println("Name: Akshay Anand");
System.out.println("Class: 10");
System.out.println("Roll No.: 5");
System.out.println("Subject: Computer Applications");
System.out.println("School: KnowledgeBoat");
}
}
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 {
public static void main(String args[]) {
System.out.println("Name: Shweta Nayak");
System.out.println("Father's Name: Arvind Nayak");
System.out.println("Date of birth: 12/12/2005");
System.out.println("Blood Group: O+");
System.out.println("Aadhar Card No.: 4321 8756 9978");
System.out.println("State: Karnataka");
}
}