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

JAVA QUESTION BANK 23-24

The document is a Java question bank covering various topics including logical operators, inbuilt packages, constructors, inheritance types, data types, access specifiers, and methods of the String class. It also includes programming exercises related to classes, arrays, vectors, and concepts like method overloading, overriding, and dynamic method dispatch. Additionally, it discusses Java's platform independence and portability, along with specific coding examples.

Uploaded by

givaxol129
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)
4 views

JAVA QUESTION BANK 23-24

The document is a Java question bank covering various topics including logical operators, inbuilt packages, constructors, inheritance types, data types, access specifiers, and methods of the String class. It also includes programming exercises related to classes, arrays, vectors, and concepts like method overloading, overriding, and dynamic method dispatch. Additionally, it discusses Java's platform independence and portability, along with specific coding examples.

Uploaded by

givaxol129
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/ 8

JAVA QUESTION BANK

1 Enlist logical operators in java


Logical And &&
Logical Or \\
Logical Not !

2 Enlist any four inbuilt packages in java



java.net java.io
java.util java.sql
java.lang java.swing
java.awt java.applet

3 Define constructor list its types


A constructor is a special type of function with no return type. Name of
constructor should be same as the name of the class. A constructor is called
automatically when we create an object of a class. Types of Construtor are:-
Default and parameterized

4 List types of inheritance supported by java



Single Inheritance. Hierarchical Inheritance
Multilevel Inheritance

5 List any four data types available in java with their storage size in bytes

int - 4 bytes char – 2 bytes
float – 4 bytes long – 8 bytes
double – 8 bytes Boolean – 1 bit

6 Enlist relational operators in java


 Equal to (==):
Not equal to (!=):
Greater than (>):
Less than (<):
Greater than or equal to (>=):
Less than or equal to (<=):
7 Enlist access specifier in java

Private Public
Default Protected

8 List any four tools of JDK



Javac Jconsole
Javadoc Jdb
Jar Javap

9 Define array. List its types


 Array is a collection of elements of similar data types.
Types of array :-
One dimensional array
Two dimensional array
Three dimensional array

10 Differentiate String and String Buffer class (any two points)


1. String:
o The String class is immutable.
o It is slow and consumes more memory.
o String overrides the equals() method of the Object class.
o String uses the string constant pool.
2. String Buffer:
o The String Buffer class is mutable.
o It is fast and consumes less memory.
o String Buffer also overrides the equals() method of the Object class.
o String Buffer uses heap memory.
11 Define a class employee with data members empid,name and salary accept
data for Two objects and display it.

12 Wap to add 2 integers,2 string and 2 float values in a vector .Remove the
element specified by the user and display the list
13 Develop a program to find reverse of a number

14 Develop a program to declare class student having data members roll and
name .Derive class result having data members mark1,mark2 and method to
initialize and display the information for two objects
15 Wap to add 2 integers,2 string and 2 float values in a vector .Remove the
element specified by the user and display the list
Same as Q.12

16 List any four methods of string class and state the use of each
toUpperCase() and toLowerCase():Use: Converts a string to uppercase or
lowercase.
 trim():Use: Removes leading and trailing white spaces from a string.
 charAt(int index): Use: Returns the character at the specified index.
 intern():Use: Returns a canonical representation of the string (from the
string pool).
 length():Use: Returns the length (number of characters) of the string.
 valueOf():Use: Converts other data types (e.g., int, double) to a string.

17 Wap to find out even numbers from 1 to 100 using for loop

18 Wap using multilevel inheritance


Same as Q.14
19 State the use of final keyword with respect to inheritance
 When a class is declared as final, it cannot be subclassed (i.e., no other class
can extend it). Useful for creating immutable classes (e.g., the
predefined String class).

20 Compare array and vector. Explain elementAt() and addElement() methods


Differences Summary:
 Arrays:  Vectors:
o Fixed size. o Dynamically allocated.
o Homogeneous. o Heterogeneous.
o Fast access. o Slower access (via
o Not dynamically methods).
resizable. o Resizable

 The elementAt() method retrieves the element at the specified index in


the vector. The syntax is :
public object elementAt(int index)
 The addElement() method appends a specified element to the end of the
vector. The syntax is :
public void addElement (object obj)

21 explain the concept of platform independent and portability with respect to


java language

• Java is a write once, run anywhere language
• Java code can be run on multiple platforms like Windows, Linux, Sun Solaris,
Macs etc.
• Java code is compiled by the compiler and converted into bytecode
• This byte code is a platform independent code because it can be run on
multiple platforms.
• The Java Virtual Machine (JVM) converts byte code into machine-level
representation

Portability:
 Java is portable because it facilitates you to carry the Java byte codes to any
platform. It doesn't require any implementation.
 Java program can be moved from one computer to another, anywhere &
anytime, changes and upgrades in OS processors & system resources will not
force any change in JAVA program
22 compare method overloading and method overriding
1. Overloading:
o Two or more methods in one class have the same method name but
different parameters.
o It doesn’t apply polymorphism.
o It applies during compile time.
o Occurs between methods in the same class.
2. Overriding:
o Two or more methods with the same method name and parameters
o It applies polymorphism.
o It applies during run time.
o Occurs between superclass and subclass.

23 Explain concept of dynamic method dispatch with example


24 wap to add two numbers using command line argument
class Main{
public static void main(String [] args){
int a = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
int sum = a + b;
System.out.println("Sum: "+sum);
}
}

25 Define a class circle having data members pi and radius Initialize and display
values of data members also calculate area of circle and display it

You might also like