Java Interview Guide
How to Build Confidence With a Solid Understanding
of Core Java Principles
By Anthony DePalma
Copyright © 2015 by Anthony DePalma
All rights reserved.
Editors: Ayesha Khan; Jon Hall
eBook formatting/conversion:
www.fromprinttoebook.com
Table of Contents
Introduction
The Purpose of this Guide
The Java Programming Language
The History of Java
The Java Virtual Machine
Procedural Programming vs Object-Oriented Programming
Questions
Object-Oriented Concepts
Abstraction
Encapsulation
Polymorphism
Mutability
Coupling
Cohesion
Questions
Object-Oriented Programming (Part I)
Classes & Objects
Primitive Types
Arrays
Strings
Enums
Packages
Questions
Object-Oriented Programming (Part II)
Methods
Pass-by-Reference vs Pass-by-Value
The Final Keyword
The Static Keyword
Access Modifiers
Annotations
Questions
The Object Superclass
Clone
Equals
HashCode
ToString
GetClass
Finalize
Wait, Notify, NotifyAll
Questions
Composition & Inheritance
Composition
Inheritance
Method Overriding vs Method Overloading
Composition vs Inheritance
Questions
Abstract Classes & Interfaces
Abstract Classes
Interfaces
Abstract Classes vs Interfaces
Anonymous Classes
Questions
Exceptions
Unchecked Exceptions
Checked Exceptions
Unchecked Exceptions vs Checked Exceptions
Errors
Try/Catch/Finally
Try-With-Resources
Questions
Generics
Compile-Time Errors vs Runtime Errors
Generics
Generic Wildcards
Type Erasure
Questions
Concurrency
Thread Lifecycle
Synchronization
The Synchronize Keyword
The Volatile Keyword
Concurrent Data Structures
The Executor Framework
ThreadLocal Storage
Atomic Variables
Questions
Memory Management
Heap Memory
Garbage Collection
Strong References
Memory Leaks
Soft References
Weak References
Reference Queue
Phantom References
Questions
Java Database Connectivity
Connection
Statements
ResultSets
SQL Injection
Object-Relational Mapping
Questions
Web Applications
The Servlet API
Servlets
JavaServer Pages
Filters
Model-View-Controller
Questions
Web Services
Service-Oriented Architecture
Web Services
SOAP
REST
SOAP vs REST
Questions
Algorithms
Big O Notation
Binary Search
Insertion Sort
Merge Sort
Quicksort
Timsort
Questions
Java Collections Framework
List
Map
Deque
Binary Search Tree
Heap
Set
Iterator
Questions
Important Interfaces
Autocloseable
Comparable
Comparator
Iterable
Runnable
Callable
Serializable
Questions
Creational Design Patterns
Builder Pattern
Factory Pattern
Abstract Factory Pattern
Prototype Pattern
Singleton Pattern
Questions
Structural Design Patterns
Adapter Pattern
Composite Pattern
Decorator Pattern
Facade Pattern
Flyweight Pattern
Questions
Behavioral Design Patterns
Command Pattern
Observer Pattern
Strategy Pattern
Visitor Pattern
Null Object Pattern
Questions
Reflection
Class
Field
Method
Pros and Cons
Questions
Dependency Injection
Inversion of Control
Service Locator vs Dependency Injection
Constructor Injection vs Setter Injection
The Spring Container
Spring Configuration
Spring Lifecycle
Questions
Aspect-Oriented Programming
Core Concerns vs Cross-Cutting Concerns
Aspect-Oriented Programming
Proxy Objects
Interface Proxies
Inheritance Proxies
Runtime Weaving vs Binary Weaving
AspectJ
Questions
Unit Testing
Test-Driven Development
Unit Tests
Test Fixtures
Mock Objects
Questions
Programming Problems
How to Approach Programming Problems
Sample Programming Problems
Interview Preparation
Before the Interview
During the Interview
After the Interview
Interview Questions
About the Author
Introduction
The Purpose of this Guide
This guide will prepare you for an interview to an entry-level or a senior-level
position as a Java software developer. It’s intended to be a high-level resource
and it’s assumed that you are already familiar with the Java language and know
how to write basic applications.
The book is divided into chapters of related concepts that are presented
in interview-sized chunks. At the end of each chapter is a series of potential
interview questions. Read through each chapter and research any topics that are
unfamiliar until you are able to answer every question confidently. All of the
questions are listed again at the end of the book.
In order to get the most out of this guide, make sure that you are able to answer
every question in your own words. From the perspective of an interviewer, it’s
always better to hear a candidate explain something uniquely, because it proves
that you understand the underlying concepts. It will also prepare you for
variations of the same questions. The stronger you understand the concepts,
the more confident you’ll appear in your interview. Are you ready?
The Java Programming Language
The History of Java
Java is an object-oriented programming language that was released by Sun
Microsystems in 1995. Unlike C++, it allowed developers to write code that
could run on multiple platforms. This principle, called Write Once,
Run Anywhere (WORA), prevented the need for developers to write different
applications for different operating systems. Java borrowed much of its syntax
from C++, but it streamlined development by providing features such
as automatic memory management and by eliminating pitfalls such as multiple
inheritance.
The Java Virtual Machine
The WORA principle is possible because of the Java Virtual Machine (JVM).
A virtual machine is software that emulates a physical machine. In traditional
programming languages, code is compiled into machine language for a specific
platform. In Java, code is compiled into a virtual machine language called
bytecode. The JVM acts as an intermediary between bytecode and the
underlying physical machine.
Every platform that supports Java has its own implementation of the JVM.
Java applications are portable because every JVM adheres to a standard
interface. The distribution package of the JVM and standard libraries is called
the Java Runtime Environment (JRE). The distribution package of the JRE and
development tools, such as the compiler and debugger, is called the Java
Development Kit (JDK).
Procedural Programming vs Object-Oriented Programming
Procedural programming is a style of writing code that executes a series of linear
procedures to produce a result. Object-oriented programming is a style of writing
code that uses objects to encapsulate state and behavior. Procedural code
is easier to use in small projects or in multithreaded environments due to its
stateless nature, but object-oriented code is far more flexible and easier
to maintain.
Questions
What is the WORA principle? Why is it beneficial?
How can Java applications run on multiple platforms?
What is the difference between the JRE and the JDK?
What is the difference between procedural programming and object-oriented
programming?
Do'stlaringiz bilan baham: |