Top 30+ Java & Android Interview Questions Every Engineer Should Master
This article compiles essential Java fundamentals and Android development interview questions—from interface purpose and abstract classes to thread blocking, memory leaks, service lifecycles, layout optimizations, and common design patterns—providing concise explanations and code snippets to help candidates ace technical screenings.
Java Basics
1. Interface purpose (Baidu): standardization, extensibility, callbacks.
2. Abstract class purpose (LeTV): provide a common type, encapsulate repeated code, define abstract methods for consistent signatures.
3. Inner class benefits (Baidu, LeTV): each instance has independent state, can implement interfaces differently, creation independent of outer class, better encapsulation.
4. Can a static method be overridden? No; static methods are hidden, not overridden.
5. Example sorting algorithms (Meituan): see linked CSDN article.
6. Java collections hierarchy (Baidu, Meituan): overview of List, Set, Map structures.
7. JVM features (Baidu, LeTV): platform independence via bytecode execution, interpretation to native instructions.
8. Garbage collection triggers (LeTV, Meituan, Xiaomi): generational GC, short-lived objects collected in young generation, long-lived objects promoted to old generation.
9. Process vs. thread differences (猎豹): processes have separate memory, threads share memory; threads enable higher concurrency.
10. Difference between == and equals, and equals vs hashCode (LeTV): see linked article.
11. Common sorting algorithm complexities (Xiaomi): see diagram image.
12. HashMap implementation (Meituan): array of buckets combined with linked lists; initialization creates an array.
13. Java state machine: reference link provided.
14. Primitive sizes: byte 1 B, short 2 B, int 4 B, long 8 B, float 4 B, double 8 B, char 2 B.
15. int vs Integer: reference link provided.
16. String vs StringBuffer vs StringBuilder differences (Xiaomi, LeTV, Baidu): immutability, thread‑safety, performance considerations.
17. Polymorphism in Java (LeTV): dynamic binding, interface implementation, benefits such as substitutability and extensibility.
18. Thread blocking mechanisms (58, Meituan): sleep, suspend/resume, yield, wait/notify with synchronization details.
19. Abstract class vs interface differences (360): default implementations, inheritance, constructors, access modifiers, multiple inheritance, speed, adding methods.
20. Container class differences (LeTV, Meituan): reference links provided.
21. Java inner classes (Xiaomi): reference link provided.
22. HashMap vs Hashtable differences (LeTV, Xiaomi): reference link provided.
23. ArrayMap vs HashMap: reference link provided.
Android Basics
1. Database operation types and importing external DB: place DB in res/raw or copy to /data/data/<package>/ using streams.
2. Local vs global broadcast: local broadcast stays within app, safer and more efficient.
3. IntentService purpose and AIDL role: background worker thread handling intents sequentially; AIDL enables IPC between processes.
4. Activity, Window, View differences and Fragment characteristics: Activity creates Window, Window hosts View hierarchy; Fragment can be added, removed, or replaced within an Activity.
5. Network request flow (Sina): see diagram image.
6. Handler, Thread, HandlerThread differences (Xiaomi): HandlerThread extends Thread with Looper for message handling.
7. Implementing high‑API features on low SDK: use @TargetApi or custom implementations.
8. Building Android from Ubuntu (Baidu): source setup, . build/envsetup.sh, lunch, make -j8.
9. Launch mode scenarios (Baidu, Xiaomi, LeTV): standard, singleTop, singleTask, singleInstance with task affinity considerations.
10. Touch event propagation (Xiaomi): reference link provided.
11. View drawing process (Baidu): background, onDraw, dispatchDraw sequence.
12. Multithreading options (360): runOnUiThread, View.post, Handler, AsyncTask.
13. Thread synchronization (Baidu): synchronized blocks, wait/notify mechanisms.
public class Singleton{
private volatile static Singleton mSingleton;
private Singleton(){ }
public static Singleton getInstance(){
if(mSingleton == null){
synchronized(Singleton.class){
if(mSingleton == null)
mSingleton = new Singleton();
}
}
return mSingleton;
}
}14. Memory leak causes (Meituan): unclosed resources, missing convertView reuse, unrecycled Bitmaps, context leaks, unremoved listeners, static collections.
15. ANR causes and fixes (Meituan): avoid IO on main thread, heavy computation, improper waits/sleeps, use IntentService, set thread priority.
16. OOM causes (LeTV, Meituan): heavy data structures, enums, large Bitmaps, heavy onDraw allocations, StringBuilder misuse.
17. Service‑Activity communication: Binder, broadcast.
18. API level differences across Android versions: reference link provided.
19. WAP networking code (360): reference link provided.
20. Keeping services alive: START_STICKY, priority attributes, foreground service, restart on destroy.
21. requestLayout vs onLayout vs onDraw vs drawChild: layout pass vs drawing pass details.
22. invalidate vs postInvalidate differences: UI thread vs background thread updates.
23. Animation framework principle: transformation matrix applied during draw, invalidate triggers next frame.
24. Per‑app memory allocation: typically 16 MB–24 MB.
25. View refresh mechanism: ViewRoot performTraversals, draw, invalidate flags.
26. LinearLayout vs RelativeLayout performance: measurement passes, margin vs padding, prefer flat hierarchies.
27. Custom view optimization: avoid allocations in onDraw, minimize invalidate calls, flatten hierarchy, consider custom ViewGroup.
28. ContentProvider overview: reference link provided.
29. Fragment lifecycle: reference diagram image.
30. Volley parsing (Meituan, LeTV): reference link provided.
31. Glide source analysis (Meituan, LeTV): reference links provided.
32. Android design patterns: reference link provided.
33. Architecture design (Sohu): reference link provided.
34. Property animation features (LeTV, Xiaomi): limitations of tween animation, need for object animation for non‑View properties.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITFLY8 Architecture Home
ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
