Wednesday, July 11, 2007

an article on unicode

While doing some research on unicode and Java, I ran across a reference to this article on basics. The opening is quite funny, so I'm looking forward to reading it.

Labels: , ,

Monday, July 09, 2007

debugging your java classpath

Trying to run stuff from my command line was an interestingly frustrating experience, but this FAQ-type page came in very handy.

Labels:

Wednesday, June 20, 2007

practice test take 1

I got about 72% on my first practice test for SCJP Java 1.4. Had about 44 minutes left over. Not bad, but can do better. The actual test will probably be more difficult so I'd like more than a 20% buffer.

Labels: ,

Monday, April 30, 2007

Java: Processes and Threads

The Java Tutorials > Essential Classes > Concurrency > Processes and Threads

Sanghera's book confused me so I had to review the differences between processes and threads!

A process has a self-contained execution environment. A process generally has a complete, private set of basic run-time resources; in particular, each process has its own memory space.

...

Threads are sometimes called lightweight processes. Both processes and threads provide an execution environment, but creating a new thread requires fewer resources than creating a new process.

Labels: , ,

Java: bounded wildcards

The Java Tutorials > Bonus > Generics > Wildcards

public void drawAll(List shapes) {
...
}

There is a small but very important difference here: we have replaced the type List with List. Now drawAll() will accept lists of any subclass of Shape, so we can now call it on a List if we want.

List is an example of a bounded wildcard. The ? stands for an unknown type, just like the wildcards we saw earlier. However, in this case, we know that this unknown type is in fact a subtype of Shape. (Note: It could be Shape itself, or some subclass; it need not literally extend Shape.) We say that Shape is the upper bound of the wildcard.

There is, as usual, a price to be paid for the flexibility of using wildcards. That price is that it is now illegal to write into shapes in the body of the method. For instance, this is not allowed:

public void addRectangle(List shapes) {
shapes.add(0, new Rectangle()); // Compile-time error!
}

You should be able to figure out why the code above is disallowed. The type of the second parameter to shapes.add() is ? extends Shape-- an unknown subtype of Shape. Since we don't know what type it is, we don't know if it is a supertype of Rectangle; it might or might not be such a supertype, so it isn't safe to pass a Rectangle there.


On the other hand, if you specify the upper bound of the wildcard, it's okay to add items to the List shapes.

Labels: ,

Java: regular expressions

The Java Tutorials: Essential Classes > Regular Expressions > Quantifiers

Greedy Meaning
X? X, once or not at all
X* X, zero or more times
X+ X, one or more times
X{n} X, exactly n times

Need to memorize these.

Labels: , ,

Java: formatters

I'll need to revisit this topic as I only have superficial comprehension of Java Formatters like NumberFormat.

Currency objects are distinct from locales because a particular locale may use multiple currencies.

Labels: , , ,

Java: super keyword

http://java.sun.com/docs/books/tutorial/java/IandI/super.html

Invocation of a superclass constructor must be the first line in the subclass constructor.

The syntax for calling a superclass constructor is

super();
--or--
super(parameter list);

Labels:

Friday, April 27, 2007

update on Sanghera's SCJP Exam for J2SE 5

I've started rereading the book, and I definitely don't recommend it for preparing for the SCJP exam for J2SE 5.

There are so many errors! Significant errors, like what exception FileReader and FileWriter throw from their read/write methods - there's a table aggregating the I/O exceptions for various Stream classes and their read/write methods, and it's wrong. Kind of annoying. Keeps me sharp, I supposed, but the Sun book has to be better.

Also, the lack of formatting of code snippets is really annoying; it's hard to read.

I'll post a list of the errata later.

For now:
p.209
* "public FileReader(...) throws IOException"
should be "throws FileNotFoundException"

p.210
* "public FileWriter(...) throws IOException"
should be "throws FileNotFoundException"

p.214
* Table 8-6 FileReader, FileWriter exception thrown by Read/Write Methods should be IOException.

p.214
* It alternatively refers to "a string and two objects are written to the stream" and "the String and the Date Objects that were written to the file," when the first code snippet writes two Strings and one Object.

* bottom code snippet "(MyClassSerial)" should be "(MySerialClass)" on the 4th and 5th lines.

Labels: ,

Sunday, January 14, 2007

Java 5 SCJP take 2!

After being a little demoralized last year (what, I can't learn the new features in 4 weekends?), it's time to take up the gauntlet again and count down till June when I absolutely have to take the Java Certified Programmer Exam for Java 5. My voucher expires then, as I mistakenly bought the voucher before I was ready to pass the exam.

Do not buy the exam voucher until you finished 80% of your studying! Would be my suggestion in order to save you money.

Because it would be unhappiness to fail the exam.

Anyway, take 2 begins!

Wish me luck.

Current useful study guides:
* Java Tutorial for the Sun Certified Java Programmers Exam
* a practice exam a day (Java 5)
* last minute review guide

I'm thinking about buying this study guide:
http://bookweb.kinokuniya.co.jp/guest/cgi-bin/booksea.cgi?ISBN=0072253606&BN=OFF
But am balking a bit at the cost. Still, it's convenient.

There's also Marcus Green's book.

In the end, Sanghera's book left me more confused than anything. I guess I really need to practice and work out the new concepts; just reading a book won't do it all.

Labels: ,

Monday, September 18, 2006

SCJP 5.0: Collections: the Map Interface

Some Map Interface methods:

void clear()

boolean containsKey(Object key)

boolean containsValue(Object value)

boolean equals(Object obj)

Object get(Object key)

int hashcode()

boolean isEmpty()

Object put(Object key, Object value)

void putAll (Map m)

Object remove(Object key)

int size()

Collection values()

For more detail see Sun's tutorial.

Labels: ,

SCJP 5.0: Collections: the Collections Interfaces

Collection
^ ^
| |
List Set
^
|
SortedSet


Map
^
|
SortedMap

Labels: ,

SCJP 5.0: Collections: the Collection Interface

Some methods in the Collection Interface:

boolean add(Object obj)
boolean addAll(Collection c)

void clear()

boolean contains(Object obj)
boolean containsAll(Collection c)

boolean isEmpty()

boolean equals(Object obj)

int hashcode()

boolean remove(Object obj)
boolean removeAll(Collection c)

Iterator iterator()

T[] toArray(T[] array)

For more detail see Sun's tutorial.

Labels: ,

Sunday, May 28, 2006

Java servlet

What is a servlet?

From Stefan Zeiger's novocode.com:
Servlets are modules of Java code that run in a server application (hence the name "Servlets", similar to "Applets" on the client side) to answer client requests. Servlets are not tied to a specific client-server protocol but they are most commonly used with HTTP and the word "Servlet" is often used in the meaning of "HTTP Servlet".

Labels:

Sunday, May 21, 2006

Struts and file upload

I'm trying to use a form that has a array of FormFile as a field of the form.

I can use to display the FormFiles with no problem, but when I submit the form, the array only has null values.

To be completely specific, I made a bean where one of the fields is a FormFile.
And my form contains an array of this bean.

When I submit the form, the action gets an array of my bean, but the FormFile attribute is null.

If I create a FormFile field directly in the form and submit it, it works as expected, giving me the uploaded file information.

Is it not possible in struts to upload a variable number of files?

I'm sure it's possible, but I have a feeling it'd be easier to just declare five FormFile fields and deal with that.

update: 2006-05-22:
I made two now obvious mistakes:

1) Need to set indexed="true" for the fields generated inside my iterate loop. This way, instead of generating (in my case) five < input name="uploadFile" type="file"> fields, I can generate
< input name="images[0].uploadFile" type="file">
< input name="images[1].uploadFile" type="file">
< input name="images[2].uploadFile" type="file">
< input name="images[3].uploadFile" type="file">
< input name="images[4].uploadFile" type="file">
where each field has a distinct name (except that there is no space between "<" and "input" normally; I added it so you could see my code).

2) My second mistake was setting the id attribute in the iterate tag to a string different from the name of my file array. My file array is called images, and I set the iterate id to "imageArray." This would generate five fields called imageArray[0].uploadFile, imageArray[1].uploadFile, etc. Since imageArray doesn't exist in my form bean, upon submission of the form the file data gets lost since there is no parameter to save imageArray data to.

Both of these mistakes are really obvious to me now, but I shouldn't have made them at all considering that I encountered the same issues half a year ago. Bleh.

update 2006-06-26: I did have to do a little fiddling to get the validation errors displayed properly. The html:errors tag sadly does not support iteration directly, so you have to use jsp expressions to get the index appropriately.

Labels: , ,

Wednesday, December 07, 2005

J2EE multibyte character processing

I just ran across an interesting article on Multibyte-character processing in J2EE. It looks like a good introduction to the issue.

Here's an IBM article on J2EE settings for Websphere. It also offers some suggestions for Struts settings.

A Java i18n Checklist

Overview of I18n and internationalization with Java.

Labels: ,

Tuesday, October 11, 2005

Eclipse JSP and XML editors

The Eclipse Web Tools Project (for the Eclipse Integrated Development Environment) has useful tools for Web application development. I specifically installed it for the JSP editor and XML editor. There are a bunch of other tools included in it, of course. The simplest way to install the Web Tools Project is to follow these instructions in your existing Eclipse installation. I have Eclipse 3.1 installed and updating took a while but worked smoothly.

Labels: , ,