wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming in Java

Total questions: 101

Worksheet time: 54mins

Name
Class
Date
1.

Which of the following option leads to the portability and security of Java?

a)

Bytecode is executed by JVM

b)

The applet makes the Java code secure and portable

c)

Use of exception handling

d)

Dynamic binding between objects

2.

Which of these data types is used to store command line arguments?

a)

a) Array

b)

b) Stack

c)

c) String

d)

d) Integer

3.

1. Which of this method is given parameter via command line arguments?

a)

a) main()

b)

b) recursive() method

c)

c) Any method

d)

d) System defined methods

4.

What are the Type Conversions available in Java language?

a)

A) Narrowing Type Conversion

b)

B) Widening Type Conversion

c)

A and B

d)

D) None of the above

5.

What is the output of the below Java code snippet?

char ch = 'A';//ASCII 65

int a = ch + 1;

ch = (char)a;

System.out.println(ch);

a)

A) 66

b)

B) A

c)

C) B

d)

D) 65

6.

What is the output of the following code snippet?

int i = 0; for(i = 0 ; i < 5; i++)

{ }

System.out.println(i);

a)

A. 5

b)

B. 0

c)

C. 4

d)

D. Compilation Error

7.

Application Program Interface is a prewritten code organized into packages

of similar topics in IDE.

a)

True

b)

False

8.

IDE stands for Integral Development Environment

a)

True

b)

False

9.

Function of the Scanner class to accept a float literal from the user is

a)

nextInt( )

b)

hasNext( )

c)

next( )

d)

nextFloat( )

10.

Absence of _________ in switch..case leads to fallthrough

a)

switch

b)

case

c)

default

d)

break

11.

The compiler of Java works on_______ to give _________.

a)

Byte Code, Source Code

b)

Source Code, Object Code

c)

Source Code, Byte Code

d)

Byte Code, Object Code

12.

Predict the value of k,

int k =10;

k=k+k++;

a)

11

b)

20

c)

21

d)

22

13.

Q) In java multi-threading, a thread can be created by

a)

Extending Thread class

b)

Implementing Runnable interface

c)

Using both

d)

None

14.

Q) Which method is called internally by Thread start() method?

a)

execute()

b)

run()

c)

launch()

d)

main()

15.

Q) Which method must be implemented by a Java thread?

a)

run()

b)

execute()

c)

start()

d)

None

16.

Q) Which statements is/are correct (More than one is correct).

a)

On calling Thread start () method a new thread get created.

b)

Thread start () method call run () method internally

c)

Thread run () method can also be called directly to create thread.

d)

All correct

17.

The life cycle of a thread in java is controlled by

a)

JRE

b)

JDK

c)

JVM

d)

None

18.

Which method is used to get current running thread object?

a)

runningThread()

b)

currentThread()

c)

runnableThread()

d)

None

19.
Which of these is not a Thread state?
a)
New
b)
Runnable
c)
sleep
d)
terminated
20.

The start() method of an thread object will change the thread from _______ state to _______ state.

a)

Ready to Active

b)

Born to Ready

c)

Ready to Wait

d)

Active to Ready

21.

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

22.

What is the parent class of All Exceptions in JAVA

a)

Throw

b)

Exception

c)

Error

d)

Bug

23.

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

a)

try

b)

catch

c)

finally

d)

throw

24.

try block may or may not contains catch blocks

a)

True

b)

False

25.

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

26.

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

27.

How to create our own exception

a)

using 'throw' keyword

b)

using 'throws' keyword

c)

using 'finally' keyword

d)

using 'throwable' keyword

28.

Exception classes belongs to following package

a)

import java.io.*

b)

import java.lang.*

c)

import java.util.*

d)

import java.lang.Exception.*

29.

Which of these keywords is not a part of exception handling?

a)

try

b)

finally

c)

thrown

d)

catch

30.

java.lang.NullPointerException is a

a)

Error

b)

runtime exception

c)

Compile time exception

d)

None

31.

Which of these class is highest in hierarchy in java

a)

java.lang.Exception

b)

java.lang.Error

c)

java.lang.Throwable

d)

java.lang.Object

32.

Choose the CORRECT exception


String department="JTMK";

Integer no=Integer.parseInt(department);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundsException

33.

Choose an exception if attempt to divide number by zero


int number = 89 / 0;

System.out.println("The answer is " + number);

a)

ArithmeticException

b)

NullPointerException

c)

NumberFormatException

d)

ArrayIndexOutOfBoundException

34.

class exception_handling

{ public static void main(String args[])

{ try

{ int a, b;

b = 0;

a = 5 / b;

System.out.print("A");

} catch(ArithmeticException e)

{ System.out.print("B");

}

finally

{ System.out.print("C");

}

}

}

a)

A

b)

B

c)

AC

d)

BC

35.

public class X

{

public static void main(String [] args)

{

try

{

badMethod();

System.out.print("A");

}

catch (RuntimeException ex) /* Line 10 */

{

System.out.print("B");

}

catch (Exception ex1)

{

System.out.print("C");

}

finally

{

System.out.print("D");

}

System.out.print("E");

}

public static void badMethod()

{

throw new RuntimeException();

}

}

a)

BD

b)

BDE

c)

BD

d)

DE

36.

public class X

{

public static void main(String [] args)

{

try

{

badMethod();

System.out.print("A");

}

catch (Exception ex)

{

System.out.print("B");

}

finally

{

System.out.print("C");

}

System.out.print("D");

}

public static void badMethod()

{

throw new Error(); /* Line 22 */

}

}

a)

ABCD

b)

Compilation fails.

c)

C is printed before exiting with an error message.

d)

BC is printed before exiting with an error message

37.

which one of the following is true?

a)

runnable interface declares the start method

b)

Thread.start() method is used to move a thread from a new state to the runnable state

c)

Thread.runnable() method is used to move a thread from new state to the runnable state

d)

Thread.run() method is used to move a thread from new state to the runnable state

38.

superclass of all classes representing the output stream of characters is -------------

a)

OutputStream

b)

Reader

c)

InputStream

d)

Writer

39.

which of this class is used by character streams for reading data from buffer

a)

BufferReader

b)

InputStreamReader

c)

FileReader

d)

FileInputStream

40.

When will the else part of try-except-else be executed?

a)

always

b)

when an exception occurs

c)

when no exception occurs

d)

never

41.

How many except statements can a try-except block have?

a)

Zero

b)

One

c)

Two

d)

Multiples

42.

++ increases the value of a variable by 1

a)

assignment operator

b)

decrement operator

c)

increment operator

d)

sentinel

43.

What would the new value of A be?

A=1;

a++;

a)

1

b)

2

c)

3

d)

4

44.

What's the value of below?


int i=5;

System.out.println(i++);

System.out.println(i);

System.out.println(++i);

a)

5

6

7

b)

6

6

7

c)

6

7

8

d)

5

5

6

45.

Which statement(s) are equivalent to i = i + 1?

a)

i += 1

b)

i++

c)

i -= 1

d)

i--

46.

Which are the types of operators seen? Select as many you think

a)

bitwise operator

b)

subtraction operator

c)

equality operator

d)

arithmetic operator

47.

what is modulo operation used for ?

a)

performs division

b)

performs division and gives no remainder

c)

performs division and gives remainder

d)

does not perform division

48.

Find the output for the following.

public class IncDec

{

public static void main(String s[])

{

int a = 1;

int b = 2;

int c;

int d;


c = ++b;

d = a++;


c++;


System.out.println("a = " + a);

System.out.print("b = " + b);

System.out.println("c = " + c);

System.out.print("d = " + d);

}

}

a)

a = 2 b = 3 c = 4 d = 1

b)

a = 2 b = 3 c = 4 d = 1

c)

Program does not compile.

d)

a = 1 b = 2 c = 4 d = 2

49.
_________________ is a collection of elements used to store the same type of data.
a)
Array
b)
Switch
c)
Case
d)
Loop
50.
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
51.

What is the first index of an array?

a)

1

b)

0

c)

2

d)

3

52.
The first value of an array called quizzes can be accessed with which of the following statements?
a)
quizzes[1] = 100;
b)
quizzes[0] = 100;
c)
quizzes[zero] = 100;
d)
quizzes[one] = 100;
53.
True or False:  An array can be store different types of data (like store both doubles and ints).
a)
True
b)
False
54.
What value is at index 1 in this array?  String[] names = {"Mack", "Dennis", "Dee", "Charlie"};
a)
Mack
b)
Dennis
c)
Dee
d)
Charlie
55.
What is the correct way to create an array with these three numbers: 12  8  15
a)
int[] = {12, 8, 15};
b)
int[] nums = {12  8  15};
c)
int[] nums = {12, 8, 15}
d)
int[] nums = {12, 8, 15};
56.

Identify the error that exist in this program segment:-

a)

An array data type cannot be use as argument.

b)

The argument was not in the right sequence with the parameter.

c)

The variable name in parameter not as same with the argument.

d)

Program consist 0 error.

57.

What data type would you use to store names of students?

a)

String

b)

char

c)

boolean

d)

None of these

e)

blonde

58.

How would you declare a variable storing the tax rate?

a)

int taxRate = 5.1;

b)

taxRate = "5.1";

c)

double taxRate = 5.1;

d)

double taxRate = "5.1";

e)

I do hereby declare thee Sir Tax Rate

59.

Q) What is maximum thread priority in Java

a)

10

b)

12

c)

5

d)

8

60.

Q) Number of threads in below java program is

public class ThreadExtended extends Thread {


public void run() {

System.out.println("\nThread is running now\n");

}


public static void main(String[] args) {


ThreadExtended threadE = new ThreadExtended();


threadE.start();

}

}

a)

0

b)

1

c)

2

d)

3

61.

Which component represents the single screen with a user interface?

a)

Services

b)

Activities

c)

Broadcast receiver

d)

Content Provider

62.

______ is a device configuration that runs on the Android Emulator.

a)

Android Virtual Device

b)

Android Visual Device

c)

Android Emulator Device

d)

APK Device

63.

Which component supplies data from one application to others on request?

a)

Services

b)

Content Provider

c)

Broadcast receiver

d)

Activities

64.

Which component runs in the background to perform long running operations?

a)

Content Providers

b)

Services

c)

Broadcast receiver

d)

Activities

65.

Which tab shows all the tools useful for the app?

a)

Tool Palette

b)

Component Palette

c)

Component Tree

d)

Design Tab

66.

Expand APK.

a)

Application Programming Kit

b)

Application Package

c)

Android Programming Kit

d)

Android Package

67.

Which language is supported by Android Studio?

a)

Python

b)

Java

c)

Kotlin

d)

C/C++

68.

Android is an open source and ______ Operating System for mobile devices.

a)

Windows Based

b)

Linux based

c)

MAC based

d)

Apple IOS

69.

Identify the features of Android.

a)

Web Browser

b)

Multi-Tasking

c)

Messaging

d)

All of the above

70.

What are the types of User Interface Theme?

a)

Darker and Light

b)

Black and White

c)

Black and Gray

d)

Darker and White

71.

___ are the objects which is used in android for passing the information among Activities in an Application

a)

Services

b)

Intents

c)

Broadcast

d)

Activity

72.

The full form of URI is ____

a)

Uniform Resource Input

b)

Uniform Resource Identifier

c)

Uniform Resource Locator

d)

Uniform Resource Identity

73.

What language used in Android Studio?

a)

Java

b)

C#

c)

HTML

d)

Android Studio

74.

All smartphone have application

a)

Yes

b)

No

75.

Android is based on which kernel?

a)

Linux

b)

Mac

c)

Windows

d)

Symbian

76.

In which directory XML layout files are stored?

a)

/res/drawable

b)

/src

c)

/res/values

d)

/res/layout

77.

During an activity life cycle, what is the first callback method invoked by the system?

a)

onStart()

b)

onCreate()

c)

onPause()

d)

onStop()

78.

What is Manifest.xml in android?

a)

It has information about layout in an application

b)

It has the information about activities in an application

c)

It has all the information about an application

d)

None of the above

79.

When developing for the Android OS, Java byte code is compiled into what?

a)

Java Source Code

b)

Dalvik Application Code

c)

Dalvik Byte Code

d)

C Source Code

80.

What is contained within the Layout xml file?

a)

Orientations and layouts that specify what the display looks like.

b)

The permissions required by the app.

c)

The strings used in the app.

d)

The code which is compiled to run the app.

81.

An activity can be thought of as corresponding to what?

a)

A Java Class

b)

A Java Project

c)

A method call

d)

An object field

82.

Src folder contain____files

a)

Java source code

b)

XML

c)

manifest

d)

None of these

83.

Q1) The activity life cycle does not contain.................

a)

onStart()

b)

onCreat()

c)

onAttach()

d)

onPause()

84.

What is the name of the layout file for the main activity?

a)

MainActivity.java

b)

AndroidManifest.xml

c)

activity_main.xml

d)

build.gradle

85.

What is the name of the string resource that specifies the application's name?

a)

app_name

b)

xmlns:app

c)

android:name

d)

applicationId

86.

What changes are made when you add a second Activity to your app by choosing File > New > Activity and an Activity template? Choose one:

a)

The second Activity is added as a Java class. You still need to add the XML layout file.

b)

The second Activity XML layout file is created and a Java class added. You still need to define the class signature.

c)

The second Activity is added as a Java class, the XML layout file is created, and the AndroidManifest.xml file is changed to declare a second Activity.

d)

The second Activity XML layout file is created, and the AndroidManifest.xml file is changed to declare a second Activity.

87.

onStart() method represents

a)

if the activity is at the background and still visible

b)

if the activity is not visible and therefore is hidden or obscured by another activity

c)

when the activity process is killed or completed terminated

d)

if the activity is at the foreground

88.

ConstraintLayout is a layout that defines the position for each view based on constraints to sibling views and the parent layout.

a)

True

b)

False

89.

Which Android Lifecycle method is recommended to set state in?

a)

onStop()

b)

onStart()

c)

onResume()

d)

onPause()

90.

This method is where you do all of your set up: creating views, etc.

a)

onPause()

b)

onStart()

c)

onCreate()

d)

onResume()

91.

The layer of the Android System Architecture is responsible for management of memory, power, devices, etc.

a)

Linux Kernel

b)

Native Libraries

c)

Android Runtime

d)

Application Framework

92.

A _______ is the user interface screen of your application. An application can have zero or more of these.

a)

Intent

b)

Bundle

c)

Activity

d)

Fragment

93.

These classes allow you to write to a file

a)

FileOutputStream and OutputStreamWriter

b)

FileOutput and OutputStream

c)

FileInputStream and InputStreamReader

d)

InputStream and OutputStream

94.

This layer in the Android System Architecture is responsible for the Webkit library

a)

Native Libraries

b)

Android Runtime

c)

Linux Kernel

d)

Application Framework

95.

An operating system (OS) built exclusively for mobile devices such as smartphones, tablets, PDAs, etc. Similar to a standard OS but is relatively simple and light.

a)

Windows Operating System

b)

Linux Operating System

c)

Macintosh Operating System

d)

Mobile Operating System

96.

It is created by Google, is one of the most commonly installed mobile OS for mobile devices, with support from various device manufacturers. It is an open source OS, which means developers are given access to unlocked hardware to develop new programs.

a)

Android

b)

Windows

c)

Linux

d)

Xamarin

97.

What is a key difference with the distribution of apps for Android based devices than other mobile device platform applications?

a)

Applications are distributed by Apple App Store only

b)

Applications are distributed by multiple vendors with different policies on applications.

c)

Applications are distributed by multiple vendors with the exact same policies on applications.

d)

Applications are distributed by the Android Market only.

98.

What is the driving force behind an Android application and that ultimately gets converted into a Dalvik executable?

a)

Java source code.

b)

R-file.

c)

the emulator.

d)

the SDK.

99.

It is a type of software that allows you to perform specific tasks.

a)

Driver

b)

System Software

c)

Application Software

d)

Desktop

100.

It is a software application designed to run on smartphones, tablet computers, and other mobile devices.

a)

Web App

b)

Desktop App

c)

Mobile App

d)

Android

101.

Your full Reg No and Name

4 lines