Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Library Classes in Java

Chapter 12

Library Classes in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Assignment Questions and Answers


Question 1

What are the library classes in Java? What is their use?

Answer

Library classes are the pre-written classes which are a part of the Java system. For example, the String and Scanner class.

Java environment has a huge library of library classes that contain pre-defined methods to simplify the job of a programmer. These methods support input/output operations, String handling and help in development of network and graphical user interface.

Question 2(i)

Define Primitive data type

Answer

Primitive data types are pre-defined by the language and form the basic building blocks of representing data. They store a single value of a specific declared type at a time. The eight built-in primitive data types in Java are byte, short, int, long, float, double, char, boolean.

Question 2(ii)

Define Composite data type

Answer

A composite data type is a data type which can be constructed in a program using the programming language's primitive data types. It is a collection of primitive data types. Examples of composite data types are String and Array.

Question 2(iii)

Define User-defined data type

Answer

The data type defined by the user to perform some specific task is known as a user-defined data type. For example, the classes created by the user are user defined data types.

Question 3

Why is a class called a composite data type? Explain.

Answer

In a class, one can assemble items of different data types to create a composite data type. The class can also be considered as a new data type created by the user, that has its own functionality. The classes allow these user-defined types to be used in programs. Hence, a class is called a composite data type.

Question 4

What is a wrapper class? Name three wrapper classes in Java.

Answer

A wrapper class allows us to convert a primitive data type into an object type. Each of Java's eight primitive data types­ has a wrapper class dedicated to it. These are known as wrapper classes because they wrap the primitive data type into an object of that class.

The three wrapper classes are Integer, Float and Double.

Question 5

Explain the terms, Autoboxing and Auto-unboxing in Java.

Answer

The automatic conversion of primitive data type into an object of its equivalent wrapper class is known as Autoboxing. For example, the below statement shows the conversion of an int to an Integer.

Integer a = 20;

Here, the int value 20 is autoboxed into the wrapper class Integer variable myinteger.

Auto-unboxing is the reverse process of Autoboxing. It is the automatic conversion of a wrapper class object­ into its corresponding primitive type. For example,

Integer myinteger = 20;   int myint = myinteger;

Here, the object myInteger is automatically unboxed into primitive type int variable myint when the assignment takes place.

Question 6

How do you convert a numeric string into a double value?

Answer

The wrapper class Double has a method parseDouble() which is used to parse a numeric string into a double value.

Syntax:

Double.parseDouble(String s);

Example:

String str = "437246.643";double d = Double.parseDouble(str);

Question 7

Describe wrapper class methods available in Java to parse string values to their numeric equivalents.

Answer

The wrapper class methods available in Java to parse string values to their numeric equivalents are described below:

  1. parseInt(string)— It is a part of wrapper class Integer. It parses the string argument as a signed integer. The characters in the string must be digits or digits separated with a decimal. The first character may be a minus sign (-) to indicate a negative value or a plus sign (+) to indicate a positive value.
    Syntax:
    int parseInt(String s)
  2. parseLong(string)— It is a part of wrapper class Long. It parses the string argument as a signed long. The characters in the string must be digits or digits separated with a decimal. The first character may be a minus sign (-) to indicate a negative value or a plus sign (+) to indicate a positive value.
    Syntax:
    long parseLong(String s)
  3. parseFloat(string)— It is a part of wrapper class Float. It returns a float value represented by the specified string.
    Syntax:
    float parseFloat(String s)
  4. parseDouble(string)— It is a part of wrapper class Double. It returns a double value represented by the specified string.
    Syntax:
    double parseDouble(String s)

Question 8

How can you check if a given character is a digit, a letter or a space?

Answer

We can check if a given character is a digit, a letter or a space by using the following methods of Character class:

  1. isDigit(char)— It returns true if the specified character is a digit; returns false otherwise.
    Syntax:
    boolean isDigit(char ch)
  2. isLetter(char)— It returns true if the specified character is a letter; returns false otherwise.
    Syntax:
    boolean isLetter(char ch)
  3. isLetterOrDigit(char)— It returns true if the specified character is a letter or a digit; returns false otherwise.
    Syntax:
    boolean isLetterOrDigit(char ch)
  4. isWhitespace(char)— It returns true if the specified character is whitespace; returns false otherwise.
    Syntax:
    boolean isWhitespace(char ch)

Question 9(i)

Distinguish between isLowerCase() and toLowerCase()

Answer

isLowerCase() toLowerCase()

isLowerCase() function checks if a given character is in lower case or not.

toLowerCase() function converts a given character to lower case.

Its return type is boolean.

Its return type is char.

Question 9(ii)

Distinguish between isUpperCase() and toUpperCase()

Answer

isUpperCase() toUpperCase()

isUpperCase() function checks if a given character is in upper case or not.

toUpperCase() function converts a given character to upper case.

Its return type is boolean.

Its return type is char.

Question 9(iii)

Distinguish between isDigit() and isLetter()

Answer

isDigit() isLetter()

isDigit() method returns true if the specified character is a digit; returns false otherwise.

isLetter() method returns true if the specified character is a letter; returns false otherwise.

Question 9(iv)

Distinguish between parseFloat() and parseDouble()

Answer

parseFloat() parseDouble()

parseFloat() method returns a float value represented by the specified string.

parseDouble() method returns a double value represented by the specified string.