What do you think about the "char" primitive in J2SDK 1.5

I think char's should not be 16-bit at the beginning (JDK 1.0). Then, there is no need to worry about things like "surrogate pairs" (Please see http://java.sun.com/developer/technicalArticles/Intl/Supplementary/ for more information).

In my opinion, char's should be stated as the following:

- One "char" contains exactly one Unicode character, no matter how big or small it is.

- "char" is not an integer type. So, "char" cannot be compared with integers (like boolean's).

- "char" can be compared to "char" by their Unicode value.

- String length is measured in number of chars (Unicode characters).

I am sure this will make the SDK implementors headache, because char's become variable length in bytes. But this will rescue all developers who use languages other than English (especially Asian languages). By this definition, no matter how unicode.org adds new characters / changes the definition, char's still represent one Unicode character.

Of course, there are still problems in this design. Please tell me what you think about this.

Thank you.

Asuka Kenji

[1143 byte] By [kennethz] at [2007-9-30 11:05:10]
# 1

Something more to say:

It will be even better if the internal (JVM) encoding uses UTF-8. Then, ASCII can be stored with one byte. Of course this may make the Strings much slower because more processing is needed. But, Java Strings are supposed to be slow, isn't it? Or, at least, not designed to be very fast. Java Strings are immutable and every operation creates a new String!

But I don't know why BigDecimal and BigInteger are also immutable ... sign ...

kennethz at 2007-7-3 22:40:09 > top of Java-index,Other Topics,Java Community Process (JCP) Program...
# 2

Because if they were mutable someone else could change a BigDecimal's value while you were using it.

class Stereo implements Product {

BigDecimal price = new BigDecimal(400);

BigDecimal getPrice() { return price; }

}

class Purchase {

List<Product> trolley;

BigDecimal total;

void add(Product p) {

if(trolley == null) trolley = new ...;

trolley.add(p);

if(total == null) {

total = p.getPrice();

} else {

total.add(p.getPrice());

}

}

}

class example {

public static void main .... {

Purchase p= new Purchase();

Stereo s = ...

p.add(s);

p.add(s);

System.out.println(s.getPrice()); // 800 !!

}

}

brucechapman at 2007-7-3 22:40:09 > top of Java-index,Other Topics,Java Community Process (JCP) Program...
# 3
Thanks.I knew this last week after reading the book "Concurrent Programming in Java, Second Edition"."Immutability" is a kind of "exclusion" to deal with thread safety.
kennethz at 2007-7-3 22:40:09 > top of Java-index,Other Topics,Java Community Process (JCP) Program...