Chapter 1 - Unit 5a

Introduction to Java

Class 10 - APC Understanding Computer Applications with BlueJ


Tick the correct answer

Question 1

A Java program developed and executed by the users without using web browser is known as:

  1. application ✓
  2. applet
  3. object
  4. none

Question 2

Who developed Java?

  1. James Gosling ✓
  2. Robert James
  3. Bjarne Stroustrup
  4. None

Question 3

Java Virtual Machine (JVM) is an:

  1. interpreter ✓
  2. compiler
  3. machine code
  4. byte code

Question 4

Java is a case sensitive language. Which is the most appropriate statement with respect to this context?

  1. Upper and lower case letters are distinguished. ✓
  2. Upper and lower case letters are ignored.
  3. Only lower case letters are distinguished.
  4. None.

Question 5

Which of the following package is needed to find the square root of a number?

  1. java.text
  2. java.math
  3. java.lang ✓
  4. None

Clarification: Math class inside java.lang package contains mathematical function. It should not be confused with java.math package which contains BigDecimal, BigInteger and MathContext classes.

Question 6

Which of the following is not a Java reserved word?

  1. private
  2. public
  3. break
  4. total ✓

Question 7

The most suitable statement for BlueJ is:

  1. It is a window based platform.
  2. It is a DOS based platform.
  3. It is a window based and DOS based platform. ✓
  4. None.

Fill in the blanks

Question 1

The initial name of Java was Oak.

Question 2

Compiler converts source code to byte code.

Question 3

JVM is used to convert Byte Code into machine code.

Question 4

Java is platform independent language.

Question 5

Windows based Java platform is known as BlueJ.

Question 6

Reserved words are also called keywords.

Question 7

java.lang package is used for mathematical functions in Java.

Clarification: Math class inside java.lang package contains mathematical functions. It should not be confused with java.math package which contains BigDecimal, BigInteger and MathContext classes.

Predict the output of the following snippets

Question 1

System.out.println("My name is ");
System.out.print("Kunal Kishore");
System.out.println("I am a student of Class X");
Output
My name is
Kunal KishoreI am a student of Class X

Question 2

System.out.println("This is my first Java program");
System.out.print("Display the message:");
System.out.print("Have fun!!!");
Output
This is my first Java program
Display the message:Have fun!!!

Question 3

System.out.println("India got independence"); 
System.out.println("on");
System.out.println("15th August,1947");
Output
India got independence
on
15th August,1947

Question 4

System.out.print("The factorial of 5 is");
System.out.println("120");
Output
The factorial of 5 is120

Write short answers

Question 1

Name a Java package which is imported by default.

Answer

java.lang is imported by default in Java.

Question 2

Explain the significance of the following Java library packages.

(a) java.lang

Answer

It provides classes that are fundamental to the design of the Java programming language. Some of the important classes it contains are Object, which is the root of the class hierarchy, Class, instances of which represent classes at run time, Wrapper classes and Math class, which provides commonly used mathematical functions such as sine, cosine, square root, etc.

(b) java.io

Answer

It contains the classes that handle fundamental input and output operations in Java.

(c) java.math

Answer

java.math package provides classes for performing arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision decimal arithmetic (BigDecimal). 

Clarification: Mathematical Library Functions like min(), max(), abs(), avg(), floor(), ceil(), round(), etc. are present in Math class of java.lang package. java.lang.Math class should not be confused with java.math package.

Question 3a

Java interpreter is called Java Virtual machine. Explain.

Answer

Java Virtual Machine takes Bytecode as input and converts it into Machine Code one line at a time. This Bytecode can be generated by compiling source code written in any JVM language like Scala, Kotlin, etc not just Java. Hence, Java interpreter is called Java Virtual Machine.

Question 3b

Name two ways of writing Java programs.

Answer

Two ways of writing Java programs are:

  1. Java Application
  2. Java Applet

Question 4

Define the terms:

(a) Source code

Answer

A set of statements written in a High-Level programming language like Java, C++, Python, etc. is called as Source Code.

(b) Machine code

Answer

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

Answer

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 BlueJ? What are the features of BlueJ?

Answer

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.

Question 6

Write down the syntax of output statement in Java with an example.

Answer

We commonly use two output statements in Java. There syntax are:

  1. System.out.println(<output value>); — This statement prints data on the console. The data to be printed is passed to the println method as a String. After printing the string, it places the cursor at the start of the next line. So the next printing happens at the start of the next line.
  2. System.out.print(<output value>); — This statement also prints data on the console. The data to be printed is passed to the print method as a String. After printing the string, the cursor remains on the same line at the end of the printed string. So the next printing starts in the same line just after the end of the previous printed string.

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");
Output
JVM stands for
Java Virtual Machine

Question 7

What is meant by Java reserved words? Name five Java reserved words which are commonly used in Java programming.

Answer

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

Differentiate between the output statements System.out.println() and System.out.print().

Answer

System.out.println()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.

Question 9

A Java program uses a Compiler as well as an Interpreter. Explain.

Answer

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 10

Write a package that is used for input/output operation in Java

Answer

java.io is used for input/output operation in Java.

No comments:

Post a Comment

any problem in any program comment:-

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...