• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does the following output mean for String?  RSS feed

 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code I used is:

The output is:
Fields =
public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER

The only field in the String class is a Comparator object that holds String objects?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergiu Dobozi wrote:
The output is:
Fields =
public static final java.util.Comparator java.lang.String.CASE_INSENSITIVE_ORDER

The only field in the String class is a Comparator object that holds String objects?


Taking a quick look at the source code for the String class ... wait a sec ...

Yup, that is the only non-private field for the String class. So, the output is correct.

Henry
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is documented in the Java API documentation for String.CASE_INSENSITIVE_ORDER

Also, this object does *not* "hold String objects". Rather, it has a compare(String, String) method so it's more correct to say that it "takes two String objects as arguments to its compare() method."
 
Sergiu Dobozi
Ranch Hand
Posts: 107
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:

Taking a quick look at the source code for the String class ... wait a sec ...

Yup, that is the only non-private field for the String class. So, the output is correct.

Henry

I just now found out that you can view the source code for all classes. Does that mean that you everything is transparent? No hidden implementations and you can see every method how it was created for instance?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost the whole JDK is open source, so yes, if you want, you can see the source code for everything.

The Java source code for the standard Java classes is in the file src.zip in your JDK installation directory. Some methods are, however, implemented in native code (not in Java, but in C or C++). The source for those methods is not in src.zip, but it's still available. You can download the full source code, including the source code of the Java compiler and the JVM from the OpenJDK website. It is, however, a very large and very complicated project that has more than 20 years of work by very smart engineers in it, so don't expect it to be easy to understand.

Oracle' JDK is basically OpenJDK but with a few parts replaced by proprietary software, such as the font rendering engine.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!