• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Modifying Core JAVA Classes

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
2 questions
1. Is it possible to modify a Core JAVA class and put it back in rt.jar?
2.Is it possible to create a non-Core class and place it in one of the core packages (i.e. java.util)
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure... but this is the path towards damnation. Bad karma is sure to follow.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sure you can. But instead of physically changing rt.jar, there's an easier way. Simply prepend your class files to the boot classpath:
java -Xbootclasspath/p:your_file_location
Your class files will be picked up ahead of rt.jar by the bootstrap classloader.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Steve Corn:
2 questions
1. Is it possible to modify a Core JAVA class and put it back in rt.jar?
2.Is it possible to create a non-Core class and place it in one of the core packages (i.e. java.util)


Why would you want to do that?
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your choice of action may depend if you are writing code for a one-time personal project, long-term many-user project, commercial product, etc.
I'm guessing you want to do this to fix some of Sun's bugs or change their behavior.
The typical choice would be to override the methods you want to change. Often you can't do that conventionally because of private declarations. Another option might be to copy the core class's source to your own file, change the class's name, and customize the code. This is useful if you can control what instances are used in your program. (E.g. if you fix something in JTextField, you can always choose to use MyTextField, but if you change something in Thread, you can't control the use of that everywhere.)
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually it may be a bit stickier than that. When a JAR is signed for security, the Java VM is going to take certain pains to ensure that some evil person doesn't override a critical class and either blow a hole in the Java security system or make an innocent application do something bad.
 
reply
    Bookmark Topic Watch Topic
  • New Topic