0% found this document useful (0 votes)
301 views5 pages

Library Classes

A package in Java is used to group related classes. There are two types of packages - built-in packages provided by Java API and user-defined packages created by programmers. The asterisk(*) in an import statement indicates that all classes in the imported package can be used. Wrapper classes wrap primitive types in objects and are in the java.lang package. isUpperCase() checks if a character is uppercase while toUpperCase() converts a character to uppercase. parseInt() converts a string to an integer and toString() converts an integer to a string. Primitive types are fundamental types while composite types are created using primitive types.

Uploaded by

Anirudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
301 views5 pages

Library Classes

A package in Java is used to group related classes. There are two types of packages - built-in packages provided by Java API and user-defined packages created by programmers. The asterisk(*) in an import statement indicates that all classes in the imported package can be used. Wrapper classes wrap primitive types in objects and are in the java.lang package. isUpperCase() checks if a character is uppercase while toUpperCase() converts a character to uppercase. parseInt() converts a string to an integer and toString() converts an integer to a string. Primitive types are fundamental types while composite types are created using primitive types.

Uploaded by

Anirudh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

What is a package?

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


Built-In packages — These are provided by Java API
1. 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 It is used to convert the character given as its
is in upper case or not. argument to 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 Data Types are Java's fundamental data types
Primitive Data Types

Primitive Data Types are built-in data types defined by Composite Data Types are defined by the
Java language specification programmer

Examples of Primitive Data Types are byte, short, int, long, Examples of Composite Data Types are Class
float, double, char, boolean and Array

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

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

Output

Question 3

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

1007

Question 4

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

Output

70
70
Question 5
char ch = 'y';
char chr = Character.toUpperCase(ch);
int p = (int) chr;
System.out.println(chr + "\t" + p);
Output

Y 89

Question 6

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

Output

A Great Victory

Question 7
char ch = 'x'; int n = 5;
n = n + (int)ch;
char c = (char)n;
System.out.println((char)((int)c-26));

Output

c
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

You might also like