Font size
WorksheetsJAVA FULL STACK TEST 1
Total questions: 75
Worksheet time: 4hrs 45mins
String txt = "Hello World";
System.out.println(txt.toUpperCase());
Choose the correct output.
"HELLO WORLD"
HELLO WORLD
Hello world
Hello World
Choose correct purpose of indexOf() in String class.
returns the index (the position) of the last occurrence of a specified text in a string
returns the character of the first occurrence of a specified character in a string
returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)
returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)
String x = "10";
String y = "20";
String z = x + y;
System.out.println(z);
Guess the output.
1020
10 20
30
"10 20"
Choose most appropriate purpose of trim() method in String?
to remove white spaces
to get a substring of the string
to cut String at desired index
to remove extra white spaces from start and end of String
What is the most appropriate way to check if two Strings are identical?
string1 == string2
string1.equals(string2)
string1.same(string2)
string1.equalsIgnorecase(string2)
Which of these class is superclass of String and StringBuffer class?
java.util
java.lang
ArrayList
None of the mentioned
What is the output of this program?
class String_demo{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
System.out.println(s);
}
}
a
b
c
abc
What is the output of this program?
class String_demo{
public static void main(String args[]){
char chars[] = {'a', 'b', 'c'};
String s = new String(chars);
String s1 = "abcd";
int len1 = s1.length();
int len2 = s.length();
System.out.println(len1 + " " + len2);
}
}
3 0
0 3
3 4
4 3
What is the output of following program?
class string_class{
public static void main(String args[]){
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}
hello hello
world world
hello world
world hello
What is the output of this program?
class string_class{
public static void main(String args[]){
String obj = "hello";
String obj1 = "world";
String obj2 = "hello"; System.out.println(obj.equals(obj1) + " " + obj.equals(obj2)); }
}
false false
true true
true false
false true
What does the following print?
System.out.println( "And yet, it moves!".charAt(0) );
A
n
!
The statement is incorrect.
What does the following print?
String str = "And yet, it moves!"
System.out.println( str.charAt( str.length() ) );
A
n
!
The statment is incorrect.
Which of the following statement about Set is true?
A HashSet cannot have a null value.
Set allows duplicate values.
Set allows null values but only single occurrence.
Set extends the Java.util.collection interface.
When does method overloading is determined?
At run time
At compile time
At coding time
At execution time
Which concept of Java is achieved by combining methods and attribute into a class?
Encapsulation
Inheritance
Polymorphism
Abstraction
Which of the below is invalid identifier with the main method?
public
static
final
private
What is the extension of compiled java classes?
.java
.class
.txt
.js
Which of this keyword must be used to inherit a class?
super
this
extend
extends
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6int [] nums = {2, 3, 5, 8, 9, 11};
How would you access the fourth element in nums?
nums[4]
nums[3]
nums(4)
nums(3)
Which of the following class creation prevents creating a child class of the Example class?
class Example {}
abstract public class Example {}
public final class Example {}
Which of the following is not part of the Collection interface?
Deque
List
HashMap
LinkedList
What is difference between starting thread with run() and start() method?
There is no difference
When you call start() method, main thread internally calls run() method to start newly created Thread
run() calls start() method internally
None
_________________ KEY UNIQUELY IDENTIFIES EACH ROW UNIQUELY IN THE TABLE
FOREIGN
PRIMARY
SUPER
COMPOSITE
Predict the output of the following program.
class A{
int a=40;//non static
public static void main(String args[]){
System.out.println(a);
}
}
Compilation Error
40
0
None of the above
what is the output of this question?
class Test1 {
static int x = 10;
public
static void main(String[] args)
{
Test1 t1 = new Test1();
Test1 t2 = new Test1();
t1.x = 20;
System.out.print(t1.x + " ");
System.out.println(t2.x);
}
}
10 10
20 20
10 20
20 10
Which SQL function is used to count the number of rows in a SQL query?
COUNT()
NUMBER()
SUM()
COUNT(*)
If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by default
ASC
DESC
There is no default value
None of the mentioned
What does the ALTER TABLE clause do?
The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints
The SQL ALTER TABLE clause is used to insert data into database table
THE SQL ALTER TABLE deletes data from database table
The SQL ALTER TABLE clause is used to delete a database table
The UPDATE SQL clause can _____________
update only one row at a time
update more than one row at a time
delete more than one row at a time
delete only one row at a time
SQL query to find all the cities whose humidity is 95.
SELECT city WHERE humidity = 95
SELECT city FROM weather WHERE humidity = 95
SELECT humidity = 89 FROM weather
SELECT city FROM weather
SQL query to find the temperature in increasing order of all cities.
SELECT city FROM weather ORDER BY temperature
SELECT city, temperature FROM weather
SELECT city, temperature FROM weather ORDER BY temperature
SELECT city, temperature FROM weather ORDER BY city
Find the name of those cities with temperature and condition whose condition is either sunny or cloudy but temperature must be greater than 70.
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ OR temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ OR temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ AND temperature > 70
SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ AND temperature > 70
Which statement is used to extract data from a database?
Extract
Get
Open
Select
Which word is missing from the following SQL statement?
Select * table_name
With
Where
From
And
Where does the CREATE Command belong?
DML
DDL
DCL
It is a DML command that is used to display record.
DISPLAY
STRUCTURE
WHERE
SELECT
______________ constraint prevents NULL values
UNIQUE
NOT NULL
NULL
FOREIGN KEY
drop, truncate, create are the commands of DDL?
True
False
_____ is used to filter out the data by applying condition on grouped data.
where
from
having
order by
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
Which of the following key word is optional in Exception handling program
try
catch
finally
throw
try block may or may not contains catch blocks
True
False
What is the purpose of 'throw' keyword
To Raise an exception explicityly
To Raise an exception implicityly
To create user defined exceptions
To create custom exceptions
What is an exception
Error occurred during the execution of a program
Bug occurred during the compile time of a program
Simply an Error
It is related to input values
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of the following is not a keyword to implement Exception Handling?
throw
throws
finally
finalize
When an exception occurs in a program, which of the following will arise during program execution in Java?
Abnormal Termination of the program takes place.
The code after exception raised statement will not be executed.
Default handler is executed and prints stack trace.
All the above.
The output of the following code segment is
public class Main
{
public static void main(String[] args) {
try{
System.out.print("Java ");
int d = 56/0;
System.out.print("is");
}
catch(ArithmeticException e)
{
System.out.print("Life");
}
}
}
Java is Life
Java Life
Prints stack trace
Java Life is
Which of these classes is super class of Exception class?
Throwable
System
RunTime
Class
Which class provide implementation for service() method ?
HttpServlet
GenericServlet
Servlet
none of the above
What is the lifecycle of a servlet?
Servlet class is loaded
Servlet instance is created
init(),service() and destroy() methods will be called
All the above
How many times init() method is called during life time of a servlet?
two times
one time
several times
never called
When destroy method() of servlet called ?
for first request
when you close the browser window
when you remove the application from server
none of the above
The life cycle of a servlet is managed by
servlet context
servlet container
the supporting protocol (such as http or https)
All of the above
Select the method to get form data into jsp
getParameter()
request.getparameter()
request.getParameter()
request.getString()
The code inside scriplet will be placed in _____ method of jsp life cycle.
jsp_init()
jsp_service()
_jspService()
httpService()
“request” is instance of which one of the following classes
Request
HttpRequest
HttpServletRequest
ServletRequest
Which method is used to register a jdbc driver?
Class.ForName()
Class.forName()
class.ForName()
class.forName()
What is the return type of executeUpdate() method?
byte
short
int
long
What is the return type of executeQuery() method?
int
ResultSet
array
none of the above
what is the package name of "Class"?
java.util
java.sql
java.lang
java.io
What is JDBC?
JDBC is a java based protocol.
JDBC is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.
JDBC is a specification to tell how to connect to a database.
Joint Driver for Basic Connection
Which of the following encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed?
DriverManager
JDBC driver
Connection
Statement
what is true about getConnection() method?
It is a static method from DriverManager class
It is a non static method from DriverManager class
It is a static method from DriverManager interface
It is a non static method from DriverManager interface
Which package contains JDBC classes and interfaces?
java.lang
java.io
java.sql
java.jdbc
JDBC Stands for _________
Java Database Connectivity
Java Driver Connectivity
Java Developer Connectivity
None of the above
Which of the following method is used to execute insert query in JDBC?
executeUpdate()
executeQuery()
execute()
executeInsert()
What is the return type of ResultSet next() method?
boolean
int
String
long
