How can update my class instance at runtime?

What would happen if at runtime I update a class file?
Will the JVM know to use that instead?
How can I use the updated class at runtime?
Who can give me an example?
thanks all!

yes,I write it like these:
//MyClassLoader.java
import java.io.*;
public class MyClassLoader extends ClassLoader
     public Class loadClass(String name,boolean resolve)
          throws ClassNotFoundException{
          //return super.loadClass(name,resolve);
          Class c=findClass(name);
          resolveClass(c);
          return c;
     public Class loadClass(String name)
          throws ClassNotFoundException{
          return loadClass(name,true);
public Class findClass(String name) {
byte[] b = loadClassData(name+".class");
//return defineClass(name, b, 0, b.length);
          Class c=null;
          System.out.println("load--class--data--success!");
          c=defineClass(name,b,0,b.length);
          System.out.println("define class success!");
          return c;
private byte[] loadClassData(String name) {
// load the class data from the connection
     byte[] b=null;
     try{
          //DataInputStream in =
//new DataInputStream(
          BufferedInputStream in=
new BufferedInputStream(
new FileInputStream(name));
          int len=in.available();
          b=new byte[len];
          in.read(b,0,len);
          System.out.println("load "+name+" is success!\n"+name+"'s length is"+len);
     }catch(Exception e){System.out.println("load--"+name+"--data error:"+e);}
     return b;
//Client.java
import java.io.*;
public class Client
     public static void main(String[] args)
     try{
          System.out.println("����������Load��������������");
          DataInputStream input=new DataInputStream(System.in);//��������������Load��������������
          MyClassLoader loader=new MyClassLoader();
          Load load=(Load)loader.loadClass(input.readLine()).newInstance();
          while(true){
               load.print(); //print a sentence here! I will modify it when Client is runing!
               input=new DataInputStream(System.in);
               String inStr=input.readLine();
               if(inStr!=null && inStr.trim()!=null)
                    load = (Load)loader.loadClass(inStr).newInstance();
     }catch(Exception e){System.out.println("main error:"+e);}
I skip the Load interface and it's sub class,it's easy.
MyClassLoader can load my class from the disk!
why?

Similar Messages

  • How can I consume a c# windows runtime component in a WRL (C++) class?

    I would like to instantiate a class of a C# windows runtime project, from a WRL project.
    In order to make the C# class I have created a WRL project to generate an interface for it to implement. This has worked, but I would rather do it all in the one C# project. I don't know how to do this, and I also don't know how to finally consume the C#
    project (and the resulting .winmd file) from a Wrl project. 

    You're right; I'll post back here.
    Edit: I asked over here:
    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/53a77d09-01b1-4039-8ad3-207b47b08775/how-can-i-consume-a-c-windows-runtime-component-in-a-wrl-c-class?forum=winappswithnativecode#53a77d09-01b1-4039-8ad3-207b47b08775

  • How can I have an instance of mx.controls.List in a SWF from Flash?

    How can I have an instance of mx.controls.List component in a Flash, and import its SWF into a Flex application so it can controll it?  Is it possible to do this either at author-time or runtime?
    I see plenty of examples of how you can import a SWC into Flex, but how can I have my Flash interface, with Flex components already in place to be consumed by Flex?
    Thanks

    Hallo, here is more code for my problem:
    class Login {
       Devisen dev=new Devisen();
    class Devisen {
       JTextField field2;
       if (!Check.check_field2()) return; // if value not okay than return
    class Check {
       public static void check_field2()
         HOW TO GET THE CONTENT OF field2 HERE ?
    One solution ist to give the instance to the static function, with the keyword "this"
    if (!Check.check_field2(this)) return;and get the instance
    public static void check_field2(Devisen dev)BUT is that a problem for memory to give every method an instance of the class ? I have 50 fields to control and I dont want do give every check_method an instance of Devisen, if this is a problem for performance.
    Or do I only give the place where the existing instance is.
    Hmm...?
    Thank you Wolfgang

  • How can I get an instance of my customize cell in tableview?

    Hi,I'd like to generate a customize tablecell in my tableview.but How can I get an instance of my customize cell in tableview when selected item changes?
    public class Person {
              private javafx.beans.property.BooleanProperty active;
              private StringProperty firstName;
              private StringProperty lastName;
              private StringProperty email;
              private Person(String fName, String lName, String email) {
                   this.active = new SimpleBooleanProperty(true);
                   this.firstName = new SimpleStringProperty(fName);
                   this.lastName = new SimpleStringProperty(lName);
                   this.email = new SimpleStringProperty(email);
              public javafx.beans.property.BooleanProperty activeProperty() { return active; }
              public StringProperty firstNameProperty() { return firstName; }
              public StringProperty lastNameProperty() { return lastName; }
              public StringProperty emailProperty() { return email; }
    final ObservableList<Person> data = FXCollections.observableArrayList(
                             new Person("Jacob", "Smith", "[email protected]"),
                             new Person("Isabella", "Johnson", "[email protected]"),
                             new Person("Ethan", "Williams", "[email protected]"),
                             new Person("Emma", "Jones", "[email protected]"),
                             new Person("Michael", "Brown", "[email protected]")
    public class RatingCell extends TableCell<Person,String> {
        private NabiSyncRating rating;//NabiSyncRating is a customize control.it has some method ,like change backgroud-color,value,etc.
        public RatingCell() {
             rating = new NabiSyncRating(-1);
        @Override
        public void startEdit() {
            super.startEdit();
            if (isEmpty()) {
                return;
            rating.setDisable(false);
            rating.requestFocus();
        @Override
        public void cancelEdit() {
            super.cancelEdit();
            rating.setDisable(true);
        public void commitEdit(String value) {
            super.commitEdit(value);
            rating.setDisable(true);
        @Override
        public void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
    Callback<TableColumn<Person, String>, TableCell<Person, String>> ratingCellFactory = new Callback<TableColumn<Person, String>, TableCell<Person, String>>() {
                        @Override
                        public TableCell<Person, String> call(
                                  TableColumn<Person, String> p) {
                             return new RatingCell();
    TableColumn firstNameCol = new TableColumn();
    firstNameCol.setCellFactory(ratingCellFactory);
    firstNameCol.setMinWidth(100);
    firstNameCol.setMaxWidth(224);
    firstNameCol.setResizable(true);
    tableView.getColumns().addAll(firstNameCol);
    tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
                  @Override
                  public void changed(ObservableValue observable, Object oldvalue, Object newValue)
                               Person person=(Person)newValue;
                               //I'd like to get the instance of my customize control 'RatingCell' ,How can I get the RatingCell instance which in current row?
                         System.out.println("selected row is : " + newValue );
                  });

    HI,
    I have found a solution to find it
    First ,you need to set person property 'id' as the input parameter for your customized component method 'public void updateItem(String item, boolean empty)'
    ratingCol.setCellValueFactory(new PropertyValueFactory<Person,String>("id"));
    firstNameCol.setCellFactory(ratingCellFactory);and then you need to implement your customize component like this:
    import javafx.scene.control.ContentDisplay;
    import javafx.scene.control.TableCell;
    public class RatingCell extends TableCell<Person,String> {
        private NabiSyncRating rating;
        public RatingCell() {
             rating = new NabiSyncRating(5);
            this.setGraphic(rating);
            this.setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            this.setEditable(true);
        public void updateRating()
             if(rating!=null)
                  rating.selectRating();
        @Override
        public void startEdit() {
            super.startEdit();
            if (isEmpty()) {
                return;
            rating.setDisable(false);
            rating.requestFocus();
        @Override
        public void cancelEdit() {
            super.cancelEdit();
            rating.setDisable(true);
        public void commitEdit(String value) {
            super.commitEdit(value);
            rating.setDisable(true);
        @Override
        public void updateItem(String item, boolean empty) {
             if(item!=null && item.length()>0)
                  if(rating!=null)
                       rating.setId("NR"+item);
                       this.setId("NC"+item);
                super.updateItem(item, empty);
    } and find the current like this :
    tableView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {
                       @Override
                       public void changed(ObservableValue observable, Object oldvalue, Object newValue)
                            Person person=(Person)newValue;
                            Set<Node> colNodes=tableView.lookupAll("RatingCell");
                            for(Node nod:colNodes)
                                 System.out.println("person.email:"+"NC"+person.email.getValue()+"|nodId: " + nod.getId()+"\r\n" );
                                 if(("NC"+person.email.getValue()).equals(nod.getId()))
                                       System.out.println("get current instance" );
                                      ((RatingCell)nod).updateRating();
                       });Edited by: noob on Apr 20, 2012 4:49 PM

  • How to update cgicmd.dat file during runtime?

    I'd like to know how do update cgicmd.dat file during runtime. For example, I run a report one.jsp as
    http://<machine>:<port>/reports/rwservlet?one.jsp&USERID=uid/pwd@db&DESTYPE=cache&mode=bitmap&desformat=htmlcss
    within this report there is a hyperlink to open another report named two.jsp.
    before creating this hyperlink, I'd like to update cgicmd.dat file with passed in userID, pwd, and connection, so two.jsp can use this key for userinfo
    so I can create hyperlink as follows
    srw.set_hyperlink('/reports/rwservlet?report=two.jsp'||
    '&cmdkey=userinfo&DESTYPE=cache&mode=bitmap&desformat=htmlcss');
    Thanks

    To my knowledge the cgicmd.dat is only read when the OC4J starts, so you would have to come up with another solution. Using Single-Sign-On (SSO) is quite a good idea, and it's there for cases like this.
    Regards,
    Martin Malmstrom

  • HT4623 How can update my iPhone to the last ios5. I dont want ios 6 as I want to keep google maps

    How can update my iPhone to the last ios5. I dont want ios 6 as I want to keep google maps?

    I disagree, Mr. WJ:
    If Matt had updated his iPhone via the Cloud and not by USB cable to his computer, the old IOS would still be on the computer and he would be able to "restore" to it. It would depend on what his backup settings were configured.
    For instance, I always backup to my computer at home. But, in the last few days I was notified that IOS 6.1 came out. So, if I wanted, I could install the update via WIFI from where I am at work. But, my old IOS would still be safe on my home computer that I can restore from if need be.
    And then you basically repeated what I stated about Google Maps being a app you can download now.
    Who loves ya, baby?

  • How can i learn class methodology

    i'm a programmer for 2 years. i know vb 6.0, php 4. but in these languages i never make a program with using class. because i dont know how can i make a class.
    now i started to learn java. but i can't understand how can i write class in my programs. or how can i extend classes...
    what will i do to learn class. what you offer...?
    thanks for your response.
    [email protected]

    Nothing is better for the learning process than farting about /being experimental /trial and erroring in Notepad and javac, eg;-class A{
       protected A(){
         System.out.print("Hello ");
    public class B extends A{
       public static void maain(String []params){
         doesThisWork();
       private B(){
         System.out.print("world");    
       public static void doesThisWork(){
          B b = new B();  // what gets printed to screen?
          A a = new A();  // what gets printed to screen?
          a = b;  // do these compile or create a runtime error?
          b = a;
          a = (a)b;
          b = (b)a;

  • How to reference the class-instance, created in parent class.

    Hi, I have following scenario. During compilation I am gettting error message -- "cannot resolve symbol - symbol : Variable myZ"
    CODE :
    under package A.1;
         ClassZ
         Servlet1
              ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();
    How to reference the class-instance created in the parent class?

    some corrections ...
    under package A.1;
         ClassZ
         Servlet1
              init()
                   ClassZ myZ = new ClassZ;
    under package A.2;
         Servlet2 extends Servlet1
              myZ.printHi();

  • How can i set class path in ubuntu JAVA_HOME ?

    how can i set class path in ubuntu <JAVA_HOME>?

    Note that on *nix
    environment variable names are case sensitive.
    Also, you are again being vague; is it [this it|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/javac.html] or [that it|http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/java.html]

  • HT4972 IOS:How can update my iphone 3 to IOS 5

    IOS:How can update my iphone 3 to IOS 5

    Latest version for iPhone 3G is iOS 4.2.1. If you mean iPhone 3GS, connect to iTunes to update to iOS 6. If you're not sure which one you have, go to Settings > General > About > Serial Number, and enter it at http://selfsolve.apple.com/agreementWarrantyDynamic.do

  • How can update my old iphone version 4.3.3 (8j2) to ios 5

    how can update my old iphone version 4.3.3 (8j2) to ios 5

    No further iOS updates are available for an iPhone 3G.
    (78113)

  • How can update camera raw 8.6 ?

    Lightroom 5.6 needs Camera Raw 5.6 for a full compability.
    How can update camera raw 8.6?
    Thanks!

    Hi Mierteran,
    Please follow the link: Adobe - Adobe Camera Raw and DNG Converter : For Windows : Adobe DNG Converter 8.6 to download Update Camera Raw 8.6.
    Let me know if its works or not.
    Thanks,
    Ratandeep Arora

  • How can i remove paramter form at runtime of report through PSP

    I am working on PSP (PL/SQL Server pages) with html code. I made some reports through report builder (rdf files). I pass variables into report parameter through PSP and I call the reports through this code
    OWA_UTIL.redirect_url (
    p_report_url
    || '?runp=&report=WEB_BOOK_LOCATION.rdf&destype=cache&desformat=htmlcss&server=rep60_kmas&userid='
    || p_usrcon||'&p_inst_id='||p_inst_id
    but I dont want parameter form on runtime . I know the code which is used only in developer forms , this is
    add_parameter (pl_id, 'PARAMFORM', text_parameter, 'NO');
    How can I remove parameter form on runtime from PSP.
    Thanks and regards
    --Anwar

    Would adding &paramform=NO to the call solve the problem?
    I am working on PSP (PL/SQL Server pages) with html code. I made some reports through report builder (rdf files). I pass variables into report parameter through PSP and I call the reports through this code
    OWA_UTIL.redirect_url (
    p_report_url
    || '?runp=&report=WEB_BOOK_LOCATION.rdf&destype=cache&desformat=htmlcss&server=rep60_kmas&userid='
    || p_usrcon||'&p_inst_id='||p_inst_id
    but I dont want parameter form on runtime . I know the code which is used only in developer forms , this is
    add_parameter (pl_id, 'PARAMFORM', text_parameter, 'NO');
    How can I remove parameter form on runtime from PSP.
    Thanks and regards
    --Anwar                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             

  • Hi...!!! how can update my ios??? on my iphone??? help please :D

    hi...!!! how can update my ios??? on my iphone??? help please

    Open itunes, connect iphone.  That is it.  It will prompt you to updqate.
    Maybe if you were to provide some info, more help could be given.
    Which iphone?
    What itunes version do you have?
    What ips version do you have?
    What have you tried?
    What happened?

  • How can update two rows in one query?

    How can update two rows in one query?
    Edited by: OracleM on May 4, 2009 12:16 AM

    What do you mean with "two rows"? May be two columns??
    If the where clause of UPDATE query matches two rows, then it will update two rows. If you want to update two columns, then add column names to your query
    UPDATE your_table SET col1=value1, col2=value2 WHERE your_where_clause- - - - - - - - - - - - - - - - - - - - -
    Kamran Agayev A. (10g OCP)
    http://kamranagayev.wordpress.com
    [Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/]

Maybe you are looking for