0

JRE contains the .class files for library classes.

When these .class files in JRE folder will be used?

Does JRE contains the .class files for all library classes.

Let us take an example..

when we are importing the library files, we are using the definition of the class file from the src.zip and not the .class file. E.g. import java.net.InetAddress. that is just we are inheriting the library class.Therefore the code of the library class too complies along with our code na..

we are not using the .class file directly. so what is the use of having .class files for those library files in JRE folder?

I searched JRE folder, but I found no .class file for InetAddress

But command javap java.net.InetAddress still works well.

Someone please help.

Thanks in Advance.

Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77

2 Answers2

2

javap runs in the JRE so it has all the classes which come with the JRE in its class path. Most of the classes you will be interested in are in the rt.jar archive.

If you want to decompile your own class, you have to add its base directory to the class path

e.g.
$ ls
HelloWorld.class

$ javap -c -classpath . HelloWorld
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

Yes the JRE contains the class files.

luketorjussen
  • 3,156
  • 1
  • 21
  • 38
  • I searched JRE too , but I found no .class files. – Muthu Ganapathy Nathan Jul 13 '11 at 14:45
  • as Peter has said in his answer they will be in the rt.jar archive. – luketorjussen Jul 13 '11 at 14:52
  • When these .class files in JRE folder will be used? – Muthu Ganapathy Nathan Jul 13 '11 at 15:55
  • ie. when we are importing the library files, we are using the definition of the class file from the src.zip. (eg) import java.net.InetAddress. that is just we are inheriting the class. we are not using the .class file directly. so what is the use of having .class files for those library files in JRE folder – Muthu Ganapathy Nathan Jul 13 '11 at 16:02
  • 1
    we are using the class file directly. When 'javac' compiles your code it has the .class files from the JRE directory in its classpath and when you reference java.net.InetAddress, 'javac' will look at the class file in the JRE. When you run 'java' it will again have the .class files from the JRE in the classpath and will reference them when it runs your code. – luketorjussen Jul 13 '11 at 16:11