Witscale Test Center


The SCJP HandbookTM

 

Table Of Contents

Google
 


Preface

 

Preface
   Structure of this Book
   How to Read this Book
   Conventions used in this Book
   Who Should Read this Book
   
   References

 


Chapter 1
Java declaration basics
 
1.1 Java language constructs
1.2 The Java class
   1.2.1 Simple class declaration
   1.2.2 Details of class declaration
   1.2.3 Details of interface declaration
   1.2.4 UML notation for class
1.3 Variable declarations
   1.3.1 Data types
   1.3.2 Scope of variable declaration
1.4 Method declarations
   1.4.1 Method declaration without a method body
   1.4.2 Invoking methods of an object
1.5 Object creation with constructors

   1.5.1 The new keyword
   1.5.2 Object creation behind the scene
   1.5.3 Calling constructors using the keywords, this and super
1.6 Package and import statements
   1.6.1 Package declaration
   1.6.2 Import statements
Chapter summary

 


Chapter 2
Java and OOP

2.1 Introduction
2.2 Objects
   2.2.1 What is a Class?
   2.2.2 Instantiating a Class and invoking its methods
   2.2.3 Communicating objects
2.3 Implementing three basic principles of OOP in Java
   2.3.1 Encapsulation
   2.3.2 Classes and inheritance
   2.3.3 Polymorphism
2.4 Object Oriented features of Java
Chapter summary

 


Chapter 3
Modifiers

SCJP Objectives covered
3.1 Overview of modifiers
   3.1.1 The access modifiers
   3.1.2 Other modifiers
3.2 Modifiers for access control
   3.2.1 The private modifier
   3.2.2 The (default) modifier
   3.2.3 The protected modifier
   3.2.4 The public modifier
   3.2.5 Access modifiers at glance
3.3 Class modifiers
   3.3.1 The abstract modifier
   3.3.2 The final modifier
3.4 Member variables and modifiers
   3.4.1 Static variables
   3.4.2 Transient variables
   3.4.3 Volatile variables
   3.4.4 Final variables
3.5 Method declaration and modifiers
   3.5.1 Abstract methods
   3.5.2 Static methods
   3.5.3 Final methods
   3.5.4 Native methods 
   3.5.5 Synchronized methods
3.6 Code blocks and modifiers
   3.6.1 Free floating blocks
   3.6.2 Static initializer block and its use
3.7 Interface and modifiers
   3.7.1 Interface methods and modifiers
   3.7.2 Interface constants and modifiers
   3.7.3 Interface and implicit modifiers
3.8 Constructors and modifiers
   3.8.1 Private constructor and singleton Class
   3.8.2 Constructor with default access
   3.8.3 Constructor with protected access
   3.8.4 Constructor with public access
   3.8.5 Declaration facts for constructors
3.9 Default constructor
Chapter summary
Sample test
Answers with explanations

 


Chapter 4
Nested Classes

SCJP Objectives covered
4.1 Nested classes
4.2 Why inner classes
    4.2.1 The object-oriented reasons
   4.2.2 The ease of event handling
   4.2.3 The organizational reasons
4.3 Nested class types
4.4 Non-static member class (aka member inner class)
   4.4.1 Instantiating a member inner class
   4.4.2 Instantiation within the enclosing class
   4.4.3 Accessibility of variables
   4.4.4 Referencing the enclosing instance
4.5 Static nested classes.
   4.5.1 Instantiation of static nested class
   4.5.2 Accessibility of variables
4.6 Local inner class
   4.6.1 Declaration rules for method-local inner class
   4.6.2 Instantiation
   4.6.3 Accessibility of variables
4.7 Anonymous inner class
   4.7.1 Anonymous class implementing an interface
   4.7.2 Passing arguments to superclass constructors
   4.7.3 Modifiers and anonymous class
   4.7.4 Accessibility of variables
   4.7.5 Initialization of an anonymous class
   4.7.6 Passing an anonymous class instance as an argument
Chapter summary
Sample test
 Answers with explanations

 


Chapter 5
Flow control, Assertions & Exception Handling

SCJP Objectives covered
5.1 Flow control statements
5.2 Conditional statements: if, if-else and switch
   5.2.1 The if statement
   5.2.2 The if-else statement
   5.2.3 Argument to the if statement
   5.2.3 The switch statement
5.3 Iterative statements while, do-while and for
   5.3.1 The while loop
   5.3.2 The do-while loop
   5.3.3 The for loop
5.4 Interrupting the loops
   5.4.1 break and continue
   5.4.2 break and continue with labels
5.5 Exceptions
   5.5.1 Handling an exception
   5.5.2 Defining an exception
   5.5.3 Throwing an exception
   5.5.4 Declaring exceptions in overridden method
5.6 Assertions
   5.6.1 How to use assertions
   5.6.2 The assert statement and AssertionError class
   5.6.3 Compiling code that contains assertions
   5.6.4 Enabling and disabling assertions at runtime
   5.6.5 Using assertions appropriately
Chapter summary
Sample test         
Answers with explanations

 


Chapter 6
Garbage Collection


SCJP Objectives Covered
6.1 Memory management in Java
6.2 How does an object becomes garbage?
6.3 When does an object get garbage-collected?
 6.4 How does the garbage collector work?
   6.4.1 Garbage collection algorithms
   6.4.2 Tradeoffs between the garbage collection algorithms
6.5 Explicitly making object eligible for garbage collection
   6.5.1 Orphaning an object
   6.5.2 Cyclic references
6.5 When are objects implicitly eligible for garbage collection?
6.6 String literals and garbage collection
6.7 Requesting a garbage collection
6.8 What garbage collection does not guarantee
6.9 The finalize() method
Chapter Summary
Sample test
Answers with explanations

 


Chapter 7
Primitives & Arrays

SCJP Objectives
7.1 Keywords and identifiers
7.2 Primitive data types and their ranges
7.3 Literals
   7.3.1 Boolean literals
    7.3.2 Character literals
    7.3.3 Integral literals
   7.3.4 Floating-point literals
    8.3.5 String literals
7.4 Arrays
   7.4.1 Arrays declaration
   7.4.2 Arrays construction
   7.4.3 Array initialization
   7.4.4 Using the arrays
   7.4.5 Multidimensional array
Chapter summary
Sample Test
Answers with explanations

 


Chapter 8
Class Fundamentals


SCJP Objectives Covered
8.1 Java source file
   8.1.1 The top-level class and declaration rules
   8.1.2 Declaration rules for package and import statements
8.2 The main() method
   8.2.1 Signature of main method
   8.2.1 Arguments to the main method
8.3 Initialization of variables
   8.3.1 Initialization of member variables
   8.3.2 Initialization of local variables
8.4 Interface implementation
   8.4.1 Implementation rules
Chapter summary
Sample test
Answers with explanations

 

Chapter 9
Operators


SCJP Objectives Covered

9.1 Operators
9.2 Operators precedence
9.3 Unary operators
   9.3.1 Unary plus + and minus - operators
   9.3.2 Increment ++ and decrement -- operators
    9.3.3 Bitwise complement ~ operator
   9.3.4 Logical complement ! operator
   9.3.5 The cast () operator
9.4 Binary operators
   9.4.1 Multiplication * and division / operators
   9.4.2 Modulo operator %
   9.4.3 The addition + and subtraction - operators
   9.4.4 Arithmetic erroneous conditions
   9.4.5 The shift operators
   9.4.6 Comparison operators
   9.4.7 The bitwise operators: & ^ and |
   9.4.8 Short circuit && (AND) and || (OR) operators
9.5 Ternary operator ?:
9.6 Assignment operators
   9.6.1 Assignment returns a value
9.7 Order of evaluation
Chapter summary
Sample test
Answers with explanations

 

Chapter 10
Conversion, Casting and Arithmetic promotion


SCJP Objectives Covered
10.1 Type changes in Java
10.2 Data types and contexts of type change
10.3 Type conversion in primitives
   10.3.1 Widening conversions in primitives
   10.3.2 Primitive type conversion during assignment
   10.3.3 Literals and primitive type conversion during assignment
   10.3.4 Primitive type conversion during a method call
    
   10.3.5 Primitive type conversion during unary and binary operations (Numeric Promotion)
   10.3.6 Primitive type casting
10.4 Object reference conversions
   10.4.1 Three types of object references
   10.4.2 Rules of object reference conversion
   10.4.3 Array reference conversion
   10.4.4 Object reference conversion during a method call
10.5 Object reference casting
   10.5.1 Compile time rules for reference casting
   10.5.2 Runtime rules for reference casting
    
   10.6 Conversion and casting in method return types
Chapter summary
Sample test
Answers with explanations

 


Chapter 11
Method Overloading & Overriding


SCJP Objectives Covered
11.1 Encapsulation and implementation hiding
    
   11.1.1 Implementing tight encapsulation
   11.1.2 Benefits of encapsulation
11.2 Composition and generalization
   11.2.1 The generalization and IS-A relationship (inheritance)
   11.2.2 Implementing IS-A relationship
   11.2.3 The composition and HAS-A relationship
   11.2.4 Implementing HAS-A relationship
11.3 Method overloading and overriding
   11.3.1 Method overloading
   11.3.2 Method overriding
   11.3.3 Constructor overloading
   11.3.4 Methods are overridden but variables are shadowed
Chapter summary
Sample test
Answers with explanations

Chapter 12
Threads


SCJP Objectives Covered
12.1 Thread basics
   12.1.1 What is thread?
   12.1.2 What happens when a thread is started?
   12.1.3 Scheduling the execution of multiple threads
   12.1.4 The life cycle of thread and various thread states
   12.1.5 Why little is guaranteed when multiple threads are running?
   12.1.6 How multiple threads are executed?
   12.1.7 What happens behind the scene when multiple threads are executed?
12.2 Conditions that prevent the running of a thread for some time
   12.2.1 Methods in java.lang.Thread that influence the thread scheduling
   12.2.2 Methods in java.lang.Object that influence the thread scheduling
   12.2.3 Summary of conditions that prevents threads execution (moves it out from running state)
12.3 Access to shared data/code with synchronization
   12.3.1 Coordinating access to common data/ code
   12.3.2 Which methods should be synchronized?
   12.3.2 How does the synchronization work?
   12.3.3 How to synchronize a part of method?
   12.3.4 Things to remember about synchronization
   12.3.5 Deadlock
   12.3.6 Synchronizing the static methods
12.4 Thread interaction with wait(), notify() and notifyAll()
   12.4.1 The wait and notify mechanism
   12.4.2 The wait(), notify() and notifyAll() methods
   12.4.3 Simple example using the wait(), notify() methods
   12.4.4 The notify() and notifyAll() methods
   12.4.5 Implementing wait-and-notify in a complex example
Chapter summary
Sample test
Answers with explanations

 


Chapter 13
Fundamental Classes in java.lang package


SCJP Objectives Covered
13.1 The java.lang package
13.2 The java.lang.Math class
   13.2.1 The constants defined in Math class
   13.2.2 The methods defined in Math class
13.3 The java.lang.String class
   13.3.1 String objects are immutable.
   13.3.2 Changing a reference does not mean the String object is changed.
   13.3.3 String objects created as literals are immutable too.
   13.3.4 Methods on String objects that appears to be changing it.
   13.3.5 Why the String class is marked final?
   13.3.6 Methods of String class
   13.3.7 Creation of String objects
13.4 The java.lang.StringBuffer class
   13.4.1 StringBuffer objects are mutable (changeable).
   13.4.2 Methods of StringBuffer
   13.4.3 Things to remember about String and StringBuffer class
13.5 The wrapper classes
   13.5.1 How to create wrapper objects?
   13.5.2 The immutability of wrapper objects
   13.5.3 How to get primitive values from the wrapper objects?
   13.5.4 How to get the primitive values from string objects?
   13.5.5 How to get string objects from the wrapper objects?
   13.5.6 Summary of important methods of wrapper classes in java.lang
   13.5.7 The constants defined in wrapper objects
13.6 The java.lang.Object class
   13.6.1 The methods defined in Object class
   13.6.2 The equals() method in Object, String and wrapper classes
Chapter summary
Sample test
Answers with explanations

 


Chapter 14
The Collection framework


SCJP Objectives covered
14.1 Overview of Collection framework
14.2 Six core interfaces
14.3 The concrete classes implementing the core interfaces
   14.3.1 List
   14.3.2 Set
    
   14.3.3 Map
14.4 The Collection interface and the Collections class
   14.4.1 The core interface java.util.Collection
   14.4.2 The utility class java.util.Collections
   14.4.3 The utility class java.util.Arrays
14.5 The iterator interface
14.6 Overriding the equals() and hashCode() methods
   14.6.1 The equals() method
   14.6.2 Overriding the equals() method
   14.6.3 Method contract for the equals() method
   14.6.4 The hashCode() method
   14.6.5 Overriding the hashCode() method
   14.6.5 The contract of hashCode() method
Chapter Summary
Sample Test
Answers with explanations

 

 


Appendix A
Basics Of Java Architecture

A.1 How Java works
   A.1.1 How Java program compiles?
   A.1.2 How Java program runs?
   A.1.3 JVM and platform independence
A.2 The Java Development Kit
A.3 Downloading and installing JDK
A.4 JDK utilities
A.5 Building Java applications with JDK
   A.5.1 Java Source code
   A.5.2 Compiling source code using javac
   A.5.3 Running a Java Application using java interpreter
   A.5.4 The Java Runtime Environment (JRE)