• Post Reply Bookmark Topic Watch Topic
  • New Topic

Doubt on WordUtils Class  RSS feed

 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.String extends java.lang.Object and to make use of the String functions we import the 'java.lang.String' class. This works fine.
But,
org.apache.commons.lang.WordUtils extends java.lang.Object and to make use of the WordUtils functions, when I import 'org.apache.commons.lang.WordUtils ' class. This does not work.

What wrong am i doing here?
 
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
akshitha Akki wrote:java.lang.String extends java.lang.Object and to make use of the String functions we import the 'java.lang.String' class. This works fine.

You don't need to import the java.lang.String class. Everything in the java.lang package is always automatically imported; you don't need to import classes from java.lang explicitly.

akshitha Akki wrote:But, org.apache.commons.lang.WordUtils extends java.lang.Object and to make use of the WordUtils functions, when I import 'org.apache.commons.lang.WordUtils ' class. This does not work.

What does "this does not work" mean? Do you get an error? If so, then what exactly is the error?

You need to make sure that you have the right JAR file(s) in your classpath, in this case you need to make sure that the JAR file for Apache Commons Lang is in your classpath when you compile and run your code.
 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper, I added the jar file and it worked fine.

While adding the jar file, I had a look at the package contents 'http://commons.apache.org/lang/api-2.4/org/apache/commons/lang/package-summary.html'. This jar file has many classes with various utility functions. So to make use of these functions the corresponding jar file has to be downloaded and added to the classpath, so that the program control goes to this path to get the function definition on execution time. Correct me if I am wrong.

http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/package-summary.html
This link shows all the available packages in this version of java.So when a user installs java, all these as a part of the package gets stored in the system.As the user provides the class path to jdk, whenever call to a function is made , the control goes to the bin folder of jdk and pick the corresponding fuction from there and executes. Correct me if I am wrong.

Thanks,
 
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
Correct.

But the link for the Java API documentation refers to the API of Java 1.4, which has been out of date for a long time. Java 7 is the current version, here is the API documentation.

akshitha Akki wrote:As the user provides the class path to jdk, ...

You don't have to put the classes of the standard API in the classpah; they are always automatically available.
 
akshitha Akki
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!