• Post Reply Bookmark Topic Watch Topic
  • New Topic

Corejava package download  RSS feed

 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to use C like formating (%d, %f etc) in my Java program. I understand I can use the Format() method that is available in corejava package. Can anyone tell me from where I can download corejava package?
Thanks
Kelly
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, welcome to the Ranch!
Have you downloaded the SDK? If not, you can find it at http://java.sun.com/j2se/downloads.html
There is a tools.jar package in the lib directory, that's the important one. You'll want to put it in your CLASSPATH if you're using Windows. However, if you're using a build tool or IDE, you don't have to worry about messing with the environment variables.
Within that jar file is all the standard Java packages that you'll need.
You can find a complete list of these classes and their uses (the API) at http://java.sun.com/api/index.html.
 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason
I had downloaded "Sun(TM) ONE Studio 4 update 1, Community Edition - J2SE(TM) 1.4.1_02 Cobundle". It comes with the IDE and J2SE. I am programming using the IDE.
But when I wrote a "import corejava.*" in my program, the compiler could not identify the package. It gave an error. Should I make some changes in the classpath, so that the compiler could identify the corejava package? Please do advise..
Thanks
Kelly
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you're thinking of the Format class developed by Cay Horstmann for his Core Java book. See the link to Format at the end of the page. This class is moderately useful for people coming from C who really want something similar to printf, but in the long run you're better off learning how to use the standard Java libraries to do this sort of thing. In particular classes like DecimalFormat and DateFormat (esp SimpleDateFormat) will be what you need. And maybe a simple method to add spaces (or zeroes) to the left hand side of a field, to make it fit a particular width:

This sort of thing is only useful if your output will be viewed in a fixed-width font. Often that's not the case. E.g for a GUI you're better off using things like JTextField and setting the alignment appropriately. Lots of ways to format things, depending on where you want the output to go, and what it should look like.
 
Kelly KMoni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jim
Thanks for your quick response. You are correct, that I am looking for Cay Horstmann's corejava package, without realising that it is not a Standard Java package. I am using Cay Horstmann’s book for reference, that’s the way I came across the corejava package.
Also, I am a C/C++ programmer, who is trying to learn Java by myself. As I learn, I am also working on a project in which I am converting a C program into Java. For debugging purposes, I thought this C like formatting is neat. I will learn about the DateFormat, SimpleDateFormat and DecimalFormat classes and try to use them instead.
I really appreciate your comments and the sample code, as it helps me to learn Java!
Thanks
Kelly
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!