Chapter 1 - Declarations and Access Control Flashcards
To pass the SCJP 6 exam (95 cards)
Access Modifiers Members can use
public
protected
default
private
Access Modifiers Classes can use
default
public
Class
A template that describes the kinds of state and behavior that objects of this type support
Object
When JVM encounters new keyword, make an instance of that class. Object will have its own state, and access to all behaviors defined by its class.
State
Each object has its own unique set of instance variables as defined by the class. All instance variables make up the objects state
Inheritance
Code in one class can be reused in other class. Superclasses are extended to more specific sub classes. Subclass inherits accessible instance variables and methods.
Interface
100-percent abstract superclass that identified the methods a subclass must support, but not how they must be supported.
Legal identifiers
- start with a letter, $, or connecting character like a _. Identifiers CANNOT start with a number
- after 1st character, can contain letters, $, connecting characters or numbers
- no limit to # of characters
- cant use JAVA keywords
- Identifiers are CASE sensitive
Classes and interfaces
First letter should be Capitalized, if more than 1 word, use camelcase.
Methods
First letter should be lowercase, then normal camelCase
Variables
start with lowercase, use camelCase
CONSTANTS
UPPER_CASE. use underscores for more than 1 word.
JavaBeans
Java classes that have properties. Properties are private instance variables only accessible by getter and setter methods
JavaBeans Naming Rules #1
If property is NOT boolean, methods prefix must be get, example getSize()
JavaBeans Naming Rules #2
If property is boolean, the getter method is get or is. For example getStopped() or isStopped()
JavaBeans Naming Rules #3
Setter method must prefex set, example setSize()
JavaBeans Naming Rules #3
Setter methods must be marked public, with void return type
JavaBeans Naming Rules #4
Getter methods must be marked public, take no arguments, and have a return type that matches the argument type of setter method for that property
JavaBean Listener Naming Rules #1
Listener methods names used to register a listener, must use the prefix add, followed by listener type: addActionListener()
JavaBean Listener Naming Rules #2
Listener methods used to remove a listener must use the prefix remove
JavaBean Listener Naming Rules #3
Listener method names must end with the word “Listener”
Source File Declaration Rules #1
There can be only one public class per source code file
Source File Declaration Rules #2
Comments can appear at the beginning or end of any line in the source code
Source File Declaration Rules #3
If there is a public class in a file, the name of the file must match the name of the public class. Example: public class Dog { } must be in source file as Dog.java