SCJP

Structure

  • Order of things in a file (comments disregarded): package decaration (optional)
  • There can only be one public class in a file.

Syntax

  • Reserved words to note: strictfp, assert, transient, const, native, default, volitile, instanceof.

Access and modifiers

  • Access modifiers:
    1. public: accessible to all in the Java Universe (JU)
    2. protected: accessible to other classes in the package, and subclasses in other packages
    3. private: only viewable by the class itself.
  • With no access modifier, the class has default behaviour - it is visible to all in the same package.
  • Non-access modifiers: strictfp, final, abstract.

Classes

  • If a class contains any abstract methods it must be delcared abstract.
  • abstract method declarations, including (implicit) abstract interface method declarations should end with a semicolon (;) and not curly braces.

Interfaces

  • An interface is a contract for behaviour with NO implementation code.
  • In an interface, the compiler treats method signatures as if they are prefixed by the modifiers public abstract. Both/either public and abstract keywords could be included but are unnecessary.
  • interfaces are allowed to include constants which may not be overwritten by classes that implement the interface. These constants must be public static final. However, they do not need to be declared with any of these modifiers as these are implicit.
  • instanceof is an operator, instanceOf() is a function.

Constructors

  • Constructors must never have a return type
  • A method may have the same name as the class (although it's bad practice), but this is not a constructor.
  • If no constructor is declared, the compiler will create a default zero argument constructor
  • All constructors must either call another constructor via this(args…..) or a constructor for the class that it extends, bubbling up until the zero argument constructor is called on Object. If no call is specified super() is called implicitly
  • Constructors can not be overridden by subclasses. A constructor with one or more objects will not call the super method with the same signature unless called explicitly, it will call super() unless another .
  • A constructor has to either call a super constructor (implicitly or expilitly) or a this as the first thing it does. It is not allowed to do work then call another constructor.
  • Because of this constructor chaining bubbles to the top (Object's empty constructor) then returns back down the inheritance tree, doing the work from top to bottom.

Links

 
scjp.txt · Last modified: 2009/04/21 09:12 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki