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

Multiple choice
  1. Android starts service and calls its onCreate method followed by the onStart method.

  2. onResume, onPause and onStop are not needed.

  3. As with an activity, the onDestroy method is called when the service is about to be terminated.

  4. onResume of activity life cycle is equivalent to onBind method of service.

  5. None of these

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

If a client needs a persistent connection to a service, it can call the Context.bind Service method, while onResume is called right after onStart if your activity is the foreground activity on the screen.

Multiple choice
  1. refer a possible value for the completion of a word or phrase typed into it

  2. check the spelling and grammar of the text

  3. auto correct the spelling text typed in TextView

  4. All of the above

  5. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

AutoCompleteTextView, as the name implies, is a modified TextView that will refer a possible value for the completion of a word or phrase typed into it.

Multiple choice
  1. g.drawLine(0, 4, 5, 16);

  2. canvas.drawLine(56, 0, 56, 100, paint);

  3. drawLine(4, 5, 6, 7);

  4. drawLines(x[], y[], count);

  5. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

canvas.drawLine(56, 0, 56, 100, paint); is valid in android.

Multiple choice
  1. worker thread

  2. UI thread

  3. service call

  4. foreground process

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Android, View.post(Runnable) executes the Runnable on the UI thread (main thread). This method is commonly used to update UI elements from background threads, as all UI operations must occur on the UI thread. The posted Runnable executes after the current message queue processing, ensuring thread-safe UI updates.

Multiple choice
  1. work on worker thread

  2. work on UI thread

  3. work on background thread

  4. work on foreground thread

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

onPostExecute runs on the main UI thread, allowing direct updates to UI elements without needing additional thread synchronization. This is different from doInBackground which runs on a background thread and cannot touch UI components.

Multiple choice
  1. android OS

  2. calling component

  3. onPostExecute(…) method of AsyncTask

  4. onProgressUpdate() method of AsyncTask

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

The return value from doInBackground is automatically passed as a parameter to onPostExecute, allowing the background result to be processed on the UI thread. This is the standard AsyncTask flow pattern.

Multiple choice
  1. Handler class

  2. View.postDelayed(Runnable, long)

  3. onPostExecute(…) method of AsyncTask

  4. Both (1) and (3)

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Both Handler class and onPostExecute() can execute code after background work completes. Handlers provide flexible timing control while AsyncTask's onPostExecute is specifically designed for post-background UI updates.

Multiple choice
  1. service is started through activity

  2. service binds with any component

  3. Both (1) and (2)

  4. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

onStartCommand() is called when a service is explicitly started using startService(). Binding with bindService() triggers onBind() instead. The two initiation methods have different lifecycle callbacks.

Multiple choice
  1. service is started through activity

  2. service binds with any component

  3. Both (1) and (2)

  4. None of these

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Service onCreate() is called whether the service is started via startService() or bound via bindService(). It's the initialization callback that runs once per service instance, unlike onStartCommand() which can run multiple times.

Multiple choice
  1. getSharedPreferences()

  2. getPreferences()

  3. Both (1) and (2)

  4. None of these

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The getPreferences() method (called without a name parameter) creates a single preferences file specific to that activity. In contrast, getSharedPreferences() requires a name parameter and can be shared across different activities or components.