28 February 2008

Object Orientation (Part I)

OBJECTIVES :

  • Declare Interfaces
  • Declare, Initialize, and Use Class Members
  • Use Overloading and Overriding
  • Develop Constructors
  • Describe Encapsulation, Coupling and Cohesion
  • Use Polymorphism
  • Relate Modifiers and Inheritance
  • Use Superclass Constructors and Overloaded Constructors
  • Use IS-A and HAS-A Relationships

26 February 2008

Declarations and Access Control (Part III)

Other Modifiers—Members :

  • final methods cannot be overridden in a subclass.
  • abstract methods are declared, with a signature, a return type, and an optional throws clause, but are not implemented.
  • The synchronized modifier applies only to methods and code blocks.
  • synchronized methods can have any access control and can also be marked final.
  • The native modifier applies only to methods.
  • The strictfp modifier applies only to classes and methods.
Methods with var-args :
  • As of Java 5, methods can declare a parameter that accepts from zero to many arguments, a so-called var-arg method.
  • A var-arg parameter is declared with the syntax type... name; for instance : doStuff(int... x) { }.
  • A var-arg method can have only one var-arg parameter.
  • In methods with normal parameters and a var-arg, the var-arg must come last.
Variable Declarations :
  • Instance variables can have any access control and be marked final or transient.
  • Instance variables can't be abstract, synchronized, native, or strictfp.
  • It is legal to declare a local variable with the same name as an instance variable; this is called "shadowing."
  • final variables cannot be reinitialized once assigned a value.
  • final reference variables cannot refer to a different object once the object has been assigned to the final variable.
  • final reference variables must be initialized before the constructor completes.
  • There is no such thing as a final object. An object reference marked final does not mean the object itself is immutable.
  • The transient modifier applies only to instance variables.
  • The volatile modifier applies only to instance variables.
Array Declarations :
  • Arrays can hold primitives or objects, but the array itself is always an object.
  • When you declare an array, the brackets can be to the left or right of the variable name.
  • It is never legal to include the size of an array in the declaration.
Static Variables and Methods :
  • They are not tied to any particular instance of a class.
  • No classes instances are needed in order to use static members of the class.
  • There is only one copy of a static variable / class and all instances share it.
  • static methods do not have direct access to non-static members.
Enums :
  • An enum specifies a list of constant values that can be assigned to a particular type.
  • An enum can be declared outside or inside a class, but NOT in a method.
  • An enum declared outside a class must NOT be marked static, final, abstract, protected, or private.
  • enum constructors can NEVER be invoked directly in code. They are always called automatically when an enum is initialized.
  • The semicolon at the end of an enum declaration is optional.

23 February 2008

Declarations and Access Control (Part II)

Identifiers :

  • Identifiers can begin with a letter, an underscore, or a currency character.
  • After the first character, identifiers can also include digits.
  • Identifiers can be of any length.
  • JavaBeans methods must be named using camelCase, and depending on the method's purpose, must start with set, get, is, add, or remove.
Declaration Rules :
  • A source code file can have only one public class.
  • If the source file contains a public class, the filename must match the public class name.
  • A file can have only one package statement, but multiple imports.
  • The package statement (if any) must be the first (non-comment) line in a source file.
  • The import statements (if any) must come after the package and before the class declaration.
  • package and import statements apply to all classes in the file.
  • A file can have more than one nonpublic class.
  • Files with no public classes have no naming restrictions.
Class Access Modifiers :
  • There are three access modifiers: public, protected, and private.
  • There are four access levels: public, protected, default, and private.
  • Classes can have only public or default access.
  • A class with default access can be seen only by classes within the same package.
  • A class with public access can be seen by all classes from all packages.
  • Class visibility revolves around whether code in one class can create an instance of another class, extend (or subclass), another class and access methods and variables of another class.
Class Modifiers :
  • Classes can also be modified with final, abstract, or strictfp.
  • A class cannot be both final and abstract.
  • A final class cannot be subclassed.
  • An abstract class cannot be instantiated.
  • A single abstract method in a class means the whole class must be abstract.
  • The first concrete class to extend an abstract class must implement all of its abstract methods.
Interface Implementation :
  • Interfaces are contracts for what a class can do, but they say nothing about the way in which the class must do it.
  • An interface can have only public and abstract methods, no concrete methods allowed.
  • Interfaces can have constants, which are always implicitly public, static, and final.
  • Interfaces can only extend one or more other interfaces.
Member Access Modifiers
  • Members can use all four access levels: public, protected, default, private.
  • public members can be accessed by all other classes, even in other packages.
  • private members can be accessed only by code in the same class.
  • Default members can be accessed only by classes in the same package.
  • protected members can be accessed by other classes in the same package, plus subclasses regardless of package.
  • A protected member inherited by a subclass from another package is not accessible to any other class in the subclass package, except for the subclass' own subclasses.

Declarations and Access Control (Part I)

OBJECTIVES :

  • Declare Classes and Interfaces
  • Develop Interfaces and Abstract Classes
  • Use Primitives, Arrays, Enums and Legal Identifiers
  • Use Static Methods, JavaBeans Naming, & Var-Args

22 February 2008

Great book for the certification

I have found this book. I think it will be very usefull to prepare the certification

SCJP Sun Certified Programmer for Java 5 Study Guide


21 February 2008

Sun Certified Java Programmer (SCJP)

Finally I decided to be SCJP certified. It's going to be one of my goals for 2008.
The Java certifications are used to two things:
  1. The mention on your CV that you are certified by Sun: It is a small Like beef that receives a label, or a wine that receives a drink Champagne appellation. Now, like everyone else does not pay attention to these labels, all companies do not even pay attention to the fact that you are Java certified or not.
  2. Judge your level: Personally, it is for this reason that I have decided to to be SCJP certified, to finally know at what level I am located, after more than 3 years of Java development.
What are the benefits we gain?
First, a personal satisfaction. Then, somewhere was your level of knowledge before certification, the fact that you have study and train you to pass the certification, you will have learned something new.
For some businesses, it's also the key that will allow you to be selected for offered the position in relation to other candidates who are not certified.
Ok then, let's Goooo !!!!

19 February 2008

Determining list size using Struts


This is an exemple showing how to detect the size of a list using struts . We can use the bean:size tag that
define a bean containing the number of elements in a Collection.

<bean:size id="listSize" name="listForm" property="myList">
<nested:iterate property="
myList" indexid="index">
.....
<% if((index.intValue() + 1) == listSize.intValue()) { %>
           End
< % }%>
< /nested:iterate>

HelloWorld.java

This blog is a corner to share with you my little knowlage and my simple experience in life.