Library Classes

Section A

2006

Question 1
(d) What is a wrapper class? Give an example. [3]

A wrapper class is a class that wraps (cover) a primitive type value in an object. It converts the values in the object (e.g., a String variable) to primitive value (e.g.: int or double etc.). Examples of wrapper classes: Integer, Double etc.

Question 3
(h) What is a package? Give an example. [2]

A group of related classes and interfaces are known as a package. The java.lang is a package.

2007

Question 1
(d) Name the following:-
(i) A package that is invoked by default.
(ii) A keyword, to use the classes defined in a package. [2]

(i) java.lang
(ii) import

2008

Question 2
(d) What is the use of exception handling in Java? [2]

Exception in general means some un-expected situation that causes a run time error. The programmer can write statements to handle (avoid) this situation. Handling of these exceptions are known as exception handling.

Question 3
(h) Write a Java statement to input / read the following from the user using the keyboard.
(i) Character
(ii) String [2]

(i) char c = sc.next().charAt(0);
(ii) String s = sc.nextLine();

2009

Question 1
(a) Write one word answer for the following:
(i) A method that converts a string to a primitive integer data type.
(ii) The default initial value of a boolean variable data type. [2]

(i) Integer.parseInt()
(ii) false

2010

Question 1
(d) What is an Exception? Name two Exception handling blocks. [2]

Exception in general means some unexpected situation that causes a run time error. The way of handling program exceptions is known as exception handling. The try and catch are the two exception handlers.

Question 2
(h) (ii) What is the use of the keyword import? [2]

(ii) The import statement is used to include the predefined classes in a predefined package.

2011

Question 2
(b) (i) Name the package that contains Scanner class.
(ii) Which unit of the class gets called when the object of the class is created. [2]

(i) java.util
(ii) constructor

(d) Write the output of the following:
(i) System.out.println(Character.isUpperCase(‘R’));
(ii) System.out.println(Character.toUpperCase(‘j’)); [2]

(i) true
(ii) J

Question 3
(g) Name the keyword that :
(i) informs that an error has occurred in an input/output operation. [2]

(i) throws

(h) What are library classes? [2]

Library classes are predefined classes in the form of packages to reduce the programming effort of users.
Examples:Math, String etc.

2012

Question 1
(e) Name the type of error (syntax, runtime and logical)
(i) Division by a variable that contains a value of zero
(ii) Multiplication operator used for division
(iii) Missing semicolon. [2]

(i) Runtime error
(ii) Logical error
(iii) Syntax error

Question 2
(b) Complete the code below to create an object for Scanner class.
Scanner sc=____ Scanner(_____) [2]

Scanner sc=new Scanner(System.in);

Question 3
(f) State the method that
(i) Converts a string to primitive float data type.
(ii) Determines if the specified character is an uppercase character. [2]

(i) Float.parseFloat()
(ii) Character.isUpperCase()

2013

Question 2
(a) Name any two wrapper classes. [2]

1) Integer
2) Double

(e) What is an exception? [2]

Exception in general means some un-expected situation that causes a run time error. For example when the user input a character for a statement to input integer it causes an exception.

Question 3
(e) What is the data type that the following library functions return?
(i) isWhitespace(char ch)
(ii) Math.random() [2]

(i) boolean
(ii) double

Name the methods of Scanner class that:
(i) is used to input an integer data from the standard input stream
(ii) is used to input a string data from the standard input stream. [2]

(i) nextInt()
(ii) next()

2014

Question 1
(b) What is meant by package? Name any two Java Application Programming Interface Packages. [2]

A group of related classes and interfaces are known as a package.
1) java.lang
2) java.io

Question 3
(j) What will be the output when the following code segments are executed?
(i) String s= “1001”;
int x= Integer.valueOf(s);
double y= Double.valueOf(s);
System.out.println("x="+x);
System.out.println("y="+y);
(ii) System.out.println("The king said \”Begin at the beginning!\” to me."); [2]

(i) x=1001
y=1001.0
(ii) The king said ”Begin at the beginning!” to me.

2015

Question 1
(e) Name the wrapper classes of char type and boolean type. [2]

Character and Boolean

Question 3
(a) State the data type and value of y after the following is executed:
char x=’7’; y=Character.isLetter(x); [2]

Data type: boolean
Value: false

(b) What is the function of catch block in exception handling? Where does it appear in a program? [2]

The catch block in exception handling catches the exceptions that happened in the try block and informs an Exception class.

(e) Name the mathematical function which is used to find sine of an angle given in radians? [2]

Math.sin()

Question 2
(g) State the package that contains the class:
(i) BufferedReader
(ii) Scanner [2]

(i). java.io
(ii) java.util

2016

Question 1
(c) Name any two library packages. [2]

1) java.lang
2) java.io

(d) Name the type of error (syntax, runtime or logical error) in each case given below:
(i) Math.sqrt(36-45)
(ii) int a;b;c; [2]

(i) Logical error (There is output, it is NaN)
(ii) Syntax error

2017

Question 2
(a) Name the following:
(i) A keyword used to call a package in the program [2]

(i) import

(c) State the data type and value of res after the following is executed
char ch=’t’; res=Character.toUppercase(ch); [2]

Data type: char
Value: T

Question 3
(g) What are the values stored in variable r1 and r2:
(i) double r1=Math.abs(Math.min(-2.83,-5.83);
double r2=Math.sqrt(Math.floor(16.3)); [2]

r1 = 5.83
r2 = 4.0

(j) What is the difference between the Scanner class functions next() and nextLine()? [2]

The next() function accepts only one word. But the nextLine() function accepts multiple words

2018

Question 1
(c) Write a difference between the functions isUpperCase() and toUpperCase(). [2]

isUpperCase(): It is a Character class function to check whether a character is upper case or not. It returns boolean value true or false.
E.g.: Character.isUpperCase(‘N’) returns true.
toUpperCase(): It is a Character class function to convert a character into upper case. It returns char value.
E.g.: Character.toUpperCase(‘a’) returns A.

Question 2
(a) (ii) Name the package that contain wrapper classes [2]

(ii) java.lang

2019

Question 2
(b) Give output of the following:
String P= “20”, Q= “19”;
int a=Integer.parseInt(P);
int b=Integer.parseInt(Q);
System.out.println(a+""+b); [2]

2019

(c) What are the various types of errors in Java? [2]

1) Syntax errors. E.g.: Class Sum
2) Run time error. E.g.: System.out.println(5/0);
3) Logical error: remainder=a/b;

(a) State the data type and value of res after the following is executed:
char ch=’9’;
res=Character.isDigit(ch); [2]

Data type: boolean
Value: true

Question 3
(a) Write a Java expression for the following:
|x2+2xy| [2]

Math.abs(x*x+2*x*y)

(b) Write return type of the following functions:
(i} startswith()
(ii) random() [2]

(ii) double

(j) What is meant by a package? Give an example. [2]

Package is group of related classes and interfaces. E.g.: java.lang is a package.

2020

Question 2
(a) What is autoboxing in Java? Give an example. [2]

Autoboxing is the process by which a primitive type value is automatically stored (boxed) into its equivalent wrapper type object.
E.g.: Integer ob = 5;
Here ob is an object of Integer wrapper class. Primitive value 5 is boxed into object ob. There is no need to explicitly create an object as Integer ob = new Integer(5);

Question 2
(d) What is the use of import statement in Java? [2]

The import statement is used to link classes in a package to user's program.

Question 3
(f) What is the data type returned by the following library methods?
(i) isWhitespace()
(ii) compareToIgnoreCase() [2]

(i) boolean
(ii) int