Computer Knowledge
Java Core Classes and Threads
1,935 Questions
Java core classes and threads form the foundation of object oriented programming and are crucial for IT officer and programming exams. This includes concepts like string mutability, collections, and multithreading. Solve these questions to test your practical coding and theoretical knowledge.
String and StringBuffer classesThread execution methodsJava collections frameworkCharacter streams input outputVariable serialization rules
Java Core Classes and Threads Questions
-
onStart()
-
onResume()
-
onCreate()
-
None of above
C
Correct answer
Explanation
onCreate() is the first method called when an activity is created. It's where you initialize your activity, set up the UI with setContentView(), bind data, and create any objects or resources the activity will need. This method is called once per activity instance, unlike onStart() or onResume() which can be called multiple times.
-
onResume(), onStop()
-
onStart(), onStop()
-
onStart(), onDestroy()
-
onResume(), onDestroy()
-
None of above
B
Correct answer
Explanation
In Android activity lifecycle, onStart() indicates when the activity becomes visible to the user, and onStop() is called when it's no longer visible. Resources needed to display the activity to the user (such as views and UI elements) should be initialized in onStart() and released in onStop(). onResume() and onPause() are for foreground/interactive state, not visibility.
-
onCreate()
-
onResume()
-
onStart()
-
None of above
A
Correct answer
Explanation
The onCreate() method receives a savedInstanceState Bundle parameter that contains the activity's previously saved state. This state is captured in onSaveInstanceState() when the activity may be killed by the system. onResume() and onStart() do not receive this Bundle parameter.
-
Recovery scenerio
-
Recovery types
-
Exception handler
-
onexit
A
Correct answer
Explanation
QTP handles exceptions using Recovery Scenarios, which allow you to define trigger events, recovery operations, and post-recovery test run options. This is QTP's built-in mechanism for handling unexpected events, errors, or application crashes during test execution. Option C (Exception handler) is a general programming term but not QTP-specific.
-
wait
-
waitproperty
-
sleep
-
getproperty
B
Correct answer
Explanation
The waitproperty method is used for synchronization in QTP. It pauses test execution until a specified object property achieves a certain value or times out. This is the preferred synchronization method over static waits like wait() or sleep() because it waits dynamically based on application state rather than fixed time intervals.
-
Gettext
-
Getvisibletext
-
GetROProperty
-
All the above
D
Correct answer
Explanation
All the above is correct because different methods are used in different contexts to retrieve text values. GetROProperty retrieves runtime object properties including text, GetVisibleText captures visible text on screen, and GetText is used for retrieving text from specific objects. The appropriate method depends on the testing scenario.
-
When browser is closed
-
When the page reloads as well.
-
Only when you navigate out of the page.
-
All Of the Above
D
Correct answer
Explanation
The onunload event is triggered when the document is being unloaded from the browser. This includes closing the browser window, reloading the current page, or navigating to a new webpage. Since all these actions trigger the unload sequence, 'All Of the Above' is the correct choice.
B
Correct answer
Explanation
onreadystatechange is an event handler property of the XMLHttpRequest object, not a method. It's a property that you assign a function to (xhr.onreadystatechange = function(){}), not a method that you call. Methods are invoked with parentheses, properties are assigned values.
-
Bit-oriented
-
Byte-oriented
-
Character Oriented
-
1+2
-
2+3
-
All of these
-
void onCreate(Bundle savedInstanceState)
-
void onStart()
-
void onResume()
-
void onDestroy()
-
void onExit
E
Correct answer
Explanation
Android's Activity lifecycle includes standard callback methods such as onCreate, onStart, onResume, and onDestroy. There is no void onExit method in Java's Android Activity lifecycle class, making it an invalid method name, whereas the others are all standard, valid callbacks.
-
ContentResolver cr = getContentResolver();
-
ContentResolver cr = getContentResolver(cr);
-
ContentResolver cr = getContentResolver(content);
-
ContentResolver cr = getContentResolver(void);
-
ContentResolver cr = getContentResolver(context);
A
Correct answer
Explanation
getContentResolver() is the correct method to obtain a ContentResolver instance within an Activity or other application component. It takes no parameters and returns a ContentResolver object that can interact with content providers. The other options incorrectly pass parameters (cr, content, void, context) to this method.
-
query()
-
insert()
-
update()
-
delete()
-
onCreate()
-
mp.initialize();
-
mp.start();
-
mp.do();
-
mp.run();
-
mp.process();
B
Correct answer
Explanation
In Android, the MediaPlayer class uses the start() method to begin or resume playback of audio/video streams. The other listed options like initialize, do, run, or process are not standard methods of the Android MediaPlayer API for initiating media playback.
-
String str =”cocoa”;
-
NSString *str =@”cocoa”;
-
NSString str= “cocoa”;
-
NSString* str=@”cocoa”;
B
Correct answer
Explanation
In Objective-C, strings are declared using NSString class with the @ symbol before the string literal to indicate it's an Objective-C string object (not a C string). The correct syntax is NSString *str = @"cocoa"; where the asterisk denotes a pointer to the object, and the @ symbol creates an NSString object from the literal.
-
-(void) mouseUp: (NSEvent *) theEvent;
-
-(void) mouseDown: (NSEvent *) theEvent;
-
-(void) mouseDragged: (NSEvent *) theEvent;
-
-(void) mouseClick: (NSEvent *) theEvent;
D
Correct answer
Explanation
The standard mouse event methods in Cocoa are mouseUp, mouseDown, and mouseDragged. There is no 'mouseClick' method in the standard mouse event protocol - click events are typically derived from up/down combinations.