wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA FULL STACK TEST 1

Total questions: 75

Worksheet time: 4hrs 45mins

Name
Class
Date
1.

String txt = "Hello World";

System.out.println(txt.toUpperCase());


Choose the correct output.

a)

"HELLO WORLD"

b)

HELLO WORLD

c)

Hello world

d)

Hello World

2.

Choose correct purpose of indexOf() in String class.

a)

returns the index (the position) of the last occurrence of a specified text in a string

b)

returns the character of the first occurrence of a specified character in a string

c)

returns the index (the position) of the first occurrence of a specified text in a string (excluding whitespace)

d)

returns the index (the position) of the first occurrence of a specified text in a string (including whitespace)

3.

String x = "10";

String y = "20";

String z = x + y;

System.out.println(z);

Guess the output.

a)

1020

b)

10 20

c)

30

d)

"10 20"

4.

Choose most appropriate purpose of trim() method in String?

a)

to remove white spaces

b)

to get a substring of the string

c)

to cut String at desired index

d)

to remove extra white spaces from start and end of String

5.

What is the most appropriate way to check if two Strings are identical?

a)

string1 == string2

b)

string1.equals(string2)

c)

string1.same(string2)

d)

string1.equalsIgnorecase(string2)

6.

Which of these class is superclass of String and StringBuffer class?

a)

java.util

b)

java.lang

c)

ArrayList

d)

None of the mentioned

7.

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)

a

b)

b

c)

c

d)

abc

8.

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);

}

}

a)

3 0

b)

0 3

c)

3 4

d)

4 3

9.

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);

}

}

a)

hello hello

b)

world world

c)

hello world

d)

world hello

10.

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)); }

}

a)

false false

b)

true true

c)

true false

d)

false true

11.

What does the following print?

System.out.println( "And yet, it moves!".charAt(0) );

a)

A

b)

n

c)

!

d)

The statement is incorrect.

12.

What does the following print?

String str = "And yet, it moves!"

System.out.println( str.charAt( str.length() ) );

a)

A

b)

n

c)

!

d)

The statment is incorrect.

13.

Which of the following statement about Set is true?

a)

A HashSet cannot have a null value.

b)

Set allows duplicate values.

c)

Set allows null values but only single occurrence.

d)

Set extends the Java.util.collection interface.

14.

When does method overloading is determined?

a)

At run time

b)

At compile time

c)

At coding time

d)

At execution time

15.

Which concept of Java is achieved by combining methods and attribute into a class?

a)

Encapsulation

b)

Inheritance

c)

Polymorphism

d)

Abstraction

16.

Which of the below is invalid identifier with the main method?

a)

public

b)

static

c)

final

d)

private

17.

What is the extension of compiled java classes?

a)

.java

b)

.class

c)

.txt

d)

.js

18.

Which of this keyword must be used to inherit a class?

a)

super

b)

this

c)

extend

d)

extends

19.
_________________ is a collection of elements used to store the same type of data.
a)
Array
b)
Switch
c)
Case
d)
Loop
20.
What are the legal indexes for the array ar, given the following declaration:
int[] ar = {2, 4, 6, 8 }
a)
 0, 1, 2, 3
b)
 1, 2, 3, 4
c)
2, 4, 6, 8
d)
 0, 2, 4, 6
21.

int [] nums = {2, 3, 5, 8, 9, 11};

How would you access the fourth element in nums?

a)

nums[4]

b)

nums[3]

c)

nums(4)

d)

nums(3)

22.
Index values of an array range from ______________.
a)
0 to length – 1
b)
1 to length
c)
0 to length
d)
0 to length + 1
23.
Create an array of 12 strings called months.
a)
String[] months = new String[12];
b)
String months = new String[12];
c)
String[] months = new String[];
d)
String[12] months = new String[];
24.

Which of the following class creation prevents creating a child class of the Example class?

 

a)

class Example {}

b)

abstract public class Example {}

c)

public final class Example {}

25.

Which of the following is not part of the Collection interface?

a)

Deque

b)

List

c)

HashMap

d)

LinkedList

26.

What is difference between starting thread with run() and start() method?

a)

There is no difference

b)

When you call start() method, main thread internally calls run() method to start newly created Thread

c)

run() calls start() method internally

d)

None

27.

_________________ KEY UNIQUELY IDENTIFIES EACH ROW UNIQUELY IN THE TABLE

a)

FOREIGN

b)

PRIMARY

c)

SUPER

d)

COMPOSITE

28.

Predict the output of the following program.


class A{

int a=40;//non static

public static void main(String args[]){

System.out.println(a);

}

}

a)

Compilation Error

b)

40

c)

0

d)

None of the above

29.

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);

}

}

a)

10 10

b)

20 20

c)

10 20

d)

20 10

30.

Which SQL function is used to count the number of rows in a SQL query?

a)

COUNT()

b)

NUMBER()

c)

SUM()

d)

COUNT(*)

31.

If you don’t specify ASC or DESC after a SQL ORDER BY clause, the following is used by default

a)

ASC

b)

DESC

c)

There is no default value

d)

None of the mentioned

32.

What does the ALTER TABLE clause do?

a)

The SQL ALTER TABLE clause modifies a table definition by altering, adding, or deleting table columns and/or constraints

b)

The SQL ALTER TABLE clause is used to insert data into database table

c)

THE SQL ALTER TABLE deletes data from database table

d)

The SQL ALTER TABLE clause is used to delete a database table

33.

The UPDATE SQL clause can _____________

a)

update only one row at a time

b)

update more than one row at a time

c)

delete more than one row at a time

d)

delete only one row at a time

34.

SQL query to find all the cities whose humidity is 95.

a)

SELECT city WHERE humidity = 95

b)

SELECT city FROM weather WHERE humidity = 95

c)

SELECT humidity = 89 FROM weather

d)

SELECT city FROM weather

35.

SQL query to find the temperature in increasing order of all cities.

a)

SELECT city FROM weather ORDER BY temperature

b)

SELECT city, temperature FROM weather

c)

SELECT city, temperature FROM weather ORDER BY temperature

d)

SELECT city, temperature FROM weather ORDER BY city

36.

Find the name of those cities with temperature and condition whose condition is either sunny or cloudy but temperature must be greater than 70.

a)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ OR temperature > 70

b)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ OR temperature > 70

c)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ OR condition = ‘cloudy’ AND temperature > 70

d)

SELECT city, temperature, condition FROM weather WHERE condition = ‘sunny’ AND condition = ‘cloudy’ AND temperature > 70

37.

Which statement is used to extract data from a database?

a)

Extract

b)

Get

c)

Open

d)

Select

38.

Which word is missing from the following SQL statement?


Select * table_name

a)

With

b)

Where

c)

From

d)

And

39.

Where does the CREATE Command belong?

a)

DML

b)

DDL

c)

DCL

40.

It is a DML command that is used to display record.

a)

DISPLAY

b)

STRUCTURE

c)

WHERE

d)

SELECT

41.

______________ constraint prevents NULL values

a)

UNIQUE

b)

NOT NULL

c)

NULL

d)

FOREIGN KEY

42.

drop, truncate, create are the commands of DDL?

a)

True

b)

False

43.

_____ is used to filter out the data by applying condition on grouped data.

a)

where

b)

from

c)

having

d)

order by

44.

What is the advantage of Exception Handling

a)

To avoid abnormal termination of a program

b)

To find out errors

c)

To Debug program

d)

None of these

45.

Which of the following key word is optional in Exception handling program

a)

try

b)

catch

c)

finally

d)

throw

46.

try block may or may not contains catch blocks

a)

True

b)

False

47.

What is the purpose of 'throw' keyword

a)

To Raise an exception explicityly

b)

To Raise an exception implicityly

c)

To create user defined exceptions

d)

To create custom exceptions

48.

What is an exception

a)

Error occurred during the execution of a program

b)

Bug occurred during the compile time of a program

c)

Simply an Error

d)

It is related to input values

49.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

50.

Which of the following is not a keyword to implement Exception Handling?

a)

throw

b)

throws

c)

finally

d)

finalize

51.

When an exception occurs in a program, which of the following will arise during program execution in Java?

a)

Abnormal Termination of the program takes place.

b)

The code after exception raised statement will not be executed.

c)

Default handler is executed and prints stack trace.

d)

All the above.

52.

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");

}

}

}

a)

Java is Life

b)

Java Life

c)

Prints stack trace

d)

Java Life is

53.

Which of these classes is super class of Exception class?

a)

Throwable

b)

System

c)

RunTime

d)

Class

54.

Which class provide implementation for service() method ?

a)

HttpServlet

b)

GenericServlet

c)

Servlet

d)

none of the above

55.

What is the lifecycle of a servlet?

a)

Servlet class is loaded

b)

Servlet instance is created

c)

init(),service() and destroy() methods will be called

d)

All the above

56.

How many times init() method is called during life time of a servlet?

a)

two times

b)

one time

c)

several times

d)

never called

57.

When destroy method() of servlet called ?

a)

for first request

b)

when you close the browser window

c)

when you remove the application from server

d)

none of the above

58.
who dose control life cycle of servlet
a)
browser
b)
client
c)
container
d)
user
59.
in which folder we can put web.xml
a)
classes
b)
package
c)
WEB-INF
d)
web apps
60.
which lifecycle method make ready the servlet for garbage collection
a)
init()
b)
service()
c)
destroy()
d)
put()
61.

The life cycle of a servlet is managed by

a)

servlet context

b)

servlet container

c)

the supporting protocol (such as http or https)

d)

All of the above

62.

Select the method to get form data into jsp

a)

getParameter()

b)

request.getparameter()

c)

request.getParameter()

d)

request.getString()

63.

The code inside scriplet will be placed in _____ method of jsp life cycle.

a)

jsp_init()

b)

jsp_service()

c)

_jspService()

d)

httpService()

64.

“request” is instance of which one of the following classes

a)

Request

b)

HttpRequest

c)

HttpServletRequest

d)

ServletRequest

65.

Which method is used to register a jdbc driver?

a)

Class.ForName()

b)

Class.forName()

c)

class.ForName()

d)

class.forName()

66.

What is the return type of executeUpdate() method?

a)

byte

b)

short

c)

int

d)

long

67.

What is the return type of executeQuery() method?

a)

int

b)

ResultSet

c)

array

d)

none of the above

68.

what is the package name of "Class"?

a)

java.util

b)

java.sql

c)

java.lang

d)

java.io

69.

What is JDBC?

a)

JDBC is a java based protocol.

b)

JDBC is a standard Java API for database-independent connectivity between the Java programming language and a wide range of databases.

c)

JDBC is a specification to tell how to connect to a database.

d)

Joint Driver for Basic Connection

70.

Which of the following encapsulates an SQL statement which is passed to the database to be parsed, compiled, planned and executed?

a)

DriverManager

b)

JDBC driver

c)

Connection

d)

Statement

71.

what is true about getConnection() method?

a)

It is a static method from DriverManager class

b)

It is a non static method from DriverManager class

c)

It is a static method from DriverManager interface

d)

It is a non static method from DriverManager interface

72.

Which package contains JDBC classes and interfaces?

a)

java.lang

b)

java.io

c)

java.sql

d)

java.jdbc

73.

JDBC Stands for _________

a)

Java Database Connectivity

b)

Java Driver Connectivity

c)

Java Developer Connectivity

d)

None of the above

74.

Which of the following method is used to execute insert query in JDBC?

a)

executeUpdate()

b)

executeQuery()

c)

execute()

d)

executeInsert()

75.

What is the return type of ResultSet next() method?

a)

boolean

b)

int

c)

String

d)

long