WorksheetsProgramming in Java
Total questions: 101
Worksheet time: 54mins
Which of the following option leads to the portability and security of Java?
Bytecode is executed by JVM
The applet makes the Java code secure and portable
Use of exception handling
Dynamic binding between objects
Which of these data types is used to store command line arguments?
a) Array
b) Stack
c) String
d) Integer
1. Which of this method is given parameter via command line arguments?
a) main()
b) recursive() method
c) Any method
d) System defined methods
What are the Type Conversions available in Java language?
A) Narrowing Type Conversion
B) Widening Type Conversion
A and B
D) None of the above
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) 66
B) A
C) B
D) 65
What is the output of the following code snippet?
int i = 0; for(i = 0 ; i < 5; i++)
{ }
System.out.println(i);
A. 5
B. 0
C. 4
D. Compilation Error
Application Program Interface is a prewritten code organized into packages
of similar topics in IDE.
True
False
IDE stands for Integral Development Environment
True
False
Function of the Scanner class to accept a float literal from the user is
nextInt( )
hasNext( )
next( )
nextFloat( )
Absence of _________ in switch..case leads to fallthrough
switch
case
default
break
The compiler of Java works on_______ to give _________.
Byte Code, Source Code
Source Code, Object Code
Source Code, Byte Code
Byte Code, Object Code
Predict the value of k,
int k =10;
k=k+k++;
11
20
21
22
Q) In java multi-threading, a thread can be created by
Extending Thread class
Implementing Runnable interface
Using both
None
Q) Which method is called internally by Thread start() method?
execute()
run()
launch()
main()
Q) Which method must be implemented by a Java thread?
run()
execute()
start()
None
Q) Which statements is/are correct (More than one is correct).
On calling Thread start () method a new thread get created.
Thread start () method call run () method internally
Thread run () method can also be called directly to create thread.
All correct
The life cycle of a thread in java is controlled by
JRE
JDK
JVM
None
Which method is used to get current running thread object?
runningThread()
currentThread()
runnableThread()
None
The start() method of an thread object will change the thread from _______ state to _______ state.
Ready to Active
Born to Ready
Ready to Wait
Active to Ready
What is the advantage of Exception Handling
To avoid abnormal termination of a program
To find out errors
To Debug program
None of these
What is the parent class of All Exceptions in JAVA
Throw
Exception
Error
Bug
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
How to create our own exception
using 'throw' keyword
using 'throws' keyword
using 'finally' keyword
using 'throwable' keyword
Exception classes belongs to following package
import java.io.*
import java.lang.*
import java.util.*
import java.lang.Exception.*
Which of these keywords is not a part of exception handling?
try
finally
thrown
catch
java.lang.NullPointerException is a
Error
runtime exception
Compile time exception
None
Which of these class is highest in hierarchy in java
java.lang.Exception
java.lang.Error
java.lang.Throwable
java.lang.Object
Choose the CORRECT exception
String department="JTMK";
Integer no=Integer.parseInt(department);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundsException
Choose an exception if attempt to divide number by zero
int number = 89 / 0;
System.out.println("The answer is " + number);
ArithmeticException
NullPointerException
NumberFormatException
ArrayIndexOutOfBoundException
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
B
AC
BC
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();
}
}
BD
BDE
BD
DE
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 */
}
}
ABCD
Compilation fails.
C is printed before exiting with an error message.
BC is printed before exiting with an error message
which one of the following is true?
runnable interface declares the start method
Thread.start() method is used to move a thread from a new state to the runnable state
Thread.runnable() method is used to move a thread from new state to the runnable state
Thread.run() method is used to move a thread from new state to the runnable state
superclass of all classes representing the output stream of characters is -------------
OutputStream
Reader
InputStream
Writer
which of this class is used by character streams for reading data from buffer
BufferReader
InputStreamReader
FileReader
FileInputStream
When will the else part of try-except-else be executed?
always
when an exception occurs
when no exception occurs
never
How many except statements can a try-except block have?
Zero
One
Two
Multiples
++ increases the value of a variable by 1
assignment operator
decrement operator
increment operator
sentinel
What would the new value of A be?
A=1;
a++;
1
2
3
4
What's the value of below?
int i=5;
System.out.println(i++);
System.out.println(i);
System.out.println(++i);
5
6
7
6
6
7
6
7
8
5
5
6
Which statement(s) are equivalent to i = i + 1?
i += 1
i++
i -= 1
i--
Which are the types of operators seen? Select as many you think
bitwise operator
subtraction operator
equality operator
arithmetic operator
what is modulo operation used for ?
performs division
performs division and gives no remainder
performs division and gives remainder
does not perform division
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 = 2 b = 3 c = 4 d = 1
a = 2 b = 3 c = 4 d = 1
Program does not compile.
a = 1 b = 2 c = 4 d = 2
ar, given the following declaration:int[] ar = {2, 4, 6, 8 }0, 1, 2, 31, 2, 3, 40, 2, 4, 6What is the first index of an array?
1
0
2
3
Identify the error that exist in this program segment:-
An array data type cannot be use as argument.
The argument was not in the right sequence with the parameter.
The variable name in parameter not as same with the argument.
Program consist 0 error.
What data type would you use to store names of students?
String
char
boolean
None of these
blonde
How would you declare a variable storing the tax rate?
int taxRate = 5.1;
taxRate = "5.1";
double taxRate = 5.1;
double taxRate = "5.1";
I do hereby declare thee Sir Tax Rate
Q) What is maximum thread priority in Java
10
12
5
8
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();
}
}
0
1
2
3
Which component represents the single screen with a user interface?
Services
Activities
Broadcast receiver
Content Provider
______ is a device configuration that runs on the Android Emulator.
Android Virtual Device
Android Visual Device
Android Emulator Device
APK Device
Which component supplies data from one application to others on request?
Services
Content Provider
Broadcast receiver
Activities
Which component runs in the background to perform long running operations?
Content Providers
Services
Broadcast receiver
Activities
Which tab shows all the tools useful for the app?
Tool Palette
Component Palette
Component Tree
Design Tab
Expand APK.
Application Programming Kit
Application Package
Android Programming Kit
Android Package
Which language is supported by Android Studio?
Python
Java
Kotlin
C/C++
Android is an open source and ______ Operating System for mobile devices.
Windows Based
Linux based
MAC based
Apple IOS
Identify the features of Android.
Web Browser
Multi-Tasking
Messaging
All of the above
What are the types of User Interface Theme?
Darker and Light
Black and White
Black and Gray
Darker and White
___ are the objects which is used in android for passing the information among Activities in an Application
Services
Intents
Broadcast
Activity
The full form of URI is ____
Uniform Resource Input
Uniform Resource Identifier
Uniform Resource Locator
Uniform Resource Identity
What language used in Android Studio?
Java
C#
HTML
Android Studio
All smartphone have application
Yes
No
Android is based on which kernel?
Linux
Mac
Windows
Symbian
In which directory XML layout files are stored?
/res/drawable
/src
/res/values
/res/layout
During an activity life cycle, what is the first callback method invoked by the system?
onStart()
onCreate()
onPause()
onStop()
What is Manifest.xml in android?
It has information about layout in an application
It has the information about activities in an application
It has all the information about an application
None of the above
When developing for the Android OS, Java byte code is compiled into what?
Java Source Code
Dalvik Application Code
Dalvik Byte Code
C Source Code
What is contained within the Layout xml file?
Orientations and layouts that specify what the display looks like.
The permissions required by the app.
The strings used in the app.
The code which is compiled to run the app.
An activity can be thought of as corresponding to what?
A Java Class
A Java Project
A method call
An object field
Src folder contain____files
Java source code
XML
manifest
None of these
Q1) The activity life cycle does not contain.................
onStart()
onCreat()
onAttach()
onPause()
What is the name of the layout file for the main activity?
MainActivity.java
AndroidManifest.xml
activity_main.xml
build.gradle
What is the name of the string resource that specifies the application's name?
app_name
xmlns:app
android:name
applicationId
What changes are made when you add a second Activity to your app by choosing File > New > Activity and an Activity template? Choose one:
The second Activity is added as a Java class. You still need to add the XML layout file.
The second Activity XML layout file is created and a Java class added. You still need to define the class signature.
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.
The second Activity XML layout file is created, and the AndroidManifest.xml file is changed to declare a second Activity.
onStart() method represents
if the activity is at the background and still visible
if the activity is not visible and therefore is hidden or obscured by another activity
when the activity process is killed or completed terminated
if the activity is at the foreground
ConstraintLayout is a layout that defines the position for each view based on constraints to sibling views and the parent layout.
True
False
Which Android Lifecycle method is recommended to set state in?
onStop()
onStart()
onResume()
onPause()
This method is where you do all of your set up: creating views, etc.
onPause()
onStart()
onCreate()
onResume()
The layer of the Android System Architecture is responsible for management of memory, power, devices, etc.
Linux Kernel
Native Libraries
Android Runtime
Application Framework
A _______ is the user interface screen of your application. An application can have zero or more of these.
Intent
Bundle
Activity
Fragment
These classes allow you to write to a file
FileOutputStream and OutputStreamWriter
FileOutput and OutputStream
FileInputStream and InputStreamReader
InputStream and OutputStream
This layer in the Android System Architecture is responsible for the Webkit library
Native Libraries
Android Runtime
Linux Kernel
Application Framework
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.
Windows Operating System
Linux Operating System
Macintosh Operating System
Mobile Operating System
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.
Android
Windows
Linux
Xamarin
What is a key difference with the distribution of apps for Android based devices than other mobile device platform applications?
Applications are distributed by Apple App Store only
Applications are distributed by multiple vendors with different policies on applications.
Applications are distributed by multiple vendors with the exact same policies on applications.
Applications are distributed by the Android Market only.
What is the driving force behind an Android application and that ultimately gets converted into a Dalvik executable?
Java source code.
R-file.
the emulator.
the SDK.
It is a type of software that allows you to perform specific tasks.
Driver
System Software
Application Software
Desktop
It is a software application designed to run on smartphones, tablet computers, and other mobile devices.
Web App
Desktop App
Mobile App
Android
Your full Reg No and Name
