Inheritence:
Allows code in one class to be used in another class. Allows us to define a general(more abstract) superclass, and extend it with more specific sub-classes.
A subclass that inherits from the superclass is automatically given accessible instance variables and methods defined by the superclass, but is also free to override superclass methods to define more specific behavior.
Cohesive:
Cohesion indicates the degree to which a class has a single, well-focused urpose.
Every class should have a focused set of responsibilities. Cohesiveness defines the extent to which a class has a focussed set of responsibilities.
Coupling:
Coupling is the degree to which one class knows about another class.
How a class is tied to another-classes.
High cohesiveness and Loose coupling is desired.
Legal Identifiers:
- Identifiers must start with a letter, $ or _, cannot start with a number or special characters
- After the first character, Identifier can have any combination of letters, currency symbol, connecting characters or numbers
- No limit on the size of a legal identifier.
Class:
A class is a template that defines the state and behavior objects of its type support.
Naming a class - It should be a noun, with the first letter capitalized, and if it has more than one word, it should follow the "camelCase" notation. eg. Dog, Account, PrintWriter.
Interfaces:
Interface is like a 100% abstract superclass that defines the methods a subclass must support, but not how they must be supported.
- methods are public abstract(whether mentioned or not)
- variables are public static final(whether mentioned or not)
- An interface cannot be static, final, strictfp or native
- An interface can extend only another interface
- An interface cannot implement another interface or class
- An interface is always public abstract(whether mentioned or not)
eg. public abstract interface Rollable{}
Naming an interface - Should be an adjective. Other rules remain the same as that for a class. eg. Runnable.
Object:
Instance of a class, created by the JVM whenever it encounters the new keyword.
Naming Conventions (variables, constants & methods):
variable - Should have meaningful names (camelCase for long names)
constant(static final) - Should have meaningful names + CAPS
method - verb-noun combination, telling what it does. eg. getBalance, doCalculation, setCustomerName
Source File Naming Rules:
- There can be only one public class in a source file, Its name should be the name of the Java file
- There can be more than one non-public classes in a source file
- Source files with no public classes can have a name that does not match with any of the classes in the file.
Modifiers in Java (2 types):Access Modifiers: public(any class can acess), private(only class and its members can access), protected-(class & its sub-classes can access) & default - (package level access)
Non-access Modifiers: strictfp(floating point arithmatic corresponds to IEEE 754 standard rules), final & abstract
Abstract & Final Classes:
- A class cannot be both final & abstract(since final means the class cannot be sub-classed and abstract means the methods of the class needs to be implemented by the extending class)
- Abstract class cannot be instantiated
- An abstract class can have both abstract and non-abstract methods.
Class Access:
When we say Class A has access to Class B, it means Class A can:
- Create an instance of Class B
- Extend class B(ie. become a subclass of Class A)
- Access certain methods and variables of class B, depending on the access control of those methods & varables.
Access modifiers for local methods:
- Local varaibles cannot have access modifiers.
Click here for Part 2 - SCJP 1.5 - Chapter 1(Part 2) - Declaration and Access Control - Notes Allows code in one class to be used in another class. Allows us to define a general(more abstract) superclass, and extend it with more specific sub-classes.
A subclass that inherits from the superclass is automatically given accessible instance variables and methods defined by the superclass, but is also free to override superclass methods to define more specific behavior.
Cohesive:
Cohesion indicates the degree to which a class has a single, well-focused urpose.
Every class should have a focused set of responsibilities. Cohesiveness defines the extent to which a class has a focussed set of responsibilities.
Coupling:
Coupling is the degree to which one class knows about another class.
How a class is tied to another-classes.
High cohesiveness and Loose coupling is desired.
Legal Identifiers:
- Identifiers must start with a letter, $ or _, cannot start with a number or special characters
- After the first character, Identifier can have any combination of letters, currency symbol, connecting characters or numbers
- No limit on the size of a legal identifier.
Class:
A class is a template that defines the state and behavior objects of its type support.
Naming a class - It should be a noun, with the first letter capitalized, and if it has more than one word, it should follow the "camelCase" notation. eg. Dog, Account, PrintWriter.
Interfaces:
Interface is like a 100% abstract superclass that defines the methods a subclass must support, but not how they must be supported.
- methods are public abstract(whether mentioned or not)
- variables are public static final(whether mentioned or not)
- An interface cannot be static, final, strictfp or native
- An interface can extend only another interface
- An interface cannot implement another interface or class
- An interface is always public abstract(whether mentioned or not)
eg. public abstract interface Rollable{}
Naming an interface - Should be an adjective. Other rules remain the same as that for a class. eg. Runnable.
Object:
Instance of a class, created by the JVM whenever it encounters the new keyword.
Naming Conventions (variables, constants & methods):
variable - Should have meaningful names (camelCase for long names)
constant(static final) - Should have meaningful names + CAPS
method - verb-noun combination, telling what it does. eg. getBalance, doCalculation, setCustomerName
Source File Naming Rules:
- There can be only one public class in a source file, Its name should be the name of the Java file
- There can be more than one non-public classes in a source file
- Source files with no public classes can have a name that does not match with any of the classes in the file.
Modifiers in Java (2 types):Access Modifiers: public(any class can acess), private(only class and its members can access), protected-(class & its sub-classes can access) & default - (package level access)
Non-access Modifiers: strictfp(floating point arithmatic corresponds to IEEE 754 standard rules), final & abstract
Abstract & Final Classes:
- A class cannot be both final & abstract(since final means the class cannot be sub-classed and abstract means the methods of the class needs to be implemented by the extending class)
- Abstract class cannot be instantiated
- An abstract class can have both abstract and non-abstract methods.
Class Access:
When we say Class A has access to Class B, it means Class A can:
- Create an instance of Class B
- Extend class B(ie. become a subclass of Class A)
- Access certain methods and variables of class B, depending on the access control of those methods & varables.
Access modifiers for local methods:
- Local varaibles cannot have access modifiers.
No comments:
Post a Comment