SlideShare a Scribd company logo
1 of 18
Download to read offline
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Java Interview Questions
1. What is JVM?
Java virtual machine. This is a software component. This is where every java application will run.
2. What is platform independency?
Java applications are platform independent. That means once you write (compile) your java application, it can
run on any system (platform).
3. Is JVM platform independent?
No, JVM is platform dependent. Because every platform needs its own JVM.
4. What all the components of JVM?
JIT Compiler (Just In Time compiler), byte code verifier, class loader, garbage collector, memory manager, and
thread pool manager.
5. What is JRE ?
Java Run time Environment. It is a software component. An environment where java applications will run. Clients
needs JRE to run an application. Without JRE you can’t run a java application.
6. Then what is JVM? Will java applications run in jvm or jre?
JVM is part of JRE. Finally java applications will run in JVM only.
JRE = JVM + Standard java libraries.
7. What is JDK?
It is software which is used by java developers to write java programs.
JDK = java software framework libraries + java compiler + javae + JRE.
Note : When you download JDK, it comes along with JRE internally. You don’t have to download JRE separately.
8. What does javac (java compiler) will do?
Compiler checks if there are any syntax mistakes in your java program. If there are no errors then java compiler
generates a .class file (which is also known as byte code).
9. What is the responsibility of JVM?
JVM will convert byte code (.class file) into CPU understandable format.
10. Who will load java program into memory?
JVM’s class loader will load java program into memory.
11. What is String constant pool?
It is an area in memory (RAM) where string objects will be stored.
12. How to create objects in java?
By using “new” operator.
Note: new operator creates objects in heap location.
13. What is the use of creating object?
After creating object we can access data members and functions of that object using dot operator.
14. What is a class?
Class is a blue print or model using which we create objects. Class is also called as virtual entity. Class is stored in
code segment.
15. What is an object?
Object is a real entity which has some data and behaviour (functions). Objects are stored in heap memory.
16. What is the use of a class?
Class is used to create object. Without class we can’t create objects. Class acts as a model to generate objects.
17. What is encapsulation?
Binding related data and functions in a common unit, is called as encapsulation.
Wrapping up of data and functions together in a class, is also called as encapsulation.
Hiding data members by using private access modifier, and exposing private data by using public methods
(getters and setters) is called as encapsulation. Note: This is the practical use of encapsulation.
18. How do you achieve data security in java?
By using encapsulation feature, and with private access modifier.
19. What is abstraction?
Presenting essential features and hiding un-essential features, is abstraction.
Showing required details, and hiding un-necessary details, is also called as abstraction.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
In terms of OOPS, hiding implementation details and presenting only function declarations to outside world, is
abstraction. Abstraction is better understood by using interfaces.
20. How encapsulation differs from abstraction?
Encapsulation is a way to achieve data security.
Abstraction is a way to hide un-necessary details.
Since encapsulation hides private data from outer class, so you can say encapsulation is data abstraction. You are
hiding data members details from outer classes.
21. What is the advantage of using encapsulation?
You achieve data security by using private access modifier.
You achieve readability and maintainability by clubbing related data and functions into common class.
22. Give some real example for abstraction?
When you press remote, it switches on TV. How it is working internally is hidden (abstracted) for normal persons.
When you press a switch, it turns on FAN. How it is working internally is abstracted (hidden) for normal persons.
23. What is constructor?
It is a special function, used to construct an object. Here construct means initialize object with data.
Constructor is used to initialize data to instance variables.
24. Who creates object new operator or constructor?
New operator. Constructor will be called after new operator creates object.
25. Can a constructor have return type?
No, constructor should not have return type. Else it is considered as normal function.
26. Can I have private constructor?
Yes. It is useful in singleton design pattern. It is also useful to stop others to inherit your class.
27. What is the difference between instance variable and static variable?
Instance variables are separate for each object, static variables are common for all objects of that class.
Eg: tooth brush is instance variable because every person in the family has his own brush.
TV is a static variable, because all persons in the family use common TV.
Note : instance variables will be stored in heap, where as static variables will be stored in data segment.
Note: instance variables will be created when ever a new object is created, where as static variable will be
created only once, when you load that class into memory.
Note: How many no of objects are there, that many no of instance variables will be there, where as only one copy
of static variables will be shared will all objects.
Note : instance variables should be accessed with objects, where as static variables can be accessed with class
names also. (provided they are not private).
28. What is singleton pattern?
Having only one object for a class is called as singleton pattern.
29. What is access modifiers or access specifiers.
There are 4 access modifiers in java. They are private, default, protected, public.
They are used to control who can access your class members. By using private only your class can access.
By using public any other class can access your class members. By giving nothing (default) only your package
classes can access class members. By giving protected, your package classes and any other subclass can access
members.
30. Can I have private class?
No, unless if it is an inner class. Class within a class is called as inner class or nested class. Outer classes can be
only public or default.
31. What is inheritance?
Inheriting or acquiring members of one class to other class is called as inheritance. In java it is possible by extends
keyword.
32. What is the use of inheritance?
Inheritance reduces code duplication. Inheritance is used as a tool to achieve “code reusability”.
Inheritance also plays an important role in achieving polymorphism.
33. What is polymorphism?
One variable referring different objects at run time is considered as polymorphism, in oops.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
34. What are the different types of polymorphisms?
(Stupid question)
Static polymorphism and dynamic polymorphism.
Note : In OOPs when we use polymorphism term, it always means dynamic polymorphism.
Note: To satisfy some interviewers you can say method overloading is static polymorphism and method
overriding is dynamic polymorphism.
35. How to achieve dynamic polymorphism?
By using method overriding we achieve it. (To satisfy interviewers)
In reality we achieve polymorphism by using inheritance / abstract class/ interface + method overriding + up
casting.
36. What is the use of polymorphism?
To reduce code dependency. To write independent modules.
37. What is concrete class?
A class for which we can create object.
38. What is abstract class?
An incomplete class. Just like an incomplete building which is under construction.
You can’t create object for an abstract class.
A class which contains 0 or more no of abstract methods can be made as abstract class by using abstract
keyword.
Note : If a class contains at least one abstract method, that class should be made as abstract class.
39. What is the use of abstract class?
To share common functionality to related classes in inheritance hierarchy, we use abstract class.
To enforce some functionality to be implemented by sub classes, we use abstract classes.
Note : As mentioned already, they play important role in achieving polymorphism.
Note : The only purpose of abstract class is to be extended by some other class and give full implementation of
abstract methods.
40. What is concrete method?
A method with body.
41. What is abstract method?
A method without any body. Method with only signature. To create abstract methods we use abstract keyword.
42. What is an interface?
It is just like a class, but without any function bodies.
43. What an interface can contain?
Only constants, method declarations, and nested types.
Note: from JDK 1.8 onwards interfaces can contain methods with bodies (referred as default methods).
Note: from JDK 1.8 onwards interfaces can have static methods with bodies.
44. What is the use of interfaces?
It is a way to achieve abstraction in Java.
To hide implementation details we use interface as a tool.
Interfaces are used mostly when you are writing some libraries or server side code, and to hide your code from
clients.
Interface can be used as a tool to share or enforce some common functionality to un-related classes.
Note : abstract classes are used to share common functionality to related classes.
Interface is used as a tool to achieve multiple inheritance of classes in java.
45. Does java support multiple inheritance?
Yes, it supports multiple inheritance of interfaces.
No, it won’t support multiple inheritance of classes.
46. Some real world example of interface? (Stupid question)
Switch is interface between you and fan. Remote is interface between you and TV.
47. What is static method?
A method which can be accessed directly with class name. It is used to read private static variables. It can also
used to write some utility methods like ones in predefined Math class’s random() method.
Note : Static methods assumed to be faster than instance methods.
48. Can you access instance variables in static methods?
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
No.
Note: but instance methods (non-static methods) can access both instance variables and static variables.
49. What is final variable?
It is like a constant. Once you assign a value to final variable, you can’t change it.
50. What is final method?
A method which can’t be overridden in child class.
Eg: Many of the Object class methods are final methods. Eg: wait(), notify(), notifyAll(). They are final methods.
51. What is final class (immutable class)?
A class which can’t be inherited or extended.
Eg: String class is final class. All wrapper classes are final classes.
Wrapper classes are – Integer, Float, Boolean, ...
By default all methods of final class will become final methods. (But not variables).
52. What is immutable object?
An object whose states (Data) can’t be modifiable once assigned.
Eg: String object is an immutable object.
53. What is method overloading?
Multiple methods having same name but different parameters, in a class, is called as overloading.
54. What is method overriding?
Having same method in parent class and child class
With same method name + same parameters + same or covariant return type + same or higher access modifier.
55. Can I overload constructor?
Yes. But you can’t override constructor as it is inherited to child class.
56. How to call super class constructor?
Using super() keyword. Pass parameters in super if parent class constructor expects some parameters.
57. How to call same class constructor?
Using this() keyword.
58. How to call parent class overridden method?
Using super keyword.
59. What is the difference between StringBuilder and StringBuffer?
Builder is not synchronized, buffer is synchronized.
Builder can be used only with single thread, buffer can be used with multiple threads.
60. How will you catch run time errors in your project?
By using try-catch blocks.
Run time errors means exceptions.
61. Tell me different types of exceptions?
Checked exceptions & un checked exceptions.
62. Give examples for checked an dun checked exceptions?
Checked exceptions  IOException, JSONException, SQLException, FileNotFoundException, SocketException,
HTTPRetryException.
Unchecked Exceptions  NullPointerException, ArrayIndexOutOfBoundsException, IOError, ..
63. Difference between checked and un-checked exceptions?
Programmer should handle checked exceptions.
Programmer need not handle un-checked exceptions.
64. How do you handle checked exceptions?
There are 2 ways.
a. By using try-catch block
b. By using throws
65. What is throws and throw?
Throws keyword is to throw an exception to parent method.
Throw keyword is to re-throw an exception to parent method, after catching/handling that exception.
66. What will happen if you don’t handle checked exceptions?
Compiler will throw error.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
67. What is IOException?
IOException occurs mostly when there is problem in reading or writing data from one place to other place.
Eg: While reading data from file, if data is corrupted then it will throw IOException.
Eg: While reading data from internet connection, if connection is closed it will throw IOException.
68. What is FileNotFoundException?
While opening a file, if file is not there or if directory is not there, or if file path is wrong, it will throw this
exception.
69. What is collections in java?
Collection is a container which can hold any type of data. It is similar to data structures in c language.
70. Is collection same as array?
It is more powerful than array.
Collections are containers which can store any type of values.
Collections are containers which are dynamically growable.
Collections are containers which contains lot of predefined methods to read, insert, delete, add, and modify
elements of container very fastly.
71. What is collection framework?
It is a predefined library which comes along with JDK software. Collection framework contains 3 parts interfaces,
implementations, and algorithms.
Collection framework is the software implementations of collections.
Collection framework contains lot of predefined classes with complete implementation of many data structures
[collections] which are used to store temporary data.
72. What is ArrayList?
ArrayList is a collection[container] of elements. ArrayList allows duplicate elements to be stored.
ArrayList is ordered collection of elements. The way you insert elements, it will be read in same order.
73. What is Set?
Set is a collection [container] of elements. Set doesn’t allow duplicate elements to be stored.
Set is unordered collection of elements. The order in which elements are stored can’t be predictable.
74. What is Map?
Map is container which stores key, value pairs.
75. Which set is fastest?
HashSet is faster than LinkedHashSet and TreeSet.
76. What is the difference between HashSet, TreeSet, and LinkedHashSet?
HashSet – Unordered collection of elements. Internally uses Hashmap to store set values.
TreeSet – It maintains ascending order of elements. Internally uses red-black tree to store set values.
LinkedHashSet – It maintains insertion order of elements. Internally uses linkedlist with hashmaps to store
elements of set.
77. What is the difference between set and list? (or difference between hashset and arraylist).
Set - is unordered collection of elements. Sets won’t allow duplicate elements.
List – is ordered collection of elements. List allows duplicate values.
78. Does set allow null values?
Any set allows only one null element.
Note : List allows multiple null elements.
79. What is the difference between Arraylist and linkedlist?
They are 2 different implementations or types of lists.
ArrayList – store elements in sequential order, in contiguous memory locations. In most of the cases this is faster
than linked list.
Linked list – stores elements in non-sequential order. i.e will not store elements in contiguous memory locations.
Internally it uses something called as nodes and references (pointers).
80. Difference between vector and arraylist?
Vector – by default synchronized. Vector is deprecated, better not to use.
Arraylist – by default not synchronized. Arraylist is the replacement for vector.
81. Difference between hashtable and hasmap?
HashTable – by default synchronized. It won’t allow null key and null values. It is deprecated, better not to use.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
HashMap – by default not synchrnoized. It is the replacement for hashtable. It allows one null key and multiple
null values.
82. Difference between collections and generics?
ArrayList al = new ArrayList();  this is collection.
ArrayList<String> al = new ArrayList<String>();  This is generic.
Collection  No type safe. It was used before jdk 1.5 version when generics concepts were not introduced.
Generic  more secured and type safe. Introduced in jdk 1.5 version. Always prefer to use generics in place of
collection.
83. Difference between map and dictionary?
Dictionary is an abstract class, which implements map interface. It is deprecated. It is same as hashmap.
HashMap is the replacement of dictionary.
84. What is iterator?
It is an interface, with which we can traverse to all elements of any collection.
Using iterator you can fetch elements of set or list or map.
85. What is listiterator?
It is a subtype of iterator. Using this you can traverse and access elements of arraylist or linkedlist.
86. What is the difference between iterator and listiterator?
Iterator is used only for one way traversal. Can be used with any type of collection.
Listiterator has the capacity of two way traversal. Can be used only with list types.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Android Basic questions
87. What is DVM?
Dalvik Virtual Machine. It is not hardware component. It is a software.
88. What is the use of DVM?
Just like java programs runs in JVM, android applications runs in DVM.
89. Does each application has its own DVM?
Yes.
90. How is DVM different from JVM?
JVM is heavy which takes more memory and cpu time, DVM is light weight which is suitable for mobile phones.
DVM follows register based architecture to execute fastly. JVM follows stack based architecture which is slow.
91. What is ART?
ART = Android Run Time. This is the advanced version of DVM. From android 5.0 version onwards android
applications runs in ART, not in DVM. From android 5.0 version onwards there is no more DVM.
92. How is ART different from DVM?
ART is almost 4 times faster than DVM. DVM was using JIT compilation process, where as ART uses AOT
compilation process, which makes it more faster. AOT = Ahead Of Time compilation.
93. What are the major changes in android 5.0 version?
DVM is replaced with ART.
ListView gets more faster with RecyclerView.
Whole design changed with Material design concept.
94. Draw android architecture.
It contains 4 layers. OS layer, Libraries layer, Android framework layer, application layer.
95. Android is based on which operating system?
Linux operating system.
96. What are the versions of android?
1.5 Cupcake, 1.6 Donut, 2.0-2.1 Eclair, 2.2 Froyo, 2.3.x GingerBread, 3.0-3.1-3.2 HoneyComb,
4.0.x IceCreamSandwitch, 4.1-4.2-4.3 JellyBean, 4.4.x Kitkat, 5.0-5.1 Lollipop, 6.0 MarshMallow.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Activity , Fragment, and UI related questions
1. What is an Activity?
Ans. Each screen in android application is called as an Activity. Activity is a visible component of android.
Activity life cycle:
2. What is a fragment?
Ans. Fragment is a modular and reusable component of an activity. It can also be called as sub-activity.
3. What is the advantage of using fragments in application?
Ans. Fragments are used to build application compatible with mobiles, tablets, watches, and autos. Different devices will
have different screen sizes, and Application should fit properly in different screen sizes. This is possible by using fragments.
4. Can you tell me other advantages of using fragments?
Ans. You can build dynamically changing UI, by using fragments.
5. What is the difference between activity and fragment?
Ans. Each screen is called as activity. Fragment is part of an activity. An activity can contain 0 or more number of
fragments. Fragment doesn’t exist without an activity.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
6. What is Intent?
Ans. Intent is used to start activity or to start a service or to send a broadcast.
7. How will start an acitivity?
Ans. Create an intent, and use startActivity(intent) method.
8. How to pass data from one activity to other activity?
Ans. Use putExtra() method to pass data between one activity to other activity.
9. What is startActivityForResult() ?
Ans. If you are expecting some data from child activity to parent activity use this.
10. How to close/ stop/kill an activity?
Ans. Use finish() method to kill an activity by itself. You can also finishActivity() method to kill child activity.
11. Which layout is deprecated?
Ans. Absolute layout.
12. Which layout is better to use? Linear or relative?
Ans: Always preferable to use linear layout. Relative layout has chained dependency which may corrupt your design if you
try to modify it.
13. How will you build application compatible for both mobile phones and tablets?
Ans. Consider below points while designing applications for both phones and tablets.
a. Use dp and weights in place of px (pixels).
b. Don’t use absolute layout, consider using linear layout with weights.
c. Adjust font sizes for different screen sizes using sp (scale independent pixels). Put font sizes in values-sw folder
as required.
d. Prefer using 9-patch images so that your images stretch properly on bigger screens.
e. Strongly recommended to use “fragments” so that your application fits properly on different screen sizes.
f. Support different screen densities by supplying different image resolutions in different drawable folders.
g. Example : for medium density phones supply icon with size 48*48 pixels, for high density phones supply icon with
size 72*72 pixesl, for extra high density phones supply icon with size 96*96 pixels, for extra-extra high density
devices (tablets) supply icon with size 144*144 pixels. So that your icons looks proper on different screen
densities with different resolutions.
h. Avoid using relative layouts as well, as future modifications for your screen might become cumbersome. It uses
relative position which is dangerous if screen contains too many components.
i. User material design to have unanimous feel of your app design on different devices.
14. Can one application have 2 launcher activities ?
Ans: yes. It is possible. Go to manifest xml file, put below intent filters for whatever activities to be made as launcher.
<intent-filter>
<action android:name=”android.intent.action.MAIN”/>
<category android:name=”android.intent.category.LAUNCHER/>
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
</intent-filter>
15. Does each instance of an application contains its own instance of dalvik virtual machine?
Ans : yes.
16 . What is onSaveInstanceState() method?
Ans : This is a life cycle method of activity, which will be called if there is any configuration change to your phone (eg :
rotating phone, changing language settings). This method will also be called in case of low memory in your application.
17. How a programmer should handle this method? What to do in this method?
Ans : If programmer has any transient data to be saved in the application, save it in this method.
18. Can we save database in onSaveInstanceState() method?
Ans : Don’t save database changes in this method. Use onPause() method to save database changes and other persistent
data changes.
19. Is it possible to have an activity without UI?
Ans: Yes it is possible.
20. Can you create UI of an activity without using xml file?
Ans: Yes it is possible. Eg: Button b = new Button(this);
b.setText(“Hello world”);
setContentView(b);
21. What is context?
Ans: There are 2 types of contexts in android.
a. This context
b. getApplicationContext()
Mostly we should use this context, and never getApplicationContext(). This context is available only for activity, service and
contentprovider.
22. What is the purpose of context?
Ans : Context is used to create new resources in your application. Context is used to start other components. Context is
used to access your application resources.
23. what is px, dp, dip, dpi, and sp?
Ans : px is pixel, dp is density independent pixel, dip is also density independent pixel, dpi is dots per inch on the screen,
and sp is scale independent pixels.
Note : Never use px, it is deprecated. To specify width and height use dp. For font sizes use sp. Dpi is used while measuring
density and resolution of the phone.
24. What is the difference between linearlayout and relative layout?
Ans : Linear layout is used to align views either horizontally or vertically. Relative layout is used to align views in relative to
each other.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
25. What is weight property?
Ans : weight property is used to distribute views on the screen area based on proportions.
26. what is the difference between gravity and layout gravity?
Ans: gravity is to align view content with in the view. Layout gravity is used to align view within the parent view.
27. what is the difference between padding and margin?
Ans : Padding is used leave space between view content and view border. Margin is used to leave space between view
border and parent view or other peer views.
28. what is the purpose of weightsum?
Ans: weigt sum is not preferred to use. It is equal to sum of different view weights used in your layout. If you use
weightsum, then future modifications for your screen design will be difficult. Every time you do some change to your
design in future, you have to make sure to modify weightsum also, else it leads to wrong design.
29. Give some examples for layouts in android?
Ans: linear layout, relative layout, frame layout, table layout, absolute layout (deprecated).
30. Give some examples for adapter views in android?
Ans: ListView, GridView, Gallery (deprecated), ExpandableListView, AutoCompleteTextView, Spinner, CardView,
RecyclerView.
31. What is the parent class for activity?
Ans: Either Activity or FragmentActivity or ActionBarActivity.
32. What all the lifecycle methods of custom adapter?
Ans: getCount(), getItem(), getItemId(), getView().
33. How will you write a custom adapter?
Ans : Mostly we will create custom adapter by creating our own class by extending BaseAdapter class.
34. What is Bundle?
Ans: Bundle is a data holder, which is used to pass data between 2 activities. Bundle will also be useful while saving states
in onSaveInstanceState() method.
35. How will you start other applications from your activity?
Ans : Using Intent and startActivity() method.
36. How will you start gallery application from your activity, to get an image from the gallery?
Ans : Intent in = new Intent();
In.setType(“image/*”);
In.setAction(Intent.ACTINO_GET_CONTENT);
startActivity(in);
37. What is an Intent?
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Ans: Intent is used for 2 purposes.
a. Using Intent you can start an activity or service or broadcast receiver components.
b. Using intent you can pass data between 2 components in android.
38. What is an IntentFilter?
Ans : Intent filter is counter part for intent.
Using intent a component can tell what type of actions it can handle.
38. What is pendingIntent?
Ans : An intent which will be fired or triggered at future point of time by either alarm manager or notification manager on
behalf of your application.
39. What is ListActivity?
Ans : Its a predefined class of android, which used if you want only listview in your activity. This class will return a listview
automatically.
40. What is ListFragment?
Ans : If you want only a listview in your fragment then your fragment class should extend this class. It is exactly like
ListActivity.
41. What is ViewHolder pattern?
Ans : It is an efficient way to display items in listview.
Service, AsyncTask & Thread related questions
1. What is a service?
Ans. Service is an invisible component of android, which is used to do background operations/ tasks.
Eg1: Playing songs in the background is done by service.
Eg2: Uploading or downloading movies/ files over internet is also a background task which is done by service.
Note: Any task which is not visible to user is done by a service, in android. Or any task which should run in background
irrespective of an activity, is done by a service.
2. What is a thread?
Ans. Thread is a component of operating system, which is used to do background operations/ tasks. Thread is also known
as “light weight process”, because thread lies in a process.
3. What is the different between service and thread?
Ans. Service is component of Android framework. Thread is component of Operating system.
Service will internally use thread to do background task. Without thread, service is useless. If you try to create a service
without thread, it may lead to ANR error.
4. What is ANR ?
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Ans : Application Not Responding. It is an error thrown by Android O.S if touch events are not handled within the time limit
of 5 seconds. This will happen mostly when programmer tries to use main thread for activities and services. To avoid this
error, when programmer creates a service, you should create a thread for that service.
4. What is IntentService?
Ans. It is a predefined class of android, which is used to create a service with single thread.
5. How to create service with multiple threads?
Ans. Use AsyncTask class inside your service class.
6. What is AsyncTask?
Ans: It is a predefined class given by Android framework to create threads easily, in android applications.
7. What is the difference between Thread class and AsyncTask class?
Ans : Thread class is a complicated way to create threads. AsyncTask is an easy way to create threads.
From a thread we can’t touch UI directly. But from AsyncTask we can touch UI from onPreExecute(), onProgressUpdate(),
and onPostExecute() methods.
8. Is it impossible to touch UI from normal thread?
Ans : It is possible, but complicated. You should use either runOnUIThread() method or you should use Handler concept to
touch UI from non-ui threads.
9. What all the life cycle methods of AsyncTask class? What all the callback methods of AsyncTask?
Ans : onPreExecute(), doInBackGround(), onProgressUpdate(), onPostExecute().
10. In above methods which method runs in back ground thread?
Ans: doInBackground() method runs in background thread. Note: Don’t touch UI from this method.
11. How to start an AsyncTask?
Ans: Create an object for asynctask class, and call execute() method.
12. How to pass some data to doInBackGround() method?
Ans: You can pass data to doInBackGround() by supplying some parameters to execute() method of asynctask class.
13. Can I use AsyncTask class with activities and fragments?
Ans : You can use it anywhere.
14. What is HandlerThread?
Ans: HandlerThread is same as normal java thread, but only difference is HandlerThread contains an extra component
called as Looper to dispatch events from MessageQueue.
15. How will you create an application to connect to internet?
Ans : Take internet permission in manifest file.
Create a service.
Create an asynctask inside the service class.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
In doInBackGround() method write logic to connect to network.
16. What all the lifecycle methods of a service class?
Ans: onCreate(), onStartCommand(), onDestroy(), and onBind().
17. What is onBind()?
Ans : This method is used while implementing binder services?
18. How many types of services are available in android?
Ans : 2 types. Started services and binder services.
19. What is the difference between started service and binder service.
Ans : Started service is used to do a background task which doesn’t return any value to the client.
Binder service is something like a client-server architecture where client can send request and server will respond with
response.
20. How to start and stop a service?
Ans: Using Intent and startService() method we can start a service. A service can be stopped in 2 ways. Others can stop a
service by using predefined method stopService(intent). A service can kill itself by using stopSelfResult(resultid) method.
21. What are the disadvantages of IntentService?
Ans: Programmer can’t touch UI from intent service. It is a single threaded service.
Note : Programmer can still use Handler concept to touch UI from IntentService class.
22. What is a binder service?
Ans : Binder Service is a client server architecture, where clients can send request to binder service, and binder service will
respond back with some data.
23. What is AIDL?
Ans : Android Interface Definition Language. To create binder services with IPC mechanism we use aidl file. Aidl file
contains an interface with publicly exposed methods.
24. How to implement binder services?
Ans : If binder service is used by same application, then use binder class and return binder class object from onBind()
method.
If binder service is used by other applications then create an aidl file, and implement aidl files stub, and return stub’s object
from onBind() method.
25. What is the difference between activity and service?
Ans : Both are components of android. Activity is used to write logic for visible components (Screens). Service is used to
write logic for invisible components (back ground tasks).
Note : It is not mandatory that activity should have UI. But it makes more sense to use activity for visible components.
26. What is the difference between service and receiver?
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Ans : Both are components of android. Service is used to do heavy back ground tasks. Receiver is used to receiver
broadcast announcements from system, and to do a small light weight task in the back ground with in a time limit of 10
seconds. Both components should not have UI.
Eg : To play songs in back ground we use service.
Eg : To receive incoming message announcements , or to receiver battery low announcements , and to listen for other
important system level events we use receiver.
27. Life cycle methods of a service?
Ans : for started service -> onCreate(), onStartCommand(), onDestroy().
For binder service -> onCreate(), onBind(), onDestroy().
28. Life cycle methods of an intentservice?
Ans : constructor() and onHandleIntent().
29. What is the disadvantage of IntentService?
Ans: You can’t touch UI from intent service as it runs in separate thread.
30. Is there no way to access UI elements from IntentService directly?
Ans: It is possible by using runOnUIThread() or handler mechanism.
31. How to access UI elements from service?
Ans: Create a dynamic receiver in activity. Send a broadcast from service to trigger activity’s receiver. Then from receiver
touch UI components.
32. What is binder?
Ans : Binder is an IPC mechanism used in android.
IPC = Inter process communication.
33. What are the other IPC mechanisms available, apart from binders?
Ans : Apart from binder, generally java programs uses Serialization concept for IPC mechanism.
34. How binder is different from serialization?
Ans : Binder IPC is faster than Serialization. Because binders internally uses shared memory concept which makes it more
faster to transfer data between 2 processes.
Note : Binder internally uses Parcel concept to transfer data between 2 processes.
35. What is parcelable and serializable?
Ans : Those are 2 different mechanisms to convert object into bits and bytes. To transfer object’s data from one process to
other process, object should be chopped into byte stream. For that we can use either parcelable concept or serializable
concept.
36. What is the internal mechanism of binder IPC?
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Ans: Binders internally uses parcelable to convert objects into byte stream and uses shared memory concept to transfer
this byte stream to other process. Binder internally uses parcelables which has less restrictions while parcelling and
deparcelling unlike serialization. Due to many checks at deserialization it makes it slow.
36. What are the other differences between parcelable and serializable. Which one we should use in android?
Ans : Since android is meant for smaller and light weight devices, you should always opt for light weight and faster
technique to transfer data.
Note : Serializable and Parcelable are 2 predefined interfaces.
Parcel data is much more light weight and faster than serializable data. So go for parcels.
37. But we pass data from one application to other application in android with Bundle?
Ans: Bundle internally uses parcels as well to send data fastly.
Note: As an android developer use always bundles to pass data between components or applications. As bundle internally
uses parcels, it transfers data fastly. You should minimize the use of parcels and serializables directly in your code.
38. How to transfer an object from one activity to other activity?
Ans: In this case you can use parcelable and put it in bundle and send bundle to other activity.
39. Can I put serializable objects in a bundle?
Ans: Yes, you can. But not recommended, as it is slow.
40. How to create a serializable object?
Ans: To create a serializable object, class of that object should implement Serializable interface.
41. What is serialization?
Ans: The process of converting objects into byte stream is called as serialization.
42. What is the use of serialization?
Ans: It is a good approach to store some objects in files or to pass some objects from one place to other place.
43. What is serialization and deserialization?
Ans: You can think of it like this. If you want to send some luggage from one place to other place, you will compress the
luggage into an auto, and you will decompress that luggage and restore into a new house.
Similarly if you want to send some object’s data from one place to other place, then first we have to compress into some
universal format(ie bits and bytes). That is serialization. It is the process of converting object into byte stream.
And Deserialization(decompressing) is the process of regenerating object from that byte stream and restoring that object’s
data.
44. How to enforce security on services?
Ans: Use exported attribute to false, so that other applications can’t trigger your receiver.
Or set some permissions on your service, so that to trigger your service they need the permission.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
45. I want to create a service to do a background task. Should I use Thread class or AsyncTask class?
Ans: Always use AsyncTask class. Because it is a comfort way to create threads in android. It has advantage of touch UI
elements.
46. What is the difference between handler and asynctask?
Ans: Handler is mechanism used to communicate with Handler Threads. AsyncTask will internally use Handler concept to
communicate with main thread, in onPreExecute(), onProgressUpdate(), and onPostExecute() methods. Handler
mechanism is internally used by asynctask to communicate to main thread for UI updations from back ground thread.
47. What is the purpose of doInBackground() method in AsyncTask class?
Ans: That method will run in back ground thread. If programmer want to do some heavy back ground task like connecting
to internet, download or upload some file, or data base transactions then use that method.
Database related questions
1. How will you store data in your application?
Ans. There are many ways to store data in android application.
a. You can use sharedpreferences to store small amount of data in your phone.
b. You can use database to store huge amount of data in your phone.
c. You can save data in internal memory or external memory (sd card).
d. You can save data in a server also using internet connection.
2. What is sharedpreferences?
Ans. Sharedpreferences is also called as preferences. It is an xml file which is used to store small amount of data in your
phone. Eg: To store username and password we can use preferences as it is small amount of data.
3. Where do sharedpreference files will be stored?
Ans. It is stored in the internal memory of your phone. When user uninstalls application automatically preference file will
be deleted. Same is the case with database.
4. Which database is used in android?
Ans. SQLite database is used in android, to store heavy data in the phone in table format. Eg. To store 1000’s of contacts
and messages in our phone we use SQLite database.
5. What is content provider?
Ans. It is a component of android. It is used to share database of one application with other application.
Eg: Contact application’s contact details are shared with messaging application while composing message. This is possible
with content provider.
6. What is SQLiteOpenHelper and SQLiteDatabase?
Ans: helper class is used to do DDL operations, and database class is used to do DML operations.
Java & Android Interview Preparation
Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced.
For more interview questions visit http://skillgun.com
For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore
Connecting to Server – related questions
1. How do you connect to a server?
Using HTTPUrlConnection class. This is a predefined class of android framework, which enables programmers to
communicate with a server connected over internet.
2. What is HTTPClient class?
HTTPUrlConnection class replaced HTTPClient class. HTTPClient is an old way of connecting with servers to get
and post data.
Note: Connection class is more faster than Client class.
3. What is the procedure to get some json data from server?
a. Take internet permission in manifest file.
b. Prepare URL for the website from where you want to get the data.
c. Create a HTTPUrlConnection object by opening connection with the above created url.
d. From above connection object, get the inputstream.
e. Read inputstream data into a buffered reader
f. Bufferedreader will now contain json data, read it into a string.
g. Follow json parsing logic and parse json data which is in above string.
4. How to send and receive data between server and mobile phone?
Use JSON to send and receive data.
Note : JSON is faster than xml.
5. What are the different exceptions thrown while connecting to network?
IOException, and MalformedURLException. Both are checked exceptions, so we have to handle it by using try-
catch.
Note : While parsing JSON data it will throw a JSONParsingException, which is also checked exception.
6. How will you know if network is connected or not? How will you know if internet is connected or not?
Using ConnectivityManager class, and isConnectedOrConnecting() method. If this method returns true then
internet is either getting connected or connected already.

More Related Content

What's hot

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework Serhat Can
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Steve Pember
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMAashish Jain
 
Advanced java programming-contents
Advanced java programming-contentsAdvanced java programming-contents
Advanced java programming-contentsSelf-Employed
 
Something old, Something new.pdf
Something old, Something new.pdfSomething old, Something new.pdf
Something old, Something new.pdfMaiaGrotepass1
 
Android webservices
Android webservicesAndroid webservices
Android webservicesKrazy Koder
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesHùng Nguyễn Huy
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIOctavian Nadolu
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPTkamal kotecha
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | EdurekaEdureka!
 
[162] jpa와 모던 자바 데이터 저장 기술
[162] jpa와 모던 자바 데이터 저장 기술[162] jpa와 모던 자바 데이터 저장 기술
[162] jpa와 모던 자바 데이터 저장 기술NAVER D2
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Androidma-polimi
 
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptxRihabBENLAMINE
 

What's hot (20)

Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
 
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
 
Effective Java
Effective JavaEffective Java
Effective Java
 
ASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOMASP, ASP.NET, JSP, COM/DCOM
ASP, ASP.NET, JSP, COM/DCOM
 
Advanced java programming-contents
Advanced java programming-contentsAdvanced java programming-contents
Advanced java programming-contents
 
React
React React
React
 
Servlets
ServletsServlets
Servlets
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Something old, Something new.pdf
Something old, Something new.pdfSomething old, Something new.pdf
Something old, Something new.pdf
 
Android webservices
Android webservicesAndroid webservices
Android webservices
 
Asynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & PromisesAsynchronous JavaScript Programming with Callbacks & Promises
Asynchronous JavaScript Programming with Callbacks & Promises
 
JSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPIJSON, JSON Schema, and OpenAPI
JSON, JSON Schema, and OpenAPI
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Arrays in Java | Edureka
Arrays in Java | EdurekaArrays in Java | Edureka
Arrays in Java | Edureka
 
Interface in java
Interface in javaInterface in java
Interface in java
 
[162] jpa와 모던 자바 데이터 저장 기술
[162] jpa와 모던 자바 데이터 저장 기술[162] jpa와 모던 자바 데이터 저장 기술
[162] jpa와 모던 자바 데이터 저장 기술
 
Broadcast Receivers in Android
Broadcast Receivers in AndroidBroadcast Receivers in Android
Broadcast Receivers in Android
 
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
1-supportpoojavapremirepartie-140408132307-phpapp01.pptx
 

Viewers also liked

Android interview questions for 2 to 5 years (1)
Android interview questions for 2 to 5 years (1)Android interview questions for 2 to 5 years (1)
Android interview questions for 2 to 5 years (1)satish reddy
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questionssatish reddy
 
Android Interview Questions
Android Interview QuestionsAndroid Interview Questions
Android Interview QuestionsGaurav Mehta
 
Android M - Runtime Permissions | Getting ready for Marshmallow
Android M - Runtime Permissions | Getting ready for MarshmallowAndroid M - Runtime Permissions | Getting ready for Marshmallow
Android M - Runtime Permissions | Getting ready for MarshmallowUmair Vatao
 
Android marshmallow permission 対応
Android marshmallow permission 対応Android marshmallow permission 対応
Android marshmallow permission 対応Shun Nakahara
 
android marshmallow- latest android application version
android marshmallow-  latest android application versionandroid marshmallow-  latest android application version
android marshmallow- latest android application versionJAI SHANKER
 
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow Mobile Dimension
 
ANDROID MARSHMALLOW
ANDROID MARSHMALLOWANDROID MARSHMALLOW
ANDROID MARSHMALLOWOm Prakash
 
Have a look Google next operating system update : Android Marshmallow
Have a look Google next operating system update : Android MarshmallowHave a look Google next operating system update : Android Marshmallow
Have a look Google next operating system update : Android MarshmallowMike Taylor
 
Instalasi Android 6.0 "Marshmallow"
Instalasi Android 6.0 "Marshmallow"Instalasi Android 6.0 "Marshmallow"
Instalasi Android 6.0 "Marshmallow"anafatwa21
 
Android Marshmallow demos
Android Marshmallow demosAndroid Marshmallow demos
Android Marshmallow demosYossi Elkrief
 
Tara Shears - Latest News from the LHC
Tara Shears - Latest News from the LHCTara Shears - Latest News from the LHC
Tara Shears - Latest News from the LHCThe Royal Institution
 
Interview questions for an Android Developer
Interview questions for an Android DeveloperInterview questions for an Android Developer
Interview questions for an Android DeveloperInterview Mocha
 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleCreating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleJim McKeeth
 

Viewers also liked (20)

Android interview questions for 2 to 5 years (1)
Android interview questions for 2 to 5 years (1)Android interview questions for 2 to 5 years (1)
Android interview questions for 2 to 5 years (1)
 
Android interview questions
Android interview questionsAndroid interview questions
Android interview questions
 
Android Interview Questions
Android Interview QuestionsAndroid Interview Questions
Android Interview Questions
 
Android M - Runtime Permissions | Getting ready for Marshmallow
Android M - Runtime Permissions | Getting ready for MarshmallowAndroid M - Runtime Permissions | Getting ready for Marshmallow
Android M - Runtime Permissions | Getting ready for Marshmallow
 
Android marshmallow permission 対応
Android marshmallow permission 対応Android marshmallow permission 対応
Android marshmallow permission 対応
 
android marshmallow- latest android application version
android marshmallow-  latest android application versionandroid marshmallow-  latest android application version
android marshmallow- latest android application version
 
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow
Игорь Цеглевский: Взгляд практика на Android 6.0 Marshmallow
 
Android Marshmallow na prática
Android Marshmallow na práticaAndroid Marshmallow na prática
Android Marshmallow na prática
 
ANDROID MARSHMALLOW
ANDROID MARSHMALLOWANDROID MARSHMALLOW
ANDROID MARSHMALLOW
 
android marshmallow
android marshmallowandroid marshmallow
android marshmallow
 
Have a look Google next operating system update : Android Marshmallow
Have a look Google next operating system update : Android MarshmallowHave a look Google next operating system update : Android Marshmallow
Have a look Google next operating system update : Android Marshmallow
 
Instalasi Android 6.0 "Marshmallow"
Instalasi Android 6.0 "Marshmallow"Instalasi Android 6.0 "Marshmallow"
Instalasi Android 6.0 "Marshmallow"
 
Android marshmallow 6.0
Android marshmallow 6.0Android marshmallow 6.0
Android marshmallow 6.0
 
Android Marshmallow
Android MarshmallowAndroid Marshmallow
Android Marshmallow
 
Android Marshmallow demos
Android Marshmallow demosAndroid Marshmallow demos
Android Marshmallow demos
 
Tara Shears - Latest News from the LHC
Tara Shears - Latest News from the LHCTara Shears - Latest News from the LHC
Tara Shears - Latest News from the LHC
 
Interview questions for an Android Developer
Interview questions for an Android DeveloperInterview questions for an Android Developer
Interview questions for an Android Developer
 
Ppt on android
Ppt on androidPpt on android
Ppt on android
 
Android 6.0 marshmallow
Android 6.0 marshmallowAndroid 6.0 marshmallow
Android 6.0 marshmallow
 
Creating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 SeattleCreating Android Services with Delphi and RAD Studio 10 Seattle
Creating Android Services with Delphi and RAD Studio 10 Seattle
 

Similar to Android interview questions

20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questionsGradeup
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfnofakeNews
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview QuestionsKuntal Bhowmick
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
 
Top 10 Interview Questions For Java
Top 10 Interview Questions For JavaTop 10 Interview Questions For Java
Top 10 Interview Questions For JavaEME Technologies
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.Questpond
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1javatrainingonline
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsRohit Singh
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedyearninginjava
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedGaurav Maheshwari
 

Similar to Android interview questions (20)

Core java questions
Core java questionsCore java questions
Core java questions
 
20 most important java programming interview questions
20 most important java programming interview questions20 most important java programming interview questions
20 most important java programming interview questions
 
1
11
1
 
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdfJAVA VIVA QUESTIONS_CODERS LODGE.pdf
JAVA VIVA QUESTIONS_CODERS LODGE.pdf
 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
 
Java Interview Questions
Java Interview QuestionsJava Interview Questions
Java Interview Questions
 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
 
Top 10 Interview Questions For Java
Top 10 Interview Questions For JavaTop 10 Interview Questions For Java
Top 10 Interview Questions For Java
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1Java J2EE Interview Questions Part-1
Java J2EE Interview Questions Part-1
 
java basic .pdf
java basic .pdfjava basic .pdf
java basic .pdf
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Java interview question
Java interview questionJava interview question
Java interview question
 
Java Core
Java CoreJava Core
Java Core
 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
 
Java Faqs useful for freshers and experienced
Java Faqs useful for freshers and experiencedJava Faqs useful for freshers and experienced
Java Faqs useful for freshers and experienced
 
Top 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experiencedTop 371 java fa qs useful for freshers and experienced
Top 371 java fa qs useful for freshers and experienced
 

Recently uploaded

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 

Recently uploaded (20)

8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 

Android interview questions

  • 1. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Java Interview Questions 1. What is JVM? Java virtual machine. This is a software component. This is where every java application will run. 2. What is platform independency? Java applications are platform independent. That means once you write (compile) your java application, it can run on any system (platform). 3. Is JVM platform independent? No, JVM is platform dependent. Because every platform needs its own JVM. 4. What all the components of JVM? JIT Compiler (Just In Time compiler), byte code verifier, class loader, garbage collector, memory manager, and thread pool manager. 5. What is JRE ? Java Run time Environment. It is a software component. An environment where java applications will run. Clients needs JRE to run an application. Without JRE you can’t run a java application. 6. Then what is JVM? Will java applications run in jvm or jre? JVM is part of JRE. Finally java applications will run in JVM only. JRE = JVM + Standard java libraries. 7. What is JDK? It is software which is used by java developers to write java programs. JDK = java software framework libraries + java compiler + javae + JRE. Note : When you download JDK, it comes along with JRE internally. You don’t have to download JRE separately. 8. What does javac (java compiler) will do? Compiler checks if there are any syntax mistakes in your java program. If there are no errors then java compiler generates a .class file (which is also known as byte code). 9. What is the responsibility of JVM? JVM will convert byte code (.class file) into CPU understandable format. 10. Who will load java program into memory? JVM’s class loader will load java program into memory. 11. What is String constant pool? It is an area in memory (RAM) where string objects will be stored. 12. How to create objects in java? By using “new” operator. Note: new operator creates objects in heap location. 13. What is the use of creating object? After creating object we can access data members and functions of that object using dot operator. 14. What is a class? Class is a blue print or model using which we create objects. Class is also called as virtual entity. Class is stored in code segment. 15. What is an object? Object is a real entity which has some data and behaviour (functions). Objects are stored in heap memory. 16. What is the use of a class? Class is used to create object. Without class we can’t create objects. Class acts as a model to generate objects. 17. What is encapsulation? Binding related data and functions in a common unit, is called as encapsulation. Wrapping up of data and functions together in a class, is also called as encapsulation. Hiding data members by using private access modifier, and exposing private data by using public methods (getters and setters) is called as encapsulation. Note: This is the practical use of encapsulation. 18. How do you achieve data security in java? By using encapsulation feature, and with private access modifier. 19. What is abstraction? Presenting essential features and hiding un-essential features, is abstraction. Showing required details, and hiding un-necessary details, is also called as abstraction.
  • 2. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore In terms of OOPS, hiding implementation details and presenting only function declarations to outside world, is abstraction. Abstraction is better understood by using interfaces. 20. How encapsulation differs from abstraction? Encapsulation is a way to achieve data security. Abstraction is a way to hide un-necessary details. Since encapsulation hides private data from outer class, so you can say encapsulation is data abstraction. You are hiding data members details from outer classes. 21. What is the advantage of using encapsulation? You achieve data security by using private access modifier. You achieve readability and maintainability by clubbing related data and functions into common class. 22. Give some real example for abstraction? When you press remote, it switches on TV. How it is working internally is hidden (abstracted) for normal persons. When you press a switch, it turns on FAN. How it is working internally is abstracted (hidden) for normal persons. 23. What is constructor? It is a special function, used to construct an object. Here construct means initialize object with data. Constructor is used to initialize data to instance variables. 24. Who creates object new operator or constructor? New operator. Constructor will be called after new operator creates object. 25. Can a constructor have return type? No, constructor should not have return type. Else it is considered as normal function. 26. Can I have private constructor? Yes. It is useful in singleton design pattern. It is also useful to stop others to inherit your class. 27. What is the difference between instance variable and static variable? Instance variables are separate for each object, static variables are common for all objects of that class. Eg: tooth brush is instance variable because every person in the family has his own brush. TV is a static variable, because all persons in the family use common TV. Note : instance variables will be stored in heap, where as static variables will be stored in data segment. Note: instance variables will be created when ever a new object is created, where as static variable will be created only once, when you load that class into memory. Note: How many no of objects are there, that many no of instance variables will be there, where as only one copy of static variables will be shared will all objects. Note : instance variables should be accessed with objects, where as static variables can be accessed with class names also. (provided they are not private). 28. What is singleton pattern? Having only one object for a class is called as singleton pattern. 29. What is access modifiers or access specifiers. There are 4 access modifiers in java. They are private, default, protected, public. They are used to control who can access your class members. By using private only your class can access. By using public any other class can access your class members. By giving nothing (default) only your package classes can access class members. By giving protected, your package classes and any other subclass can access members. 30. Can I have private class? No, unless if it is an inner class. Class within a class is called as inner class or nested class. Outer classes can be only public or default. 31. What is inheritance? Inheriting or acquiring members of one class to other class is called as inheritance. In java it is possible by extends keyword. 32. What is the use of inheritance? Inheritance reduces code duplication. Inheritance is used as a tool to achieve “code reusability”. Inheritance also plays an important role in achieving polymorphism. 33. What is polymorphism? One variable referring different objects at run time is considered as polymorphism, in oops.
  • 3. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore 34. What are the different types of polymorphisms? (Stupid question) Static polymorphism and dynamic polymorphism. Note : In OOPs when we use polymorphism term, it always means dynamic polymorphism. Note: To satisfy some interviewers you can say method overloading is static polymorphism and method overriding is dynamic polymorphism. 35. How to achieve dynamic polymorphism? By using method overriding we achieve it. (To satisfy interviewers) In reality we achieve polymorphism by using inheritance / abstract class/ interface + method overriding + up casting. 36. What is the use of polymorphism? To reduce code dependency. To write independent modules. 37. What is concrete class? A class for which we can create object. 38. What is abstract class? An incomplete class. Just like an incomplete building which is under construction. You can’t create object for an abstract class. A class which contains 0 or more no of abstract methods can be made as abstract class by using abstract keyword. Note : If a class contains at least one abstract method, that class should be made as abstract class. 39. What is the use of abstract class? To share common functionality to related classes in inheritance hierarchy, we use abstract class. To enforce some functionality to be implemented by sub classes, we use abstract classes. Note : As mentioned already, they play important role in achieving polymorphism. Note : The only purpose of abstract class is to be extended by some other class and give full implementation of abstract methods. 40. What is concrete method? A method with body. 41. What is abstract method? A method without any body. Method with only signature. To create abstract methods we use abstract keyword. 42. What is an interface? It is just like a class, but without any function bodies. 43. What an interface can contain? Only constants, method declarations, and nested types. Note: from JDK 1.8 onwards interfaces can contain methods with bodies (referred as default methods). Note: from JDK 1.8 onwards interfaces can have static methods with bodies. 44. What is the use of interfaces? It is a way to achieve abstraction in Java. To hide implementation details we use interface as a tool. Interfaces are used mostly when you are writing some libraries or server side code, and to hide your code from clients. Interface can be used as a tool to share or enforce some common functionality to un-related classes. Note : abstract classes are used to share common functionality to related classes. Interface is used as a tool to achieve multiple inheritance of classes in java. 45. Does java support multiple inheritance? Yes, it supports multiple inheritance of interfaces. No, it won’t support multiple inheritance of classes. 46. Some real world example of interface? (Stupid question) Switch is interface between you and fan. Remote is interface between you and TV. 47. What is static method? A method which can be accessed directly with class name. It is used to read private static variables. It can also used to write some utility methods like ones in predefined Math class’s random() method. Note : Static methods assumed to be faster than instance methods. 48. Can you access instance variables in static methods?
  • 4. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore No. Note: but instance methods (non-static methods) can access both instance variables and static variables. 49. What is final variable? It is like a constant. Once you assign a value to final variable, you can’t change it. 50. What is final method? A method which can’t be overridden in child class. Eg: Many of the Object class methods are final methods. Eg: wait(), notify(), notifyAll(). They are final methods. 51. What is final class (immutable class)? A class which can’t be inherited or extended. Eg: String class is final class. All wrapper classes are final classes. Wrapper classes are – Integer, Float, Boolean, ... By default all methods of final class will become final methods. (But not variables). 52. What is immutable object? An object whose states (Data) can’t be modifiable once assigned. Eg: String object is an immutable object. 53. What is method overloading? Multiple methods having same name but different parameters, in a class, is called as overloading. 54. What is method overriding? Having same method in parent class and child class With same method name + same parameters + same or covariant return type + same or higher access modifier. 55. Can I overload constructor? Yes. But you can’t override constructor as it is inherited to child class. 56. How to call super class constructor? Using super() keyword. Pass parameters in super if parent class constructor expects some parameters. 57. How to call same class constructor? Using this() keyword. 58. How to call parent class overridden method? Using super keyword. 59. What is the difference between StringBuilder and StringBuffer? Builder is not synchronized, buffer is synchronized. Builder can be used only with single thread, buffer can be used with multiple threads. 60. How will you catch run time errors in your project? By using try-catch blocks. Run time errors means exceptions. 61. Tell me different types of exceptions? Checked exceptions & un checked exceptions. 62. Give examples for checked an dun checked exceptions? Checked exceptions  IOException, JSONException, SQLException, FileNotFoundException, SocketException, HTTPRetryException. Unchecked Exceptions  NullPointerException, ArrayIndexOutOfBoundsException, IOError, .. 63. Difference between checked and un-checked exceptions? Programmer should handle checked exceptions. Programmer need not handle un-checked exceptions. 64. How do you handle checked exceptions? There are 2 ways. a. By using try-catch block b. By using throws 65. What is throws and throw? Throws keyword is to throw an exception to parent method. Throw keyword is to re-throw an exception to parent method, after catching/handling that exception. 66. What will happen if you don’t handle checked exceptions? Compiler will throw error.
  • 5. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore 67. What is IOException? IOException occurs mostly when there is problem in reading or writing data from one place to other place. Eg: While reading data from file, if data is corrupted then it will throw IOException. Eg: While reading data from internet connection, if connection is closed it will throw IOException. 68. What is FileNotFoundException? While opening a file, if file is not there or if directory is not there, or if file path is wrong, it will throw this exception. 69. What is collections in java? Collection is a container which can hold any type of data. It is similar to data structures in c language. 70. Is collection same as array? It is more powerful than array. Collections are containers which can store any type of values. Collections are containers which are dynamically growable. Collections are containers which contains lot of predefined methods to read, insert, delete, add, and modify elements of container very fastly. 71. What is collection framework? It is a predefined library which comes along with JDK software. Collection framework contains 3 parts interfaces, implementations, and algorithms. Collection framework is the software implementations of collections. Collection framework contains lot of predefined classes with complete implementation of many data structures [collections] which are used to store temporary data. 72. What is ArrayList? ArrayList is a collection[container] of elements. ArrayList allows duplicate elements to be stored. ArrayList is ordered collection of elements. The way you insert elements, it will be read in same order. 73. What is Set? Set is a collection [container] of elements. Set doesn’t allow duplicate elements to be stored. Set is unordered collection of elements. The order in which elements are stored can’t be predictable. 74. What is Map? Map is container which stores key, value pairs. 75. Which set is fastest? HashSet is faster than LinkedHashSet and TreeSet. 76. What is the difference between HashSet, TreeSet, and LinkedHashSet? HashSet – Unordered collection of elements. Internally uses Hashmap to store set values. TreeSet – It maintains ascending order of elements. Internally uses red-black tree to store set values. LinkedHashSet – It maintains insertion order of elements. Internally uses linkedlist with hashmaps to store elements of set. 77. What is the difference between set and list? (or difference between hashset and arraylist). Set - is unordered collection of elements. Sets won’t allow duplicate elements. List – is ordered collection of elements. List allows duplicate values. 78. Does set allow null values? Any set allows only one null element. Note : List allows multiple null elements. 79. What is the difference between Arraylist and linkedlist? They are 2 different implementations or types of lists. ArrayList – store elements in sequential order, in contiguous memory locations. In most of the cases this is faster than linked list. Linked list – stores elements in non-sequential order. i.e will not store elements in contiguous memory locations. Internally it uses something called as nodes and references (pointers). 80. Difference between vector and arraylist? Vector – by default synchronized. Vector is deprecated, better not to use. Arraylist – by default not synchronized. Arraylist is the replacement for vector. 81. Difference between hashtable and hasmap? HashTable – by default synchronized. It won’t allow null key and null values. It is deprecated, better not to use.
  • 6. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore HashMap – by default not synchrnoized. It is the replacement for hashtable. It allows one null key and multiple null values. 82. Difference between collections and generics? ArrayList al = new ArrayList();  this is collection. ArrayList<String> al = new ArrayList<String>();  This is generic. Collection  No type safe. It was used before jdk 1.5 version when generics concepts were not introduced. Generic  more secured and type safe. Introduced in jdk 1.5 version. Always prefer to use generics in place of collection. 83. Difference between map and dictionary? Dictionary is an abstract class, which implements map interface. It is deprecated. It is same as hashmap. HashMap is the replacement of dictionary. 84. What is iterator? It is an interface, with which we can traverse to all elements of any collection. Using iterator you can fetch elements of set or list or map. 85. What is listiterator? It is a subtype of iterator. Using this you can traverse and access elements of arraylist or linkedlist. 86. What is the difference between iterator and listiterator? Iterator is used only for one way traversal. Can be used with any type of collection. Listiterator has the capacity of two way traversal. Can be used only with list types.
  • 7. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Android Basic questions 87. What is DVM? Dalvik Virtual Machine. It is not hardware component. It is a software. 88. What is the use of DVM? Just like java programs runs in JVM, android applications runs in DVM. 89. Does each application has its own DVM? Yes. 90. How is DVM different from JVM? JVM is heavy which takes more memory and cpu time, DVM is light weight which is suitable for mobile phones. DVM follows register based architecture to execute fastly. JVM follows stack based architecture which is slow. 91. What is ART? ART = Android Run Time. This is the advanced version of DVM. From android 5.0 version onwards android applications runs in ART, not in DVM. From android 5.0 version onwards there is no more DVM. 92. How is ART different from DVM? ART is almost 4 times faster than DVM. DVM was using JIT compilation process, where as ART uses AOT compilation process, which makes it more faster. AOT = Ahead Of Time compilation. 93. What are the major changes in android 5.0 version? DVM is replaced with ART. ListView gets more faster with RecyclerView. Whole design changed with Material design concept. 94. Draw android architecture. It contains 4 layers. OS layer, Libraries layer, Android framework layer, application layer. 95. Android is based on which operating system? Linux operating system. 96. What are the versions of android? 1.5 Cupcake, 1.6 Donut, 2.0-2.1 Eclair, 2.2 Froyo, 2.3.x GingerBread, 3.0-3.1-3.2 HoneyComb, 4.0.x IceCreamSandwitch, 4.1-4.2-4.3 JellyBean, 4.4.x Kitkat, 5.0-5.1 Lollipop, 6.0 MarshMallow.
  • 8. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Activity , Fragment, and UI related questions 1. What is an Activity? Ans. Each screen in android application is called as an Activity. Activity is a visible component of android. Activity life cycle: 2. What is a fragment? Ans. Fragment is a modular and reusable component of an activity. It can also be called as sub-activity. 3. What is the advantage of using fragments in application? Ans. Fragments are used to build application compatible with mobiles, tablets, watches, and autos. Different devices will have different screen sizes, and Application should fit properly in different screen sizes. This is possible by using fragments. 4. Can you tell me other advantages of using fragments? Ans. You can build dynamically changing UI, by using fragments. 5. What is the difference between activity and fragment? Ans. Each screen is called as activity. Fragment is part of an activity. An activity can contain 0 or more number of fragments. Fragment doesn’t exist without an activity.
  • 9. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore 6. What is Intent? Ans. Intent is used to start activity or to start a service or to send a broadcast. 7. How will start an acitivity? Ans. Create an intent, and use startActivity(intent) method. 8. How to pass data from one activity to other activity? Ans. Use putExtra() method to pass data between one activity to other activity. 9. What is startActivityForResult() ? Ans. If you are expecting some data from child activity to parent activity use this. 10. How to close/ stop/kill an activity? Ans. Use finish() method to kill an activity by itself. You can also finishActivity() method to kill child activity. 11. Which layout is deprecated? Ans. Absolute layout. 12. Which layout is better to use? Linear or relative? Ans: Always preferable to use linear layout. Relative layout has chained dependency which may corrupt your design if you try to modify it. 13. How will you build application compatible for both mobile phones and tablets? Ans. Consider below points while designing applications for both phones and tablets. a. Use dp and weights in place of px (pixels). b. Don’t use absolute layout, consider using linear layout with weights. c. Adjust font sizes for different screen sizes using sp (scale independent pixels). Put font sizes in values-sw folder as required. d. Prefer using 9-patch images so that your images stretch properly on bigger screens. e. Strongly recommended to use “fragments” so that your application fits properly on different screen sizes. f. Support different screen densities by supplying different image resolutions in different drawable folders. g. Example : for medium density phones supply icon with size 48*48 pixels, for high density phones supply icon with size 72*72 pixesl, for extra high density phones supply icon with size 96*96 pixels, for extra-extra high density devices (tablets) supply icon with size 144*144 pixels. So that your icons looks proper on different screen densities with different resolutions. h. Avoid using relative layouts as well, as future modifications for your screen might become cumbersome. It uses relative position which is dangerous if screen contains too many components. i. User material design to have unanimous feel of your app design on different devices. 14. Can one application have 2 launcher activities ? Ans: yes. It is possible. Go to manifest xml file, put below intent filters for whatever activities to be made as launcher. <intent-filter> <action android:name=”android.intent.action.MAIN”/> <category android:name=”android.intent.category.LAUNCHER/>
  • 10. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore </intent-filter> 15. Does each instance of an application contains its own instance of dalvik virtual machine? Ans : yes. 16 . What is onSaveInstanceState() method? Ans : This is a life cycle method of activity, which will be called if there is any configuration change to your phone (eg : rotating phone, changing language settings). This method will also be called in case of low memory in your application. 17. How a programmer should handle this method? What to do in this method? Ans : If programmer has any transient data to be saved in the application, save it in this method. 18. Can we save database in onSaveInstanceState() method? Ans : Don’t save database changes in this method. Use onPause() method to save database changes and other persistent data changes. 19. Is it possible to have an activity without UI? Ans: Yes it is possible. 20. Can you create UI of an activity without using xml file? Ans: Yes it is possible. Eg: Button b = new Button(this); b.setText(“Hello world”); setContentView(b); 21. What is context? Ans: There are 2 types of contexts in android. a. This context b. getApplicationContext() Mostly we should use this context, and never getApplicationContext(). This context is available only for activity, service and contentprovider. 22. What is the purpose of context? Ans : Context is used to create new resources in your application. Context is used to start other components. Context is used to access your application resources. 23. what is px, dp, dip, dpi, and sp? Ans : px is pixel, dp is density independent pixel, dip is also density independent pixel, dpi is dots per inch on the screen, and sp is scale independent pixels. Note : Never use px, it is deprecated. To specify width and height use dp. For font sizes use sp. Dpi is used while measuring density and resolution of the phone. 24. What is the difference between linearlayout and relative layout? Ans : Linear layout is used to align views either horizontally or vertically. Relative layout is used to align views in relative to each other.
  • 11. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore 25. What is weight property? Ans : weight property is used to distribute views on the screen area based on proportions. 26. what is the difference between gravity and layout gravity? Ans: gravity is to align view content with in the view. Layout gravity is used to align view within the parent view. 27. what is the difference between padding and margin? Ans : Padding is used leave space between view content and view border. Margin is used to leave space between view border and parent view or other peer views. 28. what is the purpose of weightsum? Ans: weigt sum is not preferred to use. It is equal to sum of different view weights used in your layout. If you use weightsum, then future modifications for your screen design will be difficult. Every time you do some change to your design in future, you have to make sure to modify weightsum also, else it leads to wrong design. 29. Give some examples for layouts in android? Ans: linear layout, relative layout, frame layout, table layout, absolute layout (deprecated). 30. Give some examples for adapter views in android? Ans: ListView, GridView, Gallery (deprecated), ExpandableListView, AutoCompleteTextView, Spinner, CardView, RecyclerView. 31. What is the parent class for activity? Ans: Either Activity or FragmentActivity or ActionBarActivity. 32. What all the lifecycle methods of custom adapter? Ans: getCount(), getItem(), getItemId(), getView(). 33. How will you write a custom adapter? Ans : Mostly we will create custom adapter by creating our own class by extending BaseAdapter class. 34. What is Bundle? Ans: Bundle is a data holder, which is used to pass data between 2 activities. Bundle will also be useful while saving states in onSaveInstanceState() method. 35. How will you start other applications from your activity? Ans : Using Intent and startActivity() method. 36. How will you start gallery application from your activity, to get an image from the gallery? Ans : Intent in = new Intent(); In.setType(“image/*”); In.setAction(Intent.ACTINO_GET_CONTENT); startActivity(in); 37. What is an Intent?
  • 12. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Ans: Intent is used for 2 purposes. a. Using Intent you can start an activity or service or broadcast receiver components. b. Using intent you can pass data between 2 components in android. 38. What is an IntentFilter? Ans : Intent filter is counter part for intent. Using intent a component can tell what type of actions it can handle. 38. What is pendingIntent? Ans : An intent which will be fired or triggered at future point of time by either alarm manager or notification manager on behalf of your application. 39. What is ListActivity? Ans : Its a predefined class of android, which used if you want only listview in your activity. This class will return a listview automatically. 40. What is ListFragment? Ans : If you want only a listview in your fragment then your fragment class should extend this class. It is exactly like ListActivity. 41. What is ViewHolder pattern? Ans : It is an efficient way to display items in listview. Service, AsyncTask & Thread related questions 1. What is a service? Ans. Service is an invisible component of android, which is used to do background operations/ tasks. Eg1: Playing songs in the background is done by service. Eg2: Uploading or downloading movies/ files over internet is also a background task which is done by service. Note: Any task which is not visible to user is done by a service, in android. Or any task which should run in background irrespective of an activity, is done by a service. 2. What is a thread? Ans. Thread is a component of operating system, which is used to do background operations/ tasks. Thread is also known as “light weight process”, because thread lies in a process. 3. What is the different between service and thread? Ans. Service is component of Android framework. Thread is component of Operating system. Service will internally use thread to do background task. Without thread, service is useless. If you try to create a service without thread, it may lead to ANR error. 4. What is ANR ?
  • 13. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Ans : Application Not Responding. It is an error thrown by Android O.S if touch events are not handled within the time limit of 5 seconds. This will happen mostly when programmer tries to use main thread for activities and services. To avoid this error, when programmer creates a service, you should create a thread for that service. 4. What is IntentService? Ans. It is a predefined class of android, which is used to create a service with single thread. 5. How to create service with multiple threads? Ans. Use AsyncTask class inside your service class. 6. What is AsyncTask? Ans: It is a predefined class given by Android framework to create threads easily, in android applications. 7. What is the difference between Thread class and AsyncTask class? Ans : Thread class is a complicated way to create threads. AsyncTask is an easy way to create threads. From a thread we can’t touch UI directly. But from AsyncTask we can touch UI from onPreExecute(), onProgressUpdate(), and onPostExecute() methods. 8. Is it impossible to touch UI from normal thread? Ans : It is possible, but complicated. You should use either runOnUIThread() method or you should use Handler concept to touch UI from non-ui threads. 9. What all the life cycle methods of AsyncTask class? What all the callback methods of AsyncTask? Ans : onPreExecute(), doInBackGround(), onProgressUpdate(), onPostExecute(). 10. In above methods which method runs in back ground thread? Ans: doInBackground() method runs in background thread. Note: Don’t touch UI from this method. 11. How to start an AsyncTask? Ans: Create an object for asynctask class, and call execute() method. 12. How to pass some data to doInBackGround() method? Ans: You can pass data to doInBackGround() by supplying some parameters to execute() method of asynctask class. 13. Can I use AsyncTask class with activities and fragments? Ans : You can use it anywhere. 14. What is HandlerThread? Ans: HandlerThread is same as normal java thread, but only difference is HandlerThread contains an extra component called as Looper to dispatch events from MessageQueue. 15. How will you create an application to connect to internet? Ans : Take internet permission in manifest file. Create a service. Create an asynctask inside the service class.
  • 14. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore In doInBackGround() method write logic to connect to network. 16. What all the lifecycle methods of a service class? Ans: onCreate(), onStartCommand(), onDestroy(), and onBind(). 17. What is onBind()? Ans : This method is used while implementing binder services? 18. How many types of services are available in android? Ans : 2 types. Started services and binder services. 19. What is the difference between started service and binder service. Ans : Started service is used to do a background task which doesn’t return any value to the client. Binder service is something like a client-server architecture where client can send request and server will respond with response. 20. How to start and stop a service? Ans: Using Intent and startService() method we can start a service. A service can be stopped in 2 ways. Others can stop a service by using predefined method stopService(intent). A service can kill itself by using stopSelfResult(resultid) method. 21. What are the disadvantages of IntentService? Ans: Programmer can’t touch UI from intent service. It is a single threaded service. Note : Programmer can still use Handler concept to touch UI from IntentService class. 22. What is a binder service? Ans : Binder Service is a client server architecture, where clients can send request to binder service, and binder service will respond back with some data. 23. What is AIDL? Ans : Android Interface Definition Language. To create binder services with IPC mechanism we use aidl file. Aidl file contains an interface with publicly exposed methods. 24. How to implement binder services? Ans : If binder service is used by same application, then use binder class and return binder class object from onBind() method. If binder service is used by other applications then create an aidl file, and implement aidl files stub, and return stub’s object from onBind() method. 25. What is the difference between activity and service? Ans : Both are components of android. Activity is used to write logic for visible components (Screens). Service is used to write logic for invisible components (back ground tasks). Note : It is not mandatory that activity should have UI. But it makes more sense to use activity for visible components. 26. What is the difference between service and receiver?
  • 15. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Ans : Both are components of android. Service is used to do heavy back ground tasks. Receiver is used to receiver broadcast announcements from system, and to do a small light weight task in the back ground with in a time limit of 10 seconds. Both components should not have UI. Eg : To play songs in back ground we use service. Eg : To receive incoming message announcements , or to receiver battery low announcements , and to listen for other important system level events we use receiver. 27. Life cycle methods of a service? Ans : for started service -> onCreate(), onStartCommand(), onDestroy(). For binder service -> onCreate(), onBind(), onDestroy(). 28. Life cycle methods of an intentservice? Ans : constructor() and onHandleIntent(). 29. What is the disadvantage of IntentService? Ans: You can’t touch UI from intent service as it runs in separate thread. 30. Is there no way to access UI elements from IntentService directly? Ans: It is possible by using runOnUIThread() or handler mechanism. 31. How to access UI elements from service? Ans: Create a dynamic receiver in activity. Send a broadcast from service to trigger activity’s receiver. Then from receiver touch UI components. 32. What is binder? Ans : Binder is an IPC mechanism used in android. IPC = Inter process communication. 33. What are the other IPC mechanisms available, apart from binders? Ans : Apart from binder, generally java programs uses Serialization concept for IPC mechanism. 34. How binder is different from serialization? Ans : Binder IPC is faster than Serialization. Because binders internally uses shared memory concept which makes it more faster to transfer data between 2 processes. Note : Binder internally uses Parcel concept to transfer data between 2 processes. 35. What is parcelable and serializable? Ans : Those are 2 different mechanisms to convert object into bits and bytes. To transfer object’s data from one process to other process, object should be chopped into byte stream. For that we can use either parcelable concept or serializable concept. 36. What is the internal mechanism of binder IPC?
  • 16. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Ans: Binders internally uses parcelable to convert objects into byte stream and uses shared memory concept to transfer this byte stream to other process. Binder internally uses parcelables which has less restrictions while parcelling and deparcelling unlike serialization. Due to many checks at deserialization it makes it slow. 36. What are the other differences between parcelable and serializable. Which one we should use in android? Ans : Since android is meant for smaller and light weight devices, you should always opt for light weight and faster technique to transfer data. Note : Serializable and Parcelable are 2 predefined interfaces. Parcel data is much more light weight and faster than serializable data. So go for parcels. 37. But we pass data from one application to other application in android with Bundle? Ans: Bundle internally uses parcels as well to send data fastly. Note: As an android developer use always bundles to pass data between components or applications. As bundle internally uses parcels, it transfers data fastly. You should minimize the use of parcels and serializables directly in your code. 38. How to transfer an object from one activity to other activity? Ans: In this case you can use parcelable and put it in bundle and send bundle to other activity. 39. Can I put serializable objects in a bundle? Ans: Yes, you can. But not recommended, as it is slow. 40. How to create a serializable object? Ans: To create a serializable object, class of that object should implement Serializable interface. 41. What is serialization? Ans: The process of converting objects into byte stream is called as serialization. 42. What is the use of serialization? Ans: It is a good approach to store some objects in files or to pass some objects from one place to other place. 43. What is serialization and deserialization? Ans: You can think of it like this. If you want to send some luggage from one place to other place, you will compress the luggage into an auto, and you will decompress that luggage and restore into a new house. Similarly if you want to send some object’s data from one place to other place, then first we have to compress into some universal format(ie bits and bytes). That is serialization. It is the process of converting object into byte stream. And Deserialization(decompressing) is the process of regenerating object from that byte stream and restoring that object’s data. 44. How to enforce security on services? Ans: Use exported attribute to false, so that other applications can’t trigger your receiver. Or set some permissions on your service, so that to trigger your service they need the permission.
  • 17. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore 45. I want to create a service to do a background task. Should I use Thread class or AsyncTask class? Ans: Always use AsyncTask class. Because it is a comfort way to create threads in android. It has advantage of touch UI elements. 46. What is the difference between handler and asynctask? Ans: Handler is mechanism used to communicate with Handler Threads. AsyncTask will internally use Handler concept to communicate with main thread, in onPreExecute(), onProgressUpdate(), and onPostExecute() methods. Handler mechanism is internally used by asynctask to communicate to main thread for UI updations from back ground thread. 47. What is the purpose of doInBackground() method in AsyncTask class? Ans: That method will run in back ground thread. If programmer want to do some heavy back ground task like connecting to internet, download or upload some file, or data base transactions then use that method. Database related questions 1. How will you store data in your application? Ans. There are many ways to store data in android application. a. You can use sharedpreferences to store small amount of data in your phone. b. You can use database to store huge amount of data in your phone. c. You can save data in internal memory or external memory (sd card). d. You can save data in a server also using internet connection. 2. What is sharedpreferences? Ans. Sharedpreferences is also called as preferences. It is an xml file which is used to store small amount of data in your phone. Eg: To store username and password we can use preferences as it is small amount of data. 3. Where do sharedpreference files will be stored? Ans. It is stored in the internal memory of your phone. When user uninstalls application automatically preference file will be deleted. Same is the case with database. 4. Which database is used in android? Ans. SQLite database is used in android, to store heavy data in the phone in table format. Eg. To store 1000’s of contacts and messages in our phone we use SQLite database. 5. What is content provider? Ans. It is a component of android. It is used to share database of one application with other application. Eg: Contact application’s contact details are shared with messaging application while composing message. This is possible with content provider. 6. What is SQLiteOpenHelper and SQLiteDatabase? Ans: helper class is used to do DDL operations, and database class is used to do DML operations.
  • 18. Java & Android Interview Preparation Proprietary material of Palle® Technologies. Not for commercial use. Not to be copied and reproduced. For more interview questions visit http://skillgun.com For training visit http://techpalle.com Phone: 080-4164-5630, Bangalore Connecting to Server – related questions 1. How do you connect to a server? Using HTTPUrlConnection class. This is a predefined class of android framework, which enables programmers to communicate with a server connected over internet. 2. What is HTTPClient class? HTTPUrlConnection class replaced HTTPClient class. HTTPClient is an old way of connecting with servers to get and post data. Note: Connection class is more faster than Client class. 3. What is the procedure to get some json data from server? a. Take internet permission in manifest file. b. Prepare URL for the website from where you want to get the data. c. Create a HTTPUrlConnection object by opening connection with the above created url. d. From above connection object, get the inputstream. e. Read inputstream data into a buffered reader f. Bufferedreader will now contain json data, read it into a string. g. Follow json parsing logic and parse json data which is in above string. 4. How to send and receive data between server and mobile phone? Use JSON to send and receive data. Note : JSON is faster than xml. 5. What are the different exceptions thrown while connecting to network? IOException, and MalformedURLException. Both are checked exceptions, so we have to handle it by using try- catch. Note : While parsing JSON data it will throw a JSONParsingException, which is also checked exception. 6. How will you know if network is connected or not? How will you know if internet is connected or not? Using ConnectivityManager class, and isConnectedOrConnecting() method. If this method returns true then internet is either getting connected or connected already.