Win a copy of Practice Tests for OCP Java 17 Certification Exam (1Z0-829) this week in the OCPJP forum!

Bilal Al-Sallakh

Greenhorn
+ Follow
since Jan 28, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Bilal Al-Sallakh

While most peoble think it's not possible to subclass a non-static inner class, this is not true:



or:


if (c.equals(d)) System.out.println("c and d are equals");
if (c.equals(e)) System.out.println("c and e are equals");
c is primitive! (compile time error)!

if (a.intValue() == ((Long)b).longValue()) System.out.println("EQ ab");
Invalid cast at compile-time.

I think most others will print, oder?
Tiger doesn't support enums hierarchy --> an enum is effectively final. But since value-specific methods through anonymous inner classes will be bowerfull, it allows this special type of subclassing --> it allows abstract methods, yet the enum itself still final (can't be subclassed) --> can't be declared abstract (nor final!).

Originally posted by Nicholas Cheung:
Thanks for your work.

However, I suggest that it is better to change the title to something like:
Notes/Tips for some APIs in SCJP 1.5.

Nick



Richtig! You are right Nicholas! I just wanted to share some of my sketchs while I was reviewing the APIs. BTW there are some mistakes: parse in NumberFormat returns Number rather than int.

Originally posted by rathi ji:
why so ???



You may find a solid data-structures foundation in many data-structures and algorithms book. I think a good java programmer should already be familiar with them.

Originally posted by rathi ji:
why so ???



You may find a solid data-structures foundation in many data-structures and algorithms book. I think a good java programmer should already be familiar with them.

Originally posted by Steven Bell:
So you go from a O(1) operation to a O(n^2) operation.



I think he goes from an O(1) operation to an O(n) one.

Originally posted by Steven Bell:
So you go from a O(1) operation to a O(n^2) operation.



I think you he goes from an O(1) operation to an O(n) one.
If you are using an ArrayList, it doesn't matter.
If you are using a LinkList, the Iterator is clearly more effecient.
Classes mentioned in Objective 3.2, 3.3 + serialization....
the following method

pulic static Thread currentThread()

when called returns a Thread reference to the currently executing thread (maybe in order to control it).

What is the result if we call the method when the JVM runs on a SMP (Symmetric MultiProcessor)? As I know several threads are truly running concurrently...
Iterator: haveNext(), next(), remove();

JavaBeans naming standards: set, get, is

StringBuffer:
charAt(i)
setCharAt(i)
append(prim), append(char[]), append(Object)
insert(offset, ...)
deleteCharAt(i)
delete(start, end)
reverse()
setLength(i)
insureCapacity(i)
capacity()

Appropriate use of assertions (not for checking parameters in public methods, conditions that

should always hold).

famous thowables:
ArrayIndexOutOfBounds, ClassCast, NullPointer, IllegalArgument, IllegalState, NumberFormat
Errors: Assertion, StackOverflow, NoClassDefFound, ExceptionInInitializer

Wrappers:
Finals, Immutables
Wrapper(prim);
Wrapper(String);
Wrapper static valueOf(String);
xxx xxxValue();
prim parsePrim();

File:
boolean isFile(), isDirectory(), exists(), canRead(), canWrite()
boolean delete(), renameTo(), mkdir()
String getName(), getParent(), getPath(), getAbsolutePath(),
String[] list(); // it should be a dir

FileReader(File/String): char trio
BufferedReader(Reader): trio + String readLine
BufferedWriter(Reader): pento + newLine();
PrintWriter(InputStream): pento + print + printf + println

FileInputStream(File/String): byte trio
DataInputStream(InputStream): + readPrim + readUTF
ObjectInputStream(InputStream): + readObject

Pattern:
Pattern compile(String)
Matcher matcher()
String[] split(String)

Matcher:
boolean matches(), lookingAt(), find()
int start(), int end(), String group()

Regular expression:
* + ?: A*, AA*, A|epsilon
[] (or): [abc]
. (any_char) \d (digit) \s (space) \w (word = [A-za-z\d_])
() for grouping

Formatter:
Formatter format([Locale,] format string, Object[]);
Appendable out();

Scanner:
XXX nextXXX(), boolean hasNextXXX();

Locale:
Locale("en", "US");
String getISO3Country();
String getISO3Language();
String getDisplayCountry(Locale);
String getDisplaylanguage(Locale);
String getDisplayName(Locale);
static Locale getDefault();
static Locale[] getAvailableLocales();
static setDefault();

java.text:

DateFormat:
DateFormat getDateInstance(int, Locale);
DateFormat getTimeInstance(int, Locale);
DateFormat getDateTimeInstance(int, int, Locale);
DateFormat getInstance()
= getDateTimeInstance(SHORT, SHORT, Locale.getDefault());
int SHORT, FULL;

Date parse(String);
String format(Date());

NumberFormat:
int parse(String);
String format(long), format(double), format(Object)
NumberFormat:getInstance(Locale),
getNumberInstance(Locale), getIntegerInstance(Locale),
getDoubleInstance(Locale), getCurrencyInstance(Locale)


Collection: add, remove, contains
Map: put, get, remove, containKey, containValue
Set: Collection
List: Collection + get, set


List:
sorting: void Collections.sort(List);
binarySearch:int Collections.binarySearch(List);
to arrays:Object[] Collection.toArray();

ِArrays:
sorting:
void Arrays.sort(Object[]);
void Arrays.sort(Object[]);
void Arrays.sort(Prim[]);

binarySearch:
void Arrays.binarySearch(Object[]);
void Arrays.binarySearch(Prim[]);

to list:
List Arrays.toList(Object[]); // a view --> size can't change


java.util.Comparator, java.lang.Comparable to affect the sorting of lists and arrays.
In the SCJP 1.5 Beta exam objectives, the 2.6 objective is:

2.6 Recognize situations that will result in any of the following being thrown: ArrayIndexOutOfBoundsException, ClassCastException, IllegalArgumentException, IllegalStateException, NullPointerException, NumberFormatException, AssertionError, ExceptionInInitializerError, StackOverflowError or NoClassDefFoundError. Understand which of these are thrown by the virtual machine and recognize situations in which others should be thrown programatically.

Am I right in the following?

Thrown by JVM
ArrayIndexOutOfBoundsException
ClassCastException
NullPointerException
AssertionError
StackOverflowError
NoClassDefFoundError
ExceptionInInitializerError

Thown Programatically
NumberFormatException
IllegalArgumentException
IllegalStateException

Originally posted by Jeroen Wenting:
interfaces are NOT static by default.


Edwin means that memeber interfaces are implicitly static and I think this is right.