Multiple Choice Questions
A Java program developed and executed by the users without using web browser is known as:
Reason — Java application is a Java program that is developed to run on a computer without any help of a web browser.
Who developed Java?
- James Gosling
- Robert James
- Bjarne Stroustrup
Reason — James Gosling developed Java.
Java Virtual Machine (JVM) is an:
- machine code
- byte code
Reason — Java Virtual Machine (JVM) is a Java interpreter.
Java is a case sensitive language. Which is the most appropriate statement with respect to this context?
- Upper and lower case letters are distinguished.
- Upper and lower case letters are ignored.
- Only lower case letters are distinguished.
Upper and lower case letters are distinguished.
Reason — Java is case sensitive, i.e., it can distinguish between uppercase and lowercase letters.
Which of the following package is needed to find the square root of a number?
Reason — Math class inside java.lang package contains mathematical functions. The official documentation is provided here. It should not be confused with java.math package which contains BigDecimal, BigInteger and MathContext classes.
Which of the following is not a Java reserved word?
Reason — total is not a Java reserved word.
The most suitable statement for BlueJ is:
- It is a window based platform.
- It is a DOS based platform.
- It is a window based and DOS based platform.
It is a window based and DOS based platform.
Reason — BlueJ is a window based and DOS based platform.
Fill in the blanks
The initial name of Java was Oak.
Compiler converts source code to byte code.
JVM is used to convert Byte Code into machine code.
Java is platform independent language.
Windows based Java platform is known as BlueJ.
Reserved words are also called keywords.
java.lang package is used for mathematical functions in Java.
Clarification: Math class inside java.lang package contains mathematical functions. The official documentation is provided here. It should not be confused with java.math package which contains BigDecimal, BigInteger and MathContext classes.
Predict the output of the following snippets
System.out.println("My name is "); System.out.print("Kunal Kishore"); System.out.println("I am a student of Class X");
My name is Kunal KishoreI am a student of Class X
System.out.println("This is my first Java program"); System.out.print("Display the message:"); System.out.print("Have fun!!!");
This is my first Java program Display the message:Have fun!!!
System.out.println("India got independence"); System.out.println("on"); System.out.println("15th August,1947");
India got independence on 15th August,1947
System.out.print("The factorial of 5 is"); System.out.println("120");
The factorial of 5 is120
Write short answers
Name a Java package which is imported by default.
java.lang is imported by default in Java.
Explain the significance of the following Java library packages.
(a) java.awt — java.awt package contains classes for supporting abstract window tool kit and managing Graphical User Interface (GUI) components.
(b) java.io — It contains the classes that handle fundamental input and output operations in Java.
(c) java.net — It contains classes for supporting network operations in Java.
Java interpreter is called Java Virtual machine. Explain.
Java interpreter enables a computer to execute a Java program as well as a program written in other language compiled into Java byte code. Hence, java interpreter is called Java Virtual machine.
Name two ways of writing Java programs.
Two ways of writing Java programs are:
- Java Application
- Java Applet
Define the terms:
(a) Source code
(b) Machine code
(c) Byte code
(a) Source code — A set of statements written in a High-Level programming language like Java, C++, Python, etc. is called as Source Code.
(b) Machine code — Machine code is a low-level programming language. Instructions in machine code are written as a sequence of 0s and 1s. It is directly understood and executed by the processor.
(c) Byte code — Java compiler converts Java source code into an intermediate binary code called Byte code. Byte code can't be executed directly on the processor. It needs to be converted into Machine Code first.
What is BlueJ? What are the features of BlueJ?
BlueJ is an integrated development environment for Java. It was created for teaching Object Oriented programming to computer science students. Features of BlueJ include a simple beginner friendly graphical user interface to develop Java programs. It allows creating objects of the class dynamically, invoking their methods and also supplying data to the method arguments if present.
Write down the syntax of output statement in Java with an example.
We commonly use two output statements in Java. Their syntax is as follows:
This statement displays the output of the program on the screen in different lines. The letters 'ln' in the statement act as a line feed which directs the cursor to move to the next line.
This statement is used to display the value enclosed within its braces. It leaves the cursor in the same line on the screen.
As an example, the below statements will generate the following output:
System.out.println("JVM stands for"); System.out.print("Java "); System.out.print("Virtual "); System.out.print("Machine");
JVM stands for Java Virtual Machine
What is meant by Java reserved words? Name five Java reserved words which are commonly used in Java programming.
There are some words that carry special meaning to the system compiler. These words can't be used as variable names in the program. Such words are called Keywords or reserved words.
Five commonly used Java reserved words are:
Differentiate between the output statements System.out.println() and System.out.print().
|It prints data to the console and places the cursor in the next line.||It prints data to the console but the cursor remains at the end of the data in the same line.|
|Next printing takes place from next line.||Next printing takes place from the same line.|
A Java program uses a Compiler as well as an Interpreter. Explain.
Java compiler compiles Java source code to Byte code. Byte code cannot run on the processor directly as processor only understands machine code. Java Virtual Machine (JVM) takes this byte code as input and converts it into machine code line by line. So, JVM acts as an interpreter for converting byte code to machine code. In this way, a Java program uses both a compiler as well as an interpreter to get executed on the processor.
Write a package that is used for input/output operation in Java
java.io package is used for input/output operation in Java.