Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
34Activity
0 of .
Results for:
No results containing your search query
P. 1
SCJP

SCJP

Ratings: (0)|Views: 188|Likes:
Published by api-3864917

More info:

Published by: api-3864917 on Dec 04, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

SCJP 5.0 Quick Revision Notes
Objective: Declarations, I nitialization and Scoping
1.

The static import construct allows unqualified access to static members without inheriting from the type that contains those static members. Static imports can be performed for individual members or for a group of members.

For example:
import static java.lang.Math.PI;
// Here we import the constant PI individually from the Math class.
import static java.lang.Math.*;
//Here we import all the static members from the Math class.
2.
There are three top-level elements that may appear in a compilation unit. None of these
elements is mandatory. If they are present, then they must appear in the following order:
\u2022
package declaration
\u2022
import statements
\u2022
class definitions
3.

The filed members in an interface are implicitly public, final, and static. Interface methods cannot be native, static, synchronized, final, private, and protected. They are implicitly public, abstract, and non-static.

4.
A constructor
\u2022
has the same name as the class.
\u2022
has no return type.
\u2022
can be overloaded, but not inherited.
\u2022
can have any access, including private.
5.
Abstract classes

a. cannot be instantiated.
b. have one or more constructors.
c. may or may not have abstract methods.
d. may or may not have non-abstract methods.

6.
A default constructor is created by the compiler only if you have not provided any other constructor in the class. The
default constructor has no arguments and has the same access modifier as the class.
7.
A class can implement any number of interfaces, but it can extend only one class. An
interface can extend any number of interfaces, but it cannot implement another interface.
8.

A concrete (non-abstract) class implementing an interface has to implement all the methods declared in the interface. A concrete class extending an abstract class must define all the abstract methods defined in the latter.

9.
An enumeration is defined using theenum keyword, as shown below.
For example,
enum Fruit{
Apple,
Mango,
Banana
}
Variable of the definedenum type can then be created like this.
Fruit f;
10.
All enumerated types implicitly extend thejava.lang.Enum class.
11.
You can add methods toenums.
12.
Invoking the values() method on an enum returns an array of all the values in that type.
13.

When an array is created, all its elements are initialized to their default values, even if the array is declared locally. Static and instance variables of a class are also initialized with a default value. Local variables are never given a default value; they have to be explicitly initialized before use.

14.
A final class cannot be extended, so it is forbidden to declare a class to be both final and
abstract.
15.
According to the JavaBean naming standards, if the property name is 'x' and the type is
\u2018Type\u2019, the accessor method is of the form
Type getX()
and the mutator method is of the form
void setX(Type newValue)
However, a boolean property uses a different convention
boolean isX()
void setX(boolean newValue)
16.

Variable arguments (varargs) allow you to specify a method that can take multiple arguments of the same type and does not require that the number of arguments be predetermined.

For example, theformat method is now declared as follows:
public static String format(String pattern, Object... arguments);
The three periods(ellipsis) after the final parameter's type indicate that the final argument
may be passed as an array or as a sequence of arguments.
17.
You can only use one ellipsis per method. For example, the following is not allowed:
public Computer(String companyName, String model, String... components, double... componentPrices)
Also, the ellipsis must appear as the last argument to a method.
18.
It is legal to call the method without passing in the varargs parameter.

For example, we can invoke
Computer myComp=new Computer("HCL", "Celeron Model xxx");
even if the only constructor defined in the class is

public Computer(String companyName, String model, String... features)
So, a variable-length argument can take from zero to n arguments.
19.
An array can be passed in as the varargs parameter.
20.

Static methods and static variables of a class can be used without having any instances of that class at all. A static method cannot access non-static variables of the class. Static methods cannot be redefined as non-static in subclasses, and vice versa.

21.
An identifier is composed of a sequence of characters where each character can be a letter,
a digit, an underscore, or a dollar sign.An identifier cannot be a Java keyword and it cannot start with a
digit. It is possible to use class names as identifiers even though it is not a smart choice.
For Example:
number, $$abc, _x, String
// Legal
new, 15bb, he-he
// Illegal
22.

To get the array size, use the array instance variable called length. Arrays are indexed beginning with zero and end with length-1. Whenever you attempt to access an index value outside the range 0 to n-1, an ArrayIndexOutOfBoundsException is thrown.

23.

The return type of an overriding method should match that of the overridden method except in the case of covariant returns, as discussed in the next point. Return types of overloaded methods can be different, but changing only the return type is not legal. The arguments should also be different.

24.
Covariant return types allow a method in a subclass to return an object whose type is a
subclass of the type returned by the method with the same signature in the superclass.
25.

A method that declares a class as a return type can return any object which is of the subclass type. A method that declares an interface as a return type can return any object whose class implements that interface.

26.
A static nested class is a static member of the enclosing class. It does not have access to
the instance variables and methods of the class.
MyOuter.MyNested n = new MyOuter.MyNested();
27.
As the above example shows, a static nested class does not need an instance of the outer
class for instantiation.
28.
To instantiate a non-static inner class, you need an instance of the outer class.
A non-static inner class has access to all the members of the outer class. From inside the outer instance code, use the

inner class name alone to instantiate it:
MyInner myInner = new MyInner();
From outside the outer instance code, the inner class name must be included in the outer instance:

MyClass myClass = new MyClass();
MyClass.MyInner inner = myClass.new MyInner();
Objective: Flow Control

Activity (34)

You've already reviewed this. Edit your review.
1 hundred reads
Xuyang Zhang liked this
faisal_csedu liked this
neerajav liked this
atulkumar.it liked this
amitdpawar liked this
drsanbumd liked this
Jonathan Hollick liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->