Monday, February 15, 2010

Declarations and Access Control

Hello...
It's nice to have you visiting my posting. Let's get start to the points and main objectives, SCJP. By this time we have to assume you have basic understanding of Java. If not, please keep the pace and hope you are willing to take longer time and patience.

In this first chapter we'll talk about Declacations and Access Control which is divided into 4 sub-chapters
# Identifiers and JavaBeans
# Class Declaration
# Interface Declaration
# Class Members Declaration

Before we get deeper to each of them, lets review some basic understandings and terms in Java.
a) Class : it's not where you have your lecture, but class in Java is a template with state and behavior that an object has.
b) Object : as the Java Virtual Machine (JVM) runs at runtime, it will create a new object from class when it encounters "new" key word.
c) State (instance variables) : values assigned to objects' instance are the object's state
d) Behavior (methods) : methods is the behavior or actions of the class. Methods are the actual excecutor of actions in the

Identifiers and Keywords

Identifiers are the names for Java components, like class' name and object's name. Later we'll talk more detail about the legal rules for identifiers.

Just like the other programming language, Java also has several reserverd words known as keywords which cant be used as identifiers.

Inheritance

As an Object-Oriented Programming (OOP), Java has the concept of inheritance which means that codes defined in one class can be used in other classes, known as parent-child relation. The subclass has every Class members that superclass possesses that are assigned public or protected.

For instance, an "Animal" superclass has numOfLegs and run(), then its subclass, "Horse" will also have both of them, and it can aslo override the "run()"

Interfaces

One superb example of 'inheritance' is interface which is like a perfect abstract superclass because it only defines the methods on the superclass but it doesn't support the way it should be implemented. The subclass, therefore, should implement those superclass methods.

Finding Other Classes

It's impossible to create a program totally from scratch, whether you want or not, you will need to use another programmer's code such as Java's API classes or your friends' special function code. By organizing the classes into "package", you can use "import" to get access to that out-source code.