0% found this document useful (0 votes)
5 views

computer - Library classes -quick revision

The document provides revision notes for Class X Computer Applications covering key topics such as Library Classes, Encapsulation, Inheritance, Arrays, and String Handling. It includes definitions, examples, and explanations of Java concepts like primitive and non-primitive data types, wrapper classes, and various character functions. Additionally, it contains questions and answers to reinforce understanding of these concepts.

Uploaded by

akarshhagarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

computer - Library classes -quick revision

The document provides revision notes for Class X Computer Applications covering key topics such as Library Classes, Encapsulation, Inheritance, Arrays, and String Handling. It includes definitions, examples, and explanations of Java concepts like primitive and non-primitive data types, wrapper classes, and various character functions. Additionally, it contains questions and answers to reinforce understanding of these concepts.

Uploaded by

akarshhagarwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Class X – Computer Applications

Revision notes
Syllabus :
1. Library Classes
2. Encapsulation and Inheritance
3. Arrays
4. String Handling

Ch-Library Classes
Points to remember:
1. Primitive data types are- byte, short, int, long, float, double, char, Boolean.
2. Composite/ Reference/ User Defined/ Non-primitive are- Classes, Arrays, Strings
3. Wrapper are classes available in- java.lang package.

4. Return type of following functions are-


Character.isLowerCase(char ch) - determines if the specified character is an lowercase character.
Return type- boolean
Character.isUpperCase(char ch) - determines if the specified character is an uppercase
character.
Return type- boolean
Character.toLowerCase(char ch) - converts upper case letter into lower case.
Return type- char
Character.toUpperCase(char ch) - coverts lower case letter into upper case.
Return type- char
Character.isWhiteSpace(char ch) - determines if the specified character is an whitespace.
Return type- boolean
Character.isDigit(char ch) - determines if the specified character is a digit.
Return type- boolean
Character.isLetter(char ch) - determines if the specified character is a letter.
Return type- boolean
Character.isLetterOrDigit(char ch)- determines if the specified character is a letter or digit.
Return type- boolean

5. What will be the output of


a. String A = “26”, B= “100”;
String D= A+B + “200”;
int x = Integer.parseInt(A);
int y = Integer.parseInt(B);
int d = x+y;
System.out.println(“Result 1=” +D);
System.out.println(“Result 2=” +d);

Ans. The output is :


Result 1= 26100200
Result 2= 126

b. String s = “1001”;
int x = Integer.valueOf(s);
double y = Double.valueOf(s);
System.out.println(“x=” +x);
System.out.println(“y =” +y);

Ans. x= 1001
y= 1001.0
c. System.out.println(“The King said\” Begin at the beginning!\” to me.”);
Ans. The King said “Begin at the beginning!” to me.

d. System.out.println(Character.isUpperCase(‘R’);
Ans. true

e. System.out.println(Character.toUpperCase(‘j’);
Ans. J

6. What will be the value returned by-

a. Integer.parseInt(“-321”)
Ans : -321

7. parse methods- parse the String argument as a numeric value.


a. convert a String into its integer equivalent
Ans. Integer.parseInt()
b. converts a String to a primitive float data type.
Ans. Float.parseFloat()
c. converts a String to a primitive double data type.
Ans. Double.parseDouble()
d. converts a String to a primitive long data type.
Ans. Long.parseLong()

8. What will be the result when the following statement is executed?


int count = new Integer(12);
Ans. Variable count will be initialized with value 12.

9(i). State the data type and value of res after the following is executed:
char ch = ‘t’;
res = Character.toUpperCase(ch);

Ans. The data type of res will be char, and its value following execution will be ‘T’.

9(ii). State the data type and value of y after the following is executed:
char x = ‘7’;
y = Character.isLetter(x);
Ans. The data type of y will be boolean, and its value following execution will be false.

10. Name the wrapper class of following data types:


a. byte Byte
b. short Short
c. int Integer
d. long Long
e. float Float
f. double Double
g. char Character
h. boolean Boolean

11. The default value of a boolean variable data type


Ans. false

12. Write a Java statement to perform the following tasks on a string.


a. Extract the second last character of a word stored in the variable wd.
Ans. char seclastchar = wd.charAt(wd.length()-2));
b. Check if the second character of a String str is in uppercase.
Ans. boolean result = Character.isUpperCase(str.charAt(1));

13. What are Library classes?


Ans. Library classes are the prewritten classes which are a part of the Java system. Foe ex. the String and
the Scanner class.

14. What are wrapper classes?


Ans. A wrapper class allows you to convert a primitive data type into an object type.

15. Autoboxing / Boxing– is the automatic conversion of the primitive types into their corresponding
object wrapper classes.
Ex. Integer a = 20;

16. Auto-unboxing- It is the reverse of Autoboxing. It is the automatic conversion of wrapper class object
into its corresponding primitive type.
Ex. Integer a = 20;
int b = a;
17. Difference between in Primitive and non-primitive data type
Primitive Non-primitive/Composite/ User defined/ Referenced
1. represents a single value. 1. is a collection that holds zero or more primitive
values or objects.
2. When data is copied to a variable, the 2. When data is copied to a variable , only a referenced
variable gets its own copy of data, stored to the data is stored in the variable.
separately in memory.
3. In method call, primitive data is passed by 3. In method call, composite data type is passed by
value. reference.

*************************************************** *****************************************

Some more questions


Library Classes
Fill in the blanks
Question 1

Package is a collection of classes.

Question 2

By default, java.lang package is imported in a Java program.

Question 3

The user can create a data type by using a class.

Question 4

The data type int is included in Integer wrapper class.

Question 5
Wrapper class uses first letter in upper case.

Question 6

String data is converted to float type by using Float.parseFloat(String) function.

Question 7

Conversion from primitive type to wrapper object is called as autoboxing.

Question 8

Each character oriented function uses a wrapper tag Character.

State whether the following statements are True/False


Question 1

Java class library includes all the packages


True

Question 2

Wrapper classes belong to java.util package.


False

Question 3

Array is a non-primitive data type.


True

Question 4

Class is a composite data type.


True

Question 5

Integer.toString() converts integer data to String.


True

Choose appropriate option for the following statements


Question 1

A package contains:

1. tags
2. classes ✓
3. data
4. arrays

Question 2

Each primitive data type belongs to a specific:

1. block
2. object
3. wrapper class ✓
4. none

Question 3

Automatic conversion of primitive data into an object of wrapper class is called:

1. autoboxing ✓
2. explicit conversion
3. shifting
4. none

Question 4

The parseInt() function is a member of:

1. integer wrapper class ✓


2. character wrapper class
3. boolean wrapper class
4. none

Question 5

valueOf() function converts:

1. Primitive type to String


2. String to primitive type ✓
3. character to String
4. None

Answer the following questions


Question 1

What is a package?

In Java, a package is used to group related classes. Packages are of 2 types:

1. Built-In packages — These are provided by Java API


2. User-Defined packages — These are created by the programmers to efficiently structure their code.
java.util, java.lang are a couple of examples of built-in packages.

Question 2

What is the significance of '*' while importing a package?

The asterisk(*) sign indicates that all the classes in the imported package can be used in the program.

Question 3

Define a wrapper class.

Wrapper classes wrap the value of a primitive type in an object. Wrapper classes are present in java.lang package. The
different wrapper classes provided by Java are Boolean, Byte, Integer, Float, Character, Short, Long and Double.

Question 4

Differentiate between:

(a) isUpperCase() and toUpperCase()


isUpperCase() toUpperCase()
It is used to check if the character given as its argument is in upper It is used to convert the character given as its argument to
case or not. upper case
Its return type is boolean Its return type is char

(b) parseInt() and toString() functions

parseInt() toString()
It converts a string to an integer It converts an integer to a string
Its return type is int Its return type is String

(c) primitive type and composite type data

Primitive Data Types Composite Data Types


Composite Data Types are created by using Primitive
Primitive Data Types are Java's fundamental data types
Data Types
Primitive Data Types are built-in data types defined by Java language
Composite Data Types are defined by the programmer
specification
Examples of Primitive Data Types are byte, short, int, long, float, double,
Examples of Composite Data Types are Class and Array
char, boolean

Question 5(i)

int res = 'A';


What is the value of res?

Value of res is 65.

Question 5(ii)

Name the package that contains wrapper classes.

java.lang

Question 5(iii)

Write the prototype of a function check which takes an integer as an argument and returns a character.

char check(int n)

Write the purpose of the following functions


Question 1

Float.parseFloat()

It is used to convert string data into float data.

Question 2

Double.toString()

It is used to convert double data to a string.

Question 3

Integer.valueOf()
It is used to convert string data into the Integer wrapper object.

Question 4

Character.isDigit()

It is used to check if the character given as its argument is a digit.

Question 5

Character.isWhitespace()

It is used to check if the character given as its argument is a whitespace.

Find the output of the following program snippets


Question 1

char ch = '*'; boolean b = Character.isLetter(ch); System.out.println(b);

Output

false

Explanation

As Asterisk (*) is not a letter so Character.isLetter() method returns false.

Question 2

char c = 'A'; int n = (int) c + 32; System.out.println((char)n);

Output

Explanation

int n = (int) c + 32 ⇒ 65 + 32 ⇒ 97
So, variable n get the value of 97. 97 is the ASCII code of small a so casting n to char, prints a to the console.

Question 3

String s= "7"; int t =Integer.parseInt(s); t=t+1000; System.out.println(t);

Output

1007

Explanation

Integer.parseInt() converts "7" into an int value i.e. the decimal number 7. t+1000 adds the number 7 to 1000 giving
1007 as the output.

Question 4

char c = 'B'; int i = 4; System.out.println(c+i); System.out.println((int)c+i);

Output
70 70

Explanation

In the expression c + i, c is of type char and i is of type int. As int is the higher type so char gets promoted to int. Thus,
ASCII code of 'B' which is 66 is added to 4 giving the output as 70. This is an example of implicit type conversion.
In the next expression (int)c + i, c which is of char type is explicitly casted to int. Again, ASCII code of 'B' which is 66 is
added to 4 giving the output as 70. This is an example of explicit type conversion.

Question 5

char ch = 'y'; char chr = Character.toUpperCase(ch); int p = (int) chr;


System.out.println(chr + "\t" + p);
Output
Y 89

Explanation

Character.toUpperCase()method converts small y to capital Y so chr gets the value of 'Y'. Casting chr to int gives the
ASCII code of 'Y' which is 89.

Question 6

int n = 97; char ch = Character.toUpperCase((char)n); System.out.println(ch + " Great


Victory");

Output

A Great Victory

Explanation

97 is the ASCII code of small a so Character.toUpperCase((char)n) returns capital A which is stored in ch.

Question 7

char ch = 'x'; int n = 5; n = n + (int)ch; char c = (char)n;


System.out.println((char)((int)c-26));

Output

Explanation

As ASCII code of 'x' is 120, so the expession n + (int)ch ⇒ 5 + 120 ⇒ 125. After that, the expression (char)((int)c-26)
⇒ (char)(125 - 26) ⇒ (char)99 ⇒ 'c' as ASCII code of 'c' is 99. So, c is the final output.

Question 8

char ch = 'A'; char chr = Character.toLowerCase(ch); int n = (int)chr-32;


System.out.println((char)n + "\t" + chr);

Output

A a

Explanation

Character.toLowerCase() converts 'A' to 'a'. ASCII code of 'a' is 97. n becomes 65 — (int)chr-32 ⇒ 97 - 32 ⇒ 65. 65 is
the ASCII code of 'A'.

You might also like