Small method probrem

Hi i'm rather new on Java, and i got a small problem with methods:
class Metodus1 {
  byte life;
  String status;
  void fight() {
    if (life <= 0) {
      status = "You're dead";
      System.out.println(status + "");
    else {
      status = "You keep on fighting, " + life + " hp left";
      System.out.println(status + "");
  public static void main (String[] arguments) {
    Metodus1 doIt = new Metodus1();
    doIt.life = 100;
    doIt.status = "hello";
    System.out.println("The enemy hits you with 55");
    doIt.life =-55;
    doIt.fight();
    System.out.println("The enemy hits you with 20");
    doIt.life =-20;
    doIt.fight();
    System.out.println("The enemy hits you with 5");
    doIt.life =-5;
    doIt.fight();
    System.out.println("The enemy hits you with 15");
    doIt.life =-15;
    doIt.fight();
    System.out.println("The enemy hits you with 10");
    doIt.fight();
}The output is:
The enemy hits you with 55
You're dead
The enemy hits you with 20
You're dead
The enemy hits you with 5
You're dead
The enemy hits you with 15
You're dead
The enemy hits you with 10
You're dead
When it SHOULD be:
The enemy hits you with 55
You keep en fighting, 45 hp left
The enemy hits you with 20
You keep en fighting, 25 hp left
The enemy hits you with 5
You keep en fighting, 20 hp left
The enemy hits you with 15
You keep en fighting, 5 hp left
The enemy hits you with 10
You're dead.
I don't understand what's wrong

You have a lot of lines like this:
     doIt.life =-55;This sets doIt.life to negative 55. It's the same as this:
     doIt.life = -55;You probably meant to do this:
     doIt.life -= 55;which decrements doIt.life by 55.

Similar Messages

  • Cannot understand small method

    I have being looking at this method and while I undertand what the overall job of the method is I cannot understand what some of the lines do.
    Here it is:
    private static void helloifyClassName(JavaClass java_class )
            class_name = java_class.getClassName() + "_hello";          //Adds _hello to the class name
            int index = java_class.getClassNameIndex();
            index = ((ConstantClass)cp.getConstant(index)).getNameIndex();
            cp.setConstant(index, new ConstantUtf8(class_name.replace('.', '/')));
        }I have not been able to find a description of getClassNameIndex() in documentation, what is a class name index?
    He then changes the value of index on the next line so is there any point in having the getClassNameIndex() line?

    I have not been able to find a description of
    getClassNameIndex() in documentation, what is a class
    name index?You'll need to check with the author of the JavaClass class, or consult the documentation.
    He then changes the value of index on the next line
    so is there any point in having the
    getClassNameIndex() line?Perhaps he's saving up that valuable variable allocation space... :o)

  • Please help with small method error

    This is straight from:
    http://java.sun.com/developer/onlineTraining/new2java/divelog/part1/page7.jsp
    Keeps saying ")" is expected....i can't figure it out...usually can figure this error out quick...not this time....
    This does not work, and copy/pasting the code from the site does not work
    private void buildMenu()
                JMenuBar jmb = new JMenuBar();
                JMenu menu = new JMenu("File"/**, yes*/);
                JMenuItem item = new JMenuItem("Exit");
                     item.addActionListener(new ActionListener()
                        public void actionPerformed(Action Event ae)
                            System.exit(0);
            }// I added this one hoping it'd fix it.......nope.
    This works all by itself....
       private void buildMenu()
                JMenuBar jmb = new JMenuBar();
                JMenu menu = new JMenu("File"/**, yes*/);
                JMenuItem item = new JMenuItem("Exit");
    The hypothesis is that this is the problem area:
       item.addActionListener(new ActionListener()
                        public void actionPerformed(Action Event ae)
                            System.exit(0);
                    }); Thank you!

    ahhhhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Thank you, lol!!
    spending so much time looking at curly braces didn't go through the rest of the code.....i'm going to go bang my head against the wall.
    omfg...

  • Problem - JHS generating methods too large

    Migration From 10.1.2 to 10.1.3.1.26 (licensed)
    Thanks for the previous fix. Now I have another problem. I get the following error:
    Error(19,15): code segment of method _jspService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) too large
    When ViewController compiles.
    This is a 10.1.2 application that I've migrated to 10.1.3.1.26. I had no problems with 10.1.2. How can method_jspService be too big?
    The jspx file is a screen that has 8 sub-tabs. I haven't changed anything.
    This screen is the heart of our application, any help on this problem would be appreciated.
    Thanks!
    Message was edited by:
    user565025

    I'm a colleague of the orignal poster above. I've been looking at this issue further and will summarize it here:
    relevant threads:
    Error with large / complex pages
    Error: code segment of method _jspService(..) too large
    Re: jspx Page size limit in ADF in JDeveloper environment 10.1.3.1 (Product
    As far as I can tell the root cause is as described here:
    http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.support.was.doc/html/Java_SDK/1177375.html
    "The Java� specification states that there is a 64 K limit on the size of methods in Java. The JVM� does not execute methods that exceed this limit.
    It is possible to compile methods larger than 64 K, but the JVM will not run these methods. Consequently, the error occurs during runtime, while attempting to execute Java methods that are greater than 64 K.
    A code too large for try statement error can still be issued while compiling a JSP. The compiler limitation does not allow try/catch blocks to have a start or end location greater than 64 K into the method code. Therefore, compiler limitations are usually caught when a try/catch block overlaps the 64 K boundary.
    The workaround is to refactor the code into smaller methods or try/catch blocks."
    So it looks like Jheadstart is generating a file (see below) which violates the java spec. If I am correct then this is neither an oc4j, Sun or Jdeveloper problem; it's JHeadStart. I have tried setting the embedded server compiler and all project compilers to javac.
    Any further suggestions or workarounds would be greatly appreciated.
    Removed file listing - too long
    Message was edited by:
    JavaBat

  • Code of method longer than 65535 bytes.

    What can I do if I get this error message?
    I am using JDK 1.3 and Tomcat32.
    Thanks,
    Nicoleta Iacob

    According to http://java.sun.com/docs/books/vmspec/html/ClassFile.doc.html, "The amount of code per method is limited to 65535 bytes...". You may try to use smaller methods.

  • Max number of lines in method.

    Hi,
    Syntatically a method can span for any number of lines, but is there
    a limit on number of lines in a method so that it conforms to java code
    conventions. Could not find anything about the number of lines in Sun java code conventions doc.
    Thanks
    Deepak

    The whole point is write a method that does only one thing. The hard thing is to determine what one thing is. A method which only
    does one thing can also become long, and needs to be broken down
    to several small methods. A method name is a very good documentation
    (unless you use random method names)I also use one of my few rules of thumb here:
    rule#5059723586: if you can't describe in one sentence, using
    appropriate detail, what a method does, it needs to be refactored to
    at least two methods. repeat rule#5059723586 as long as applicable.
    rule#5059723586B: The verbs and nouns of the 'appropriate detail'
    mentioned in rule#5059723586 must refer to members, parameters
    or other methods (see also rule# 5059723586)
    kind regards,
    Jos ;-)

  • Can you detect a method that will be 65535 bytes?

    There's a well-known problem with the JVM that a method cannot be greater than 65535 bytes. Obviously, most developers know better than to write such a large method by hand. However, as automatic source code generators become more popular, this method size limit is becoming a major headache.
    http://forum.java.sun.com/thread.jspa?forumID=37&threadID=171744
    http://forum.java.sun.com/thread.jspa?forumID=52&threadID=94978
    http://forum.java.sun.com/thread.jspa?threadID=483376&start=0&tstart=0
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=510932
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4309152
    Apparently the only workaround to this problem is to split such a large method into multiple smaller methods that don't exceed the size limit. Well, that sounds great, but how do you actually do this?
    For example, in an automatic source code generator, is it possible to detect if generated code would exceed this 65535 limit? Maybe it's impossible to tell ahead-of-time how big the Java compiler will make a method. If one could easily tell that a method would exceed the size limit, it would be easier to write a code generator.
    Any thoughts?

    Thank you, jschell, for your wonderully helpful
    posts. Your positive attitude is just what these
    forums need.
    As I said before, this generator is generating
    scientific code, the code has to be this long to
    solve the given problem. And since the JVM spec
    places a constraint on method length (and we all have
    our opinions about this, but while our opinions are
    interesting, they are irrelevant) I need to find a
    way to split the big method into multiple smaller
    ones. Many others have voiced the same frustration
    with this (do a search for "code length longer than
    65535 byes" in these forums).I was rather frustrated when I ran across the C code generator problem as well.
    >
    So this post is just an attempt to get ideas or see
    if someone else has faced this problem before. Your
    condescending posts are not only offensive, but they
    do absolutely nothing to help solve the problem.Your posts seemed to suggest, rather specifically, that you thought this was a problem with the JVM (and the spec.)
    I was pointing out that that is not the case.
    You also seemed to be asking for something that would only be useful to a code generator. And I also pointed out that someone who is writing a code generator, rather than just using one, can fix this problem by simply not allowing that to occur in the first place. Which is how I write my code generators.
    So are your writing a code generator? Then change it so it doesn't have this problem.
    Are you using a code generator? If so write a 'breaker'. It takes the output from the code generator and restructures the code into smaller pieces. By the way that is exactly what I did with the C problem that I mentioned.
    And those are the solutions.
    Please refrain from posting here again unless you
    u have something constructive to say. Thank you.If you wish to pay me money (negotiable of course) then I am more than willing to say anything you wish or not say anything as the case may be.
    Or you can post your problem to your own web site where you can have complete control over the content of all the answers.
    Other than that you are out of luck.

  • Use of private methods

    Can someone tell me when a java program would use private methods? I understand that use of private instance variables is the norm and when extending a class, the use of the public methods is required to access the data. But when would it be necessary to use a private method? Thanks.

    Okay, so you create a class. And some other class uses that class.
    public class Useful {
      public void doSomethingUseful() {
    public class User {
      // Use a Useful to do something useful
      Useful u = new Useful();
      u.doSomethingUseful();
    }Now, you could put a whole bunch of krap into the single doSomethingUseful method, or you could be smart and break its work down into smaller methods, which each method having it's own responsibility. Those methods would be private, because there's no reason to expose the implementation details of the public method.

  • Multiple return values (Bug-ID 4222792)

    I had exactly the same request for the same 3 reasons: strong type safety and code correctness verification at compile-time, code readability and ease of mantenance, performance.
    Here is what Sun replied to me:
    Autoboxing and varargs are provided as part of
    JSRs 14 and 201
    http://jcp.org/en/jsr/detail?id=14
    http://jcp.org/en/jsr/detail?id=201
    See also:
    http://forum.java.sun.com/forum.jsp?forum=316
    http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html
    Multiple return values is covered by Bug-ID 4222792
    Typically this is done by returning an array.
    http://developer.java.sun.com/developer/bugParade/bugs/4222792.html
    That's exactly the problem: we dynamically create instances of array objects that would better fit well within the operand stack without stressing the garbage collector with temporary Array object instances (and with their backing store: 2 separate allocations that need to be recycled when it is clearly a pollution that the operand stack would clean up more efficiently)
    If you would like to engage in a discussion with the Java Language developers, the Generics forum would be a better place:
    http://forum.java.sun.com/forum.jsp?forum=316
    I know that (my report was already refering to the JSR for language extension) Generics is not what I was refering to (even if a generic could handle multiple return values, it would still be an allocated Object
    instance to pack them, i.e. just less convenient than using a static class for type safety.
    The most common case of multiple return values involve values that have known static datatypes and that should be checked with strong typesafety.
    The simple case that involves returning two ints then will require at least two object instances and will not solve the garbage collection overhead.
    Using a array of variable objects is exactly similar, except that it requires two instances for the components and one instance for the generic array container. Using extra method parameters with Integer, Byte, ... boxing objects is more efficient, but for now the only practical solution (which causes the least pollution in the VM allocator and garbage collector) is to use a custom class to store the return values in a single instance.
    This is not natural, and needlessly complexifies many interfaces.
    So to avoid this pollution, some solutions are used such as packing two ints into a long and returning a long, depacking the long after return (not quite clean but still much faster at run-time for methods that need to be used with high frequencies within the application. In some case, the only way to cut down the overhead is to inline methods within the caller code, and this does not help code maintenance by splitting the implementation into small methods (something that C++ can do very easily, both because it supports native types parameters by reference, and because it also supports inline methods).
    Finally, suppose we don't want to use tricky code, difficult to maintain, then we'll have to use boxing Object types to allow passing arguments by reference. Shamely boxed native types cannot be allocated on the operand stack as local variables, so we need to instanciate these local variables before call, and we loose the capacity to track the cases where these local variables are not really initialized by an effective call to the method that will assign them. This does not help debugging, and is against the concept of a strongly typed language like Java should be:
    Java makes lots of efforts to track uninitialized variables, but has no way to determine if an already instanciated Object instance refered in a local variable has effectively received an effective assignment because only the instanciation is kept. A typical code will then need to be written like this:
    Integer a = null;
    Integer b = null;
    if (some condition) {
    //call.method(a, b, 0, 1, "dummy input arg");
    // the method is supposed to have assigned a value to a and b,
    // but can't if a and b have not been instanciated, so we perform:
    call.method(a = new Integer(), b = new Integer(), 0, 1, "dummy input
    arg");
    // we must suppose that the method has modified (not initialized!)
    the value
    // of a and b instances.
    now.use(a.value(), b.value())
    // are we sure here that a and b have received a value????
    // the code may be detected at run-time (a null exception)
    // or completely undetected (the method() above was called but it
    // forgot to assign a value to its referenced objects a and b, in which
    // case we are calling in fact: now.use(0, 0); with the default values
    // or a and b, assigned when they were instanciated)
    Very tricky... Hard to debug. It would be much simpler if we just used:
    int a;
    int b;
    if (some condition) {
    (a, b) = call.method(0, 1, "dummy input arg");
    now.use(a, b);
    The compiler would immediately detect the case where a and b are in fact not always initialized (possible use bere initialization), and the first invoked call.method() would not have to check if its arguments are not null, it would not compile if it forgets to return two values in some code path...
    There's no need to provide extra boxing objects in the source as well as at run-time, and there's no stress added to the VM allocator or garbage collector simply because return values are only allocated on the perand stack by the caller, directly instanciated within the callee which MUST (checked at compile-time) create such instances by using the return statement to instanciate them, and the caller now just needs to use directly the variables which were referenced before call (here a and b). Clean and mean. And it allows strong typechecking as well (so this is a real help for programmers.
    Note that the signature of the method() above is:
    class call {
    (int, int) method(int, int, String) { ... }
    id est:
    class "call", member name "method", member type "(IILjava.lang.string;)II"
    This last signature means that the method can only be called by returning the value into a pair of variables of type int, or using the return value as a pair of actual arguments for another method call such as:
    call.method(call.method("dummy input arg"), "other dummy input arg")
    This is strongly typed and convenient to write and debug and very efficient at run-time...

    Can anyone give me some real-world examples where
    multiple return values aren't better captured in a
    class that logically groups those values? I can of
    course give hundreds of examples for why it's better
    to capture method arguments as multiple values instead
    of as one "logical object", but whenever I've hankered
    for multiple return values, I end up rethinking my
    strategy and rewriting my code to be better Object
    Oriented.I'd personally say you're usually right. There's almost always a O-O way of avoiding the situation.
    Sometimes though, you really do just want to return "two ints" from a function. There's no logical object you can think of to put them in. So you end up polluting the namespace:
    public class MyUsefulClass {
    public TwoInts calculateSomething(int a, int b, int c) {
    public static class TwoInts {
        //now, do I use two public int fields here, making it
        //in essence a struct?
       //or do I make my two ints private & final, which
       //requires a constructor & two getters?
      //and while I'm at it, is it worth implementing
      //equals(), how about hashCode()? clone()?
      //readResolve() ?
    }The answer to most of the questions for something as simple as "TwoInts" is usually "no: its not worth implementing those methods", but I still have to think about them.
    More to the point, the TwoInts class looks so ugly polluting the top level namespace like that, MyUsefulClass.TwoInts is public, that I don't think I've ever actually created that class. I always find some way to avoid it, even if the workaround is just as ugly.
    For myself, I'd like to see some simple pass-by-value "Tuple" type. My fear is it'd be abused as a way for lazy programmers to avoid creating objects when they should have a logical type for readability & maintainability.
    Anyone who has maintained code where someone has passed in all their arguments as (mutable!) Maps, Collections and/or Arrays and "returned" values by mutating those structures knows what a nightmare it can be. Which I suppose is an argument that cuts both ways: on the one hand you can say: "why add Tuples which would be another easy thing to abuse", on the other: "why not add Tuples, given Arrays and the Collections framework already allow bad programmers to produce unmainable mush. One more feature isn't going to make a difference either way".
    Ho hum.

  • Need help for a newbie problem

    I am VERY new to all this Java programming but have really started to enjoy it.
    I have two problems with my program that I can not find answers to.
    1. I am looking to find out why my code will not select the right answers when I select the first choice in the array. The answer that is delivered turns out to be the 3rd selection. The second and third selection work great, but the first selection always turns out with the thrid answer.
    2. I know I need to do better error checking on the user input. At this point I am only checking for correct integer input, but I dont know how to fix or avoid the error for when the user would mistakedly enter letters instead of numbers.
    Any hints?
    Code to follow... I hope...
    No gui allowed for this program.
    First time posting so I hope this works and I do it the right way...
    import java.text.DecimalFormat;      //To round to 2 decimal places for payment format.
    import java.io.*;                          //Allows User to input.
    public class Wk5JimP
         //classes for keyboard inputs from user
         public static InputStreamReader reader = new InputStreamReader (System.in);
         public static BufferedReader keyboard = new BufferedReader (reader);
         //main
         public static void main (String[] args) throws IOException
              //Variables
              DecimalFormat decimal = new DecimalFormat("#,##0.00");     //Makes the decimal format for the output
              int appAmount = 200000;                                             //approved loan amount
              short rPay = 0;                                                       //repayment option
              int ps;                                                                 //payment schedule switching variable.
              //Year array and variables
              int yTerm[] = {30, 15, 7,};                                        //Term of the loan in years array
              short rOller2 = 0;                                                  //looping variable for rolling the years
              short rOller3 = 0;                                                  //looping variable for rolling the years
              //Month array and variables
              int mTerm[] = {360, 180, 84,};                                   //Term of the loan in months array
              short rOller = 0;                                                  //looping variable for rolling the months
              short rOller1 = 0;                                                  //looping variable for rolling the months
              //Interest rate array and variables
              double iRate[] = {5.75, 5.50, 5.35,};                              //interest rate array
              int liRate = 0;                                                       //looping variable for interest rate
              int liRate1 = 0;                                                  //looping variable for interest rate
              // Payment array and variables
              double mPayment[] = {
                   ((appAmount*(iRate[0]/12/100))/(1-1/Math.pow((1+iRate[0]/12/100), mTerm[0]))),
                   ((appAmount*(iRate[1]/12/100))/(1-1/Math.pow((1+iRate[1]/12/100), mTerm[1]))),
                   ((appAmount*(iRate[2]/12/100))/(1-1/Math.pow((1+iRate[2]/12/100), mTerm[2])))
                                       };                                             //monthly payment array
              int lPay = 0;                                                       //looping variable for payment incrementation
              int lPay1 = 0;                                                       //looping variable for payment incrementation
              //Dollar amounts into decimal format of two places
              String fappAmount = decimal.format(appAmount);
              //Output to screen for header information
              System.out.println();
              System.out.println("Congratulations!");
              System.out.println("You are approved for a $" + fappAmount + " loan");
              System.out.println("The three repayment options are listed below.\n");
              System.out.println("-------------------------------------------------------------------------");
              System.out.println(" Repayment\t Loan\t\t   Term\t\t  Interest\t  Monthly");
              System.out.println("  Option\tAmount\t       Years   Months\t  Rate \t          Payment");
              System.out.println("-------------------------------------------------------------------------");
              //Begin repayment option loop for calculation
              while (rOller != 3)
                        // if else loop to second and third repayment options
                      if (rOller1 <= 2)
                           // for statement loops last repayment option
                           for (rPay = 1; rPay <=3; rPay++)
                                    {mPayment[lPay] = mPayment[lPay1++];
                                     yTerm[rOller2] = yTerm[rOller3++];
                                     mTerm[rOller] = mTerm[rOller1++];
                                     iRate[liRate] = iRate[liRate1++];
                                //Output to screen for numerical repayment option info
                              System.out.println("    " + rPay + "\t    $" + fappAmount + "\t\t " + yTerm[rOller2] + "\t" + mTerm[rOller] + "\t    " + decimal.format(iRate[liRate]) + "% \t$" + decimal.format(mPayment[lPay])+ "\n\n");
                        else
                             //begin payment option selection
                             System.out.println();
                             System.out.println("Which one of the payment schedules would you like to see?\n");
                             System.out.println("Please enter 1 or 2 or 3 to see the payment schedule\nor enter any other number to exit.");
                             ps = Integer.parseInt(keyboard.readLine());
                                  switch (ps)
                                            case 1:
                                                 System.out.println("\nOption #1\n");
                                                 paysched(yTerm[0], appAmount, iRate[0], mPayment[0]);
                                                 break;
                                            case 2:
                                                 System.out.println("\nOption #2\n\n");
                                                 paysched(yTerm[1], appAmount, iRate[1], mPayment[1]);
                                                 break;
                                            case 3:
                                                 System.out.println("\nOption #3\n\n");
                                                 paysched(yTerm[2], appAmount, iRate[2], mPayment[2]);
                                                 break;
                                            default:
                                                 System.out.println("Thank you!\n\n");
                                                 System.exit(0);
                                      }//end switch
                   }//end while
              }//end main
                             //payment schedule method
                             public static void paysched(int yTerm, int appAmount, double iRate, double mPayment) throws IOException
                             //Declare variables for looped calculations
                             DecimalFormat decimal = new DecimalFormat("#,##0.00");     //Makes the decimal format for the output
                             double balance = appAmount;
                             double monIRate = iRate / 12;
                             double iPay = 0;
                             double pPay = 0;
                             short pNum = 1;
                             short year = 1;
                             //Header Output to screen for payment schedule
                             System.out.println("-------------------------------------------------------------------------");
                             System.out.println("   Payment \t   Principle\tInterest\tTotal \t\tBalance");
                             System.out.println(" Year  Month\t   Payment\tPayment \tPayment \tRemaining");
                             System.out.println("-------------------------------------------------------------------------");
                             //Loop for shceduled payment calculation for all but the final year
                             do
                                       //Apply the payment
                                       iPay = balance * (monIRate /100);
                                       pPay = mPayment - iPay;
                                       balance = balance - pPay;
                                       //Output to screen for payment information
                                       System.out.println("   " +year+ " \t " +pNum+ " \t  $" +(decimal.format(pPay))+ "\t$" +(decimal.format(iPay))+ "\t      $" +(decimal.format(mPayment))+ "\t     $" +(decimal.format(balance)));
                                       pNum++;
                                       if (pNum % 13 == 0)
                                            System.out.println("Press enter to see the next year payments.");
                                            System.in.read();
                                            System.in.read();
                                            year++;
                                            pNum = 1;
                                            //Output to screen for payment schedule
                                            System.out.println("-------------------------------------------------------------------------");
                                            System.out.println("   Payment \t   Principle\tInterest\tTotal \t\tBalance");
                                            System.out.println(" Year  Month\t   Payment\tPayment \tPayment \tRemaining");
                                            System.out.println("-------------------------------------------------------------------------");
                                            } //end if
                                    } //end do
                             while(year < yTerm);
                             //Final Year calculations
                             do
                                       //Apply the payment
                                       iPay = balance * (monIRate /100);
                                       pPay = mPayment - iPay;
                                       balance = balance - pPay;
                                       //Output to screen for payment information
                                       System.out.println("   " +year+ " \t " +pNum+ " \t  $" +(decimal.format(pPay))+ "\t$" +(decimal.format(iPay))+ "\t      $" +(decimal.format(mPayment))+ "\t     $" +(decimal.format(balance)));
                                       pNum++;
                                       if (pNum % 13 == 0)
                                            System.out.println("Please press enter to select and view another payment schedule.");
                                            System.in.read();
                                            System.in.read();
                                            year++;
                                            } //end if
                                  }//end do
                             while(year < (yTerm+1));
                        }//end class
    }//end classThis is my first post so please be gentle...
    Thanks for any help!

    When you choose Java to solve the problems, you need to adapt to the power/strategies/methodology that java offers you, and thats the way for solving problems in Java.
    Why would you put the entire implementation for calculation inside main method? You could break down the program into smaller methods which could do the calculation bit and then call them in main method.
    Anyways the reason that it is calculating for term of 7 years is that
                           // for statement loops last repayment option
                           for (rPay = 1; rPay <=3; rPay++)
                                    {mPayment[lPay] = mPayment[lPay1++];
                                     yTerm[rOller2] = yTerm[rOller3++];You are changing the value of the array yTerm[ ]. Hence once the control is out of the for loop the value of y[0]=7,y[1]=7 and y[2]=7.
    Solution 1: mark yTerm as final.
    Solution 2: set yTerm[0], yTerm[1] back as 30,15 after the for loop.
                      if (rOller1 <= 2)
                           // for statement loops last repayment option
                           for (rPay = 1; rPay <=3; rPay++)
                                    {mPayment[lPay] = mPayment[lPay1++];
                                     yTerm[rOller2] = yTerm[rOller3++];
                                     mTerm[rOller] = mTerm[rOller1++];
                                     iRate[liRate] = iRate[liRate1++];
                                //Output to screen for numerical repayment option info
                              System.out.println("    " + rPay + "\t    $" + fappAmount + "\t\t " + yTerm[rOller2] + "\t" + mTerm[rOller] + "\t    " + decimal.format(iRate[liRate]) + "% \t$" + decimal.format(mPayment[lPay])+ "\n\n");
                           yTerm [0]=30;
                           yTerm [1]=15;
                              }Futher the issue is with monthly calculation of pay back amount in switch - case statement.
    As you have not provided what the problem is and what is the criteria for calculation of monthly interest or reducing the amount etc. Its not possible (at least for me) to tell you why it would run to negative. Mathematically that is the only thing possible,
    Step 1: make those changes in your code. Make changes required to claculate the balance.
    Step 2: Execute the new code and
    Step 3: Gimme the dukes.
    Cheers
    $

  • Can I log in a site only with HttpUrlConnection?

    I'm trying to write a small program which help me to log into my Megaupload account and manage my own stuffs there. But I met a obstacle right from the start, login site.
    After reading some of Sun's ["working with URLs" lesson|http://java.sun.com/docs/books/tutorial/networking/urls/index.html] and searching around, I've tried coding a small method to do this step. As the following:
    try{
           URL mega = new URL("http://megaupload.com/?c=login");
           String data = URLEncoder.encode("login=1&
                                                            redir=1&
                                                            username=my_username&
                                                             password=my_password","UTF-8");
            HttpURLConnection connection = (HttpURLConnection)mega.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Host", "megaupload.com");
         connection.setRequestProperty("Cookie", cookie);
         connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)");
         connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
            connection.setRequestProperty("Accept-Language", "en-us, en;q=0.5");
         connection.setRequestProperty("Accept-Encoding", "gzip,deflate");
         connection.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
         connection.setRequestProperty("Keep-Alive", "115");
            connection.setRequestProperty("Connection", "keep-alive");
         connection.setRequestProperty("Referer", "http://megaupload.com/?c=login");
         connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         connection.setReadTimeout(10000);
         connection.setRequestProperty("Content-Length", Integer.toString(data.getBytes().length));
         connection.setDoInput(true);
         connection.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
         wr.writeBytes(data);
         wr.flush();
         wr.close();
           //Codes to reading the response from MU
    }catch(Exception e){
    }The headers i receipt was exactly the same as using Firefox, but the html body was always of the login site instead of redirecting to the home page with logged in status. After some failed attempts to solve it myself, I came up searching help from this forum, and realized that there's lots of problem similar to mine. However, not any of them is absolutely solved without using external libraries (HttpsClient). I wonder if I can do it only with existing internal libraries. If yes, what I need to do?
    Thanks in advanced for help, and sorry for my bad English.

    I modified it:
    String data  = URLEncoder.encode("login", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");
    data  += "&" + URLEncoder.encode("redir", "UTF-8") + "=" + URLEncoder.encode("1", "UTF-8");
    data  += "&" + URLEncoder.encode("username", "UTF-8") + "=" + URLEncoder.encode("chihuongbk", "UTF-8");
    data  += "&" + URLEncoder.encode("password", "UTF-8") + "=" + URLEncoder.encode("19881026h", "UTF-8");
    ..........Got the same result. I think that's not the problem. I feel there is something missing. Can you tell me whether I can log in the site this way with some more modifications !??

  • Building a multibinding column in a view

    I need to create a view where one column is binded to multiple properties, if one of the properties are not found, then it should not show anything.
    The xml/xaml that almost works..
    <mux:Column Name="TopParent" Width="25" DisplayName="Header_TopParent_DisplayName" Property="Status.DisplayName" DataType="s:String">
    <mux:Column.DisplayMemberBinding>
    <MultiBinding StringFormat="{}{0}{1}" FallbackValue="" TargetNullValue="">
    <Binding Path="ParentActivity/ParentChangeRequest/DisplayName" Mode="OneWay" />
    <Binding Path="ParentWorkItem/DisplayName" Mode="OneWay" />
    </MultiBinding>
    </mux:Column.DisplayMemberBinding>
    </mux:Column>
    The column then displays either the parent or the parent.parent workitem displayname. But the non-existing property always displays as DependencyProperty.UnsetValue:
    As you can see I have tried different things: Fallbackvalue and TargetNullValue, but no luck. I can read that I might need to create an IValueConverter that returns nothing if the value is unset. But this would require c# assembly I guess, and seems a little
    overkill for one very small method. Is there any way to achieve this through xml without custom converter method? (maybe there is a method already I could use?)
    If no, can someone direct me on how this assembly should be referenced in the view and imported to SCSM ? Would I need to bundle the dll with the view management pack or? 
    Thanks!

    I would use a converter. You reference it by adding the XML name space in the mux:ColumnCollection like this:
     xmlns:youralias="clr-namespace:YourNameSpace;assembly=YourAssembly"
    Then you can change your column binding to use the converter like this:
    Text="{Binding Path=YourProperty, Mode=OneWay, Converter={youralias:YourConverter}}"
    For this to work, your IValueConverter must inherit System.Windows.Markup.MarkupExtension and IValueConverter and have a slightly different format to normal converters like this:
    public class YourConverter : System.Windows.Markup.MarkupExtension, IValueConverter
    private static YourConverter _converter = null;
    public override object ProvideValue(IServiceProvider serviceProvider)
    if (_converter == null)
    _converter = new YourConverter();
    return _converter;
    object IValueConverter.Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    try
    //Process the value you pass and return the result
    catch
    return null;
    object IValueConverter.ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    return null;
    The assembly must either exist in the SCSM console installation directory or be bundled somewhere in a Management Pack.
    Rob Ford scsmnz.net
    Cireson www.cireson.com
    For a free SCSM 2012 Notify Analyst app click
    here

  • What do people think about the different Generic Java approaches?

    I have seen a lot of different approaches for Generic Java, and when people find problems with each approach the normal response has been: the other approach is worse with such and such a problem, do you have a better way?
    The different approaches I have seen are: (in no particular order)
    Please correct me if I am wrong and add other approaches if they are worthy of mention.
    1) PolyJ - by MIT
    This is a completely different approach than the others, that introduces a new where clause for bounding the types, and involves changing java byte codes in order to meet it's goals.
    Main comments were not a java way of doing things and far too greater risk making such big changes.
    2) Pizza - by Odersky & Wadler
    This aims at extending java in more ways than just adding Generics. The generic part of this was replaced by GJ, but with Pizza's ability to use primitives as generic types removed, and much bigger changes allowing GJ to interface with java.
    Main comments were that Pizza doesn't work well with java, and many things in Pizza were done in parallel with java, hence were no longer applicable.
    3) GJ - by Bracha, Odersky, Stoutamire & Wadler
    This creates classes with erased types and bridging methods, and inserts casts when required when going back to normal java code.
    Main comments are that type dependent operations such as new, instanceof, casting etc can't be done with parametric types, also it is not a very intuitive approach and it is difficult to work out what code should do.
    4) Runtime Generic Information - by Natali & Viroli
    Each instance holds information about its Runtime Type.
    Main comments from people were that this consumes way too much memory as each instance holds extra information about its type, and the performance would be bad due to checking Type information at runtime that would have been known at compile.
    5) NextGen - by Cartwright & Steele
    For each parameterized class an abstract base class with types erased is made and then for each new type a lightweight wrapper class and interface are created re-using code from the base class to keep the code small.
    Main comments from people were that this approach isn't as backwards compatible as GJ due to replacing the legacy classes with abstract base classes which can't be instantiated.
    6) .NET common runtime - by Kennedy & Syme
    This was written for adding Generics to C#, however the spec is also targeted at other languages such as VB.
    Main comments from people were that this approach isn't java, hence it is not subject to the restrictions of changing the JVM like java is.
    7) Fully Generated Generic Classes - by Agesen, Freund & Mitchell
    For each new type a new class is generated by a custom class loader, with all the code duplicated for each different type.
    Main comments from people were that the generated code size gets too big, and that it is lacking a base class for integration with legacy code.
    8) JSR-14 - by Sun
    This is meant to come up with a solution Generic Solution to be used in java. Currently it is heavily based on GJ and suffering from all the same problems as GJ, along with the fact that it is constantly undergoing change and so no one knows what to expect.
    See this forum for comments about it.
    As if we didn't have enough approaches already, here is yet another one that hopefully has all of the benefits, and none of the problems of the other approaches. It uses information learnt while experimenting with the other approaches. Now when people ask me if I think I have a better approach, I will have somewhere to point them to.
    (I will be happy to answer questions concerning this approach).
    9) Approach #x - by Phillips
    At compile time 1 type is made per generic type with the same name.
    e.g.class HashSet<TypeA> extends AbstractSet<TypeA> implements Cloneable, Serializable will be translated to a type: class HashSet extends AbstractSet implements Cloneable, SerializableAn instance of the class using Object as TypeA can now be created in 2 different ways.
    e.g.Set a = new HashSet();
    Set<Object> b = new HashSet<Object>();
    //a.getClass().equals(b.getClass()) is trueThis means that legacy class files don't even need to be re-compiled in order to work with the new classes. This approach is completely backwards compatible.
    Inside each type that was created from a generic type there is also some synthetic information.
    Information about each of the bounding types is stored in a synthetic field.
    Note that each bounding type may be bounded by a class and any number of interfaces, hence a ';' is used to separate bounding types. If there is no class Object is implied.
    e.g.class MyClass<TypeA extends Button implements Comparable, Runnable; TypeB> will be translated to a type: class MyClass {
      public static final Class[][] $GENERIC_DESCRIPTOR = {{Button.class, Comparable.class, Runnable.class}, {Object.class}};This information is used by a Custom Class Loader before generating a new class in order to ensure that the generic types are bounded correctly. It also gets used to establish if this class can be returned instead of a generated class (occurs when the generic types are the same as the bounding types, like for new HashSet<Object> above).
    There is another synthetic field of type byte[] that stores bytes in order for the Custom Class Loader to generate the new Type.
    There are also static methods corresponding to each method that contain the implementation for each method. These methods take parameters as required to gain access to fields, contructors, other methods, the calling object, the calling object class etc. Fields are passed to get and set values in the calling object. Constructors are passed to create new instances of the calling object. Other methods are passed when super methods are called from within the class. The calling object is almost always passed for non static methods, in order to do things with it. The class is passed when things like instanceof the generated type need to be done.
    Also in this class are any non private methods that were there before, using the Base Bounded Types, in order that the class can be used exactly as it was before Generics.
    Notes: the time consuming reflection stuff is only done once per class (not per instance) and stored in static fields. The other reflection stuff getting done is very quick in JDK1.4.1 (some earlier JDKs the same can not be said).
    Also these static methods can call each other in many circumstances (for example when the method getting called is private, final or static).
    As well as the ClassLoader and other classes required by it there is a Reflection class. This class is used to do things that are known to be safe (assuming the compiler generated the classes correctly) without throwing any exceptions.
    Here is a cut down version of the Reflection class: public final class Reflection {
      public static final Field getDeclaredField(Class aClass, String aName) {
        try {
          Field field = aClass.getDeclaredField(aName);
          field.setAccessible(true);
          return field;
        catch (Exception ex) {
          throw new Error(ex);
      public static final Object get(Field aField, Object anObject) {
        try {
          return aField.get(anObject);
        catch (Exception ex) {
          throw new Error(ex);
      public static final void set(Field aField, Object anObject, Object aValue) {
        try {
          aField.set(anObject, aValue);
        catch (Exception ex) {
          throw new Error(ex);
      public static final int getInt(Field aField, Object anObject) {
        try {
          return aField.getInt(anObject);
        catch (Exception ex) {
          throw new Error(ex);
      public static final void setInt(Field aField, Object anObject, int aValue) {
        try {
          aField.setInt(anObject, aValue);
        catch (Exception ex) {
          throw new Error(ex);
    }Last but not least, at Runtime one very lightweight wrapper class per type is created as required by the custom class loader. Basically the class loader uses the Generic Bytes as the template replacing the erased types with the new types. This can be even faster than loading a normal class file from disk, and creating it.
    Each of these classes has any non private methods that were there before, making calls to the generating class to perform their work. The reason they don't have any real code themselves is because that would lead to code bloat, however for very small methods they can keep their code inside their wrapper without effecting functionality.
    My final example assumes the following class name mangling convention:
    * A<component type> - Array
    * b - byte
    * c - char
    * C<class name length><class name> - Class
    * d - double
    * f - float
    * i - int
    * l - long
    * z - boolean
    Final Example: (very cut down version of Vector)public class Vector<TypeA> extends AbstractList<TypeA> implements RandomAccess, Cloneable, Serializable {
      protected Object[] elementData;
      protected int elementCount;
      protected int capacityIncrement;
      public Vector<TypeA>(int anInitialCapacity, int aCapacityIncrement) {
        if (anInitialCapacity < 0) {
          throw new IllegalArgumentException("Illegal Capacity: " + anInitialCapacity);
        elementData = new Object[initialCapacity];
        capacityIncrement = capacityIncrement;
      public synchronized void setElementAt(TypeA anObject, int anIndex) {
        if (anIndex >= elementCount) {
          throw new ArrayIndexOutOfBoundsException(anIndex + " >= " + elementCount);
        elementData[anIndex] = anObject;
    }would get translated as:public class Vector extends AbstractList implements RandomAccess, Cloneable, Serializable {
      public static final Class[][] $GENERIC_DESCRIPTOR = {{Object.class}};
      public static final byte[] $GENERIC_BYTES = {/*Generic Bytes Go Here*/};
      protected Object[] elementData;
      protected int elementCount;
      protected int capacityIncrement;
      private static final Field $0 = Reflection.getDeclaredField(Vector.class, "elementData"),
                                 $1 = Reflection.getDeclaredField(Vector.class, "elementCount"),
                                 $2 = Reflection.getDeclaredField(Vector.class, "capacityIncrement");
      static void $3(int _0, Field _1, Object _2, Field _3, int _4) {
        if (_0 < 0) {
          throw new IllegalArgumentException("Illegal Capacity: " + _0);
        Reflection.set(_1, _2, new Object[_0]);
        Reflection.setInt(_3, _2, _4);
      static void $4(int _0, Field _1, Object _2, Field _3, Object _4) {
        if (_0 >= Reflection.getInt(_1, _2)) {
          throw new ArrayIndexOutOfBoundsException(_0 + " >= " + Reflection.getInt(_1, _2));
        ((Object[])Reflection.get(_3, _2))[_0] = _4;
      public Vector(int anInitialCapacity, int aCapacityIncrement) {
        $3(anInitialCapacity, $0, this, $2, aCapacityIncrement);
      public synchronized void setElementAt(Object anObject, int anIndex) {
        $4(anIndex, $1, this, $0, anObject);
    } and new Vector<String> would get generated as:public class Vector$$C16java_lang_String extends AbstractList$$C16java_lang_String implements RandomAccess, Cloneable, Serializable {
      protected Object[] elementData;
      protected int elementCount;
      protected int capacityIncrement;
      private static final Field $0 = Reflection.getDeclaredField(Vector$$C16java_lang_String.class, "elementData"),
                                 $1 = Reflection.getDeclaredField(Vector$$C16java_lang_String.class, "elementCount"),
                                 $2 = Reflection.getDeclaredField(Vector$$C16java_lang_String.class, "capacityIncrement");
      public Vector$$C16java_lang_String(int anInitialCapacity, int aCapacityIncrement) {
        Vector.$3(anInitialCapacity, $0, this, $2, aCapacityIncrement);
      public synchronized void setElementAt(String anObject, int anIndex) {
        Vector.$4(anIndex, $1, this, $0, anObject);
    }Comparisons with other approaches:
    Compared with PolyJ this is a very java way of doing things, and further more it requires no changes to the JVM or the byte codes.
    Compared with Pizza this works very well with java and has been designed using the latest java technologies.
    Compared with GJ all type dependent operations can be done, and it is very intuitive, code does exactly the same thing it would have done if it was written by hand.
    Compared with Runtime Generic Information no extra information is stored in each instance and hence no extra runtime checks need to get done.
    Compared with NextGen this approach is completely backwards compatible. NextGen looks like it was trying to achieve the same goals, but aside from non backwards compatibility also suffered from the fact that Vector<String> didn't extend AbstractList<String> causing other minor problems. Also this approach doesn't create 2 types per new types like NextGen does (although this wasn't a big deal anyway). All that said NextGen was in my opinion a much better approach than GJ and most of the others.
    Compared to .NET common runtime this is java and doesn't require changes to the JVM.
    Compared to Fully Generated Generic Classes the classes generated by this approach are very lightweight wrappers, not full blown classes and also it does have a base class making integration with legacy code simple. It should be noted that the functionality of the Fully Generated Generic Classes is the same as this approach, that can't be said for the other approaches.
    Compared with JSR-14, this approach doesn't suffer from GJ's problems, also it should be clear what to expect from this approach. Hopefully JSR-14 can be changed before it is too late.

    (a) How you intend generic methods to be translated.
    Given that Vector and Vector<Object> are unrelated types,
    what would that type be represented as in the byte code of
    the method? In my approach Vector and Vector<Object> are related types. In fact the byte code signature of the existing method is exactly the same as it was in the legacy code using Vector.
    To re-emphasize what I had said when explaining my approach:
    System.out.println(Vector.class == Vector<Object>.class);  // displays true
    System.out.println(Vector.class == Vector<String>.class);  // displays false
    Vector vector1 = new Vector<Object>(); // legal
    Vector<Object> vector2 = new Vector();  // legal
    // Vector vector3 = new Vector<String>(); // illegal
    // Vector<String> vector4 = new Vector();  // illegal
    Vector<String> vector5 = new Vector<String>();  // legal
    You must also handle the case where the type
    parameter is itself a parameterized type in which the type
    parameter is not statically bound to a ground instantiation.This is also very straightforward: (let me know if I have misunderstood you)
    (translation of Vector given in my initial description)
    public class SampleClass<TypeA> {
      public static void main(String[] args) {
        System.out.println(new Vector<Vector<TypeA>>(10, 10));
    }would get translated as:public class SampleClass {
      public static final Class[][] $GENERIC_DESCRIPTOR = {{Object.class}};
      public static final byte[] $GENERIC_BYTES = {/*Generic Bytes Go Here*/};
      private static final Constructor $0 = Reflection.getDeclaredConstructor(Vector$$C16java_util_Vector.class, new Class[] {int.class, int.class});
      static void $1(Constructor _0, int _1, int _2) {
        try {
          System.out.println(Reflection.newInstance(_0, new Object[] {new Integer(_1), new Integer(_2)}));
        catch (Exception ex) {
          throw (RuntimeException)ex;
      public static void main(String[] args) {
        $1($0, 10, 10);
    }and SampleClass<String> would get generated as:public class SampleClass$$C16java_lang_String {
      private static final Constructor $0 = Reflection.getConstructor(Vector$$C37java_util_Vector$$C16java_lang_String.class, new Class[] {int.class, int.class});
      public static void main(String[] args) {
        SampleClass.$1($0, 10, 10);
    Also describe the implementation strategy for when these
    methods are public or protected (i.e. virtual).As I said in my initial description that for non final, non static, non private method invocations a Method may be passed into the implementing synthetic method as a parameter.
    Note: the following main method will display 'in B'.
    class A {
      public void foo() {
        System.out.println("in A");
    class B extends A {
      public void foo() {
        System.out.println("in B");
    public class QuickTest {
      public static void main(String[] args) {
        try {
          A.class.getMethod("foo", null).invoke(new B(), null);
        catch (Exception ex) {}
    }This is very important as foo() may be overwritten by a subclass as it is here. By passing a Method to the synthetic implementation this guarantees that covariance, invariance and contra variance all work exactly the same way as in java. This is a fundamental problem with many other approaches.
    (b) The runtime overhead associated with your translationAs we don't have a working solution to compare this to, performance comments are hard to state, but I hope this helps anyway.
    The Class Load time is affected in 4 ways. i) All the Generic Bytes exist in the Base Class, hence they don't need to be read from storage. ii) The custom class loader, time to parse the name and failed finds before it finally gets to define the class. iii) The generation of the generic bytes to parametric bytes (basically involves changing bytes from the Constant Pool worked out from a new Parametric type, Utf8, Class and the new Parametric Constant types may all be effected) iv) time to do the static Reflection stuff (this is the main source of the overhead). Basically this 1 time per class overhead is nothing to be concerned with, and Sun could always optimize this part further.
    The normal Runtime overhead (once Classes have been loaded) is affected mainly by reflection: On older JDKs the reflection was a lot slower, and so might have made a noticeable impact. On newer JDKs (since 1.4 I think), the reflection performance has been significantly improved. All the time consuming reflection is done once per class (stored in static fields). The normal reflection is very quick (almost identical to what is getting done without reflection). As the wrappers simply include a single method call to another method, these can be in-lined and hence made irrelevant. Furthermore it is not too difficult to make a parameter that would include small methods in the wrapper classes, as this does not affect functionality in the slightest, however in my testing I have found this to be unnecessary.
    (c) The space overhead (per instantiation)There are very small wrapper classes (one per new Type) that simply contain all non private methods, with single method calls to the implementing synthetic method. They also include any fields that were in the original class along with other synthetic fields used to store reflected information, so that the slow reflection only gets done once per new Type.
    (d) The per-instance space overheadNone.
    (e) Evidence that the proposed translation is sound and well-defined for all relevant cases (see below)Hope this is enough, if not let me know what extra proof you need.
    (f) Evidence for backward compatibility
    (For example, how does an old class file that passes a Vector
    to some method handle the case when the method receives a Vector<T>
    where T is a type parameter? In your translation these types are unrelated.)As explained above, in my approach these are only unrelated for T != Object, in the legacy case T == Object, hence legacy code passing in Vector is exactly the same as passing in Vector<Object>.
    (g) Evidence for forward compatibility
    (How, exactly, do class files that are compiled with a generics compiler run on an old VM)They run exactly the same way, the byte codes from this approach are all legal java, and all legal java is also legal in this approach. In order to take advantage of the Generics the Custom Class Loader would need to be used or else one would get ClassNotFoundExceptons, the same way they would if they tried using Collections on an old VM without the Collections there. The Custom Class Loader even works on older VMs (note it may run somewhat slower on older VMs).
    (h) A viable implementation strategyType specific instantiations are at Class Load time, when the Custom Class Loader gets asked for a new Class, it then generates it.
    The type specific instantiations are never shipped as they never get persisted. If you really wanted to save them all you need to do is save them with the same name (with the $$ and _'s etc), then the class loader would find them instead of generating them. There is little to be gained by doing this and the only reason I can think of for doing such a thing would be if there was some reason why the target VM couldn't use the Custom Class Loader (the Reflection class would still need to be sent as well, but that is nothing special). Basically they are always generated at Runtime unless a Class with the same name already exists in which case it would be used.
    The $GENERIC_DESCRIPTOR and $GENERIC_BYTES from the base class along with the new Type name are all that is required to generate the classes at runtime. However many other approaches can achieve the same thing for the generation, and approaches such as NextGen's template approach may be better. As this generation is only done once per class I didn't put much research into this area. The way it currently works is that the $GENERIC_DESCRIPTOR are basically used to verify that a malicious class files is not trying to create a non Type Safe Type, ie new Sample<Object>() when the class definition said class Sample<TypeA extends Button>. The $GENERIC_BYTES basically correspond to the normal bytes of a wrapper class file, except that in the constant pool it has some constants of a new Parametric Constant type that get replaced at class load time. These parametric constants (along with possibly Utf8 and Class constants) are replaced by the Classes at the end of the new type name, a little more complex than that but you probably get the general idea.
    These fine implementation details don't affect the approach so much anyway, as they basically come down to class load time performance. Much of the information in the $GENERIC_BYTES could have been worked out by reflection on the base type, however at least for now simply storing the bytes is a lot easier.
    Note: I have made a small syntax change to the requested class:
    public T(X datum) --> public T<X>(X datum)
    class T<X> {
      private X datum;
      public T<X>(X datum) {
        this.datum = datum;
      public T<T<X>> box() {
        return new T<T<X>>(this);
      public String toString() {
        return datum.toString();
      public static void main(String[] args) {
        T<String> t = new T<String>("boo!");
        System.out.println(t.box().box());
    }would get translated as:
    class T {
      public static final Class[][] $GENERIC_DESCRIPTOR = {{Object.class}};
      public static final byte[] $GENERIC_BYTES = {/*Generic Bytes Go Here*/};
      private Object datum;
      private static final Field $0 = Reflection.getDeclaredField(T.class, "datum");
      private static final Constructor $1 = Reflection.getDeclaredConstructor(T$$C1T.class, new Class[] {T.class});
      static void $2(Field _0, Object _1, Object _2) {
        Reflection.set(_0, _1, _2);
      static Object $3(Constructor _0, Object _1) {
        try {
          return Reflection.newInstance(_0, new Object[] {_1});
        catch (Exception ex) {
          throw (RuntimeException)ex;
      static String $4(Field _0, Object _1) {
        return Reflection.get(_0, _1).toString();
      static void $5() {
        T$$C16java_lang_String t = new T$$C16java_lang_String("boo!");
        System.out.println(t.box().box());
      public T(Object datum) {
        $2($0, this, datum);
      public T$$C1T box() {
        return (T$$C1T)$3($1, this);
      public String toString() {
        return $4($0, this);
      public static void main(String[] args) {
        $5();
    }as the generic bytes aren't very meaningful and by no means a requirement to this approach (NextGen's template method for generation may work just as well), here are the generated classes with some unused code commented out instead:
    class T$$C28T$$C22T$$C16java_lang_String {
      private T$$C22T$$C16java_lang_String datum;
      private static final Field $0 = Reflection.getDeclaredField(T$$C28T$$C22T$$C16java_lang_String.class, "datum");
    //  private static final Constructor $1 = Reflection.getDeclaredConstructor(T$$C34T$$C28T$$C22T$$C16java_lang_String.class, new Class[] {T$$C28T$$C22T$$C16java_lang_String.class});
      public T$$C28T$$C22T$$C16java_lang_String(T$$C22T$$C16java_lang_String datum) {
        T.$2($0, this, datum);
    //  public T$$C34T$$C28T$$C22T$$C16java_lang_String box() {
    //    return (T$$C34T$$C28T$$C22T$$C16java_lang_String)T.$3($1, this);
      public String toString() {
        return T.$4($0, this);
      public static void main(String[] args) {
        T.$5();
    class T$$C22T$$C16java_lang_String {
      private T$$C16java_lang_String datum;
      private static final Field $0 = Reflection.getDeclaredField(T$$C22T$$C16java_lang_String.class, "datum");
      private static final Constructor $1 = Reflection.getDeclaredConstructor(T$$C28T$$C22T$$C16java_lang_String.class, new Class[] {T$$C22T$$C16java_lang_String.class});
      public T$$C22T$$C16java_lang_String(T$$C16java_lang_String datum) {
        T.$2($0, this, datum);
      public T$$C28T$$C22T$$C16java_lang_String box() {
        return (T$$C28T$$C22T$$C16java_lang_String)T.$3($1, this);
      public String toString() {
        return T.$4($0, this);
      public static void main(String[] args) {
        T.$5();
    class T$$C1T {
      private T datum;
      private static final Field $0 = Reflection.getDeclaredField(T$$C1T.class, "datum");
    //  private static final Constructor $1 = Reflection.getDeclaredConstructor(T$$C6T$$C1T.class, new Class[] {T$$C1T.class});
      public T$$C1T(T datum) {
        T.$2($0, this, datum);
    //  public T$$C6T$$C1T box() {
    //    return (T$$C6T$$C1T)T.$3($1, this);
      public String toString() {
        return T.$4($0, this);
      public static void main(String[] args) {
        T.$5();
    class T$$C16java_lang_String {
      private String datum;
      private static final Field $0 = Reflection.getDeclaredField(T$$C16java_lang_String.class, "datum");
      private static final Constructor $1 = Reflection.getDeclaredConstructor(T$$C22T$$C16java_lang_String.class, new Class[] {T$$C16java_lang_String.class});
      public T$$C16java_lang_String(String datum) {
        T.$2($0, this, datum);
      public T$$C22T$$C16java_lang_String box() {
        return (T$$C22T$$C16java_lang_String)T.$3($1, this);
      public String toString() {
        return T.$4($0, this);
      public static void main(String[] args) {
        T.$5();
    }the methods from the Reflection class used in these answers not given in my initial description are:
      public static final Object newInstance(Constructor aConstructor, Object[] anArgsArray) throws Exception {
        try {
          return aConstructor.newInstance(anArgsArray);
        catch (InvocationTargetException ex) {
          Throwable cause = ex.getCause();
          if (ex instanceof Exception) {
            throw (Exception)ex;
          throw new Error(ex.getCause());
        catch (Exception ex) {
          throw new Error(ex);
      public static final Constructor getDeclaredConstructor(Class aClass, Class[] aParameterTypesArray) {
        try {
          Constructor constructor = aClass.getDeclaredConstructor(aParameterTypesArray);
          constructor.setAccessible(true);
          return constructor;
        catch (Exception ex) {
          throw new Error(ex);
      }

  • Slow starup of Java application - best practices for fine tuning JVM?

    We are having problems with a java application, which takes a long time to startup.
    In order to understand our question we better start with some background info. You will find the question(s) after that.
    Background:
    The setup is as follows:
    In a client-server solution we have a win xp, fat client running java 1.6.0.18.
    (Sun JRE). The fat client containt a lot of GUI, and connects to a server for DB access. Client machines are typical 1 to 3 years old (there are problems even on brand new machines). They have the client version of JRE - standard edition installed (Java SE 6 update 10 or better) Pretty much usual stuff so far.
    We have done a lot of profiling on the client code, and yes we have found parts of our own Java code that needs improving. we are all over this. Server side seems ok with good response times. So far, we havent found anything about shaky net connections or endless loops in the java client code or similiar.
    Still, things are not good. Starting the application takes a long time. too long.
    There are many complicating factors, but here is what we think we have observed:
    There is a problem with cold vs. varm starts of the application. Apparently, after a reboot of the client PC - things are really, really bad - and it takes (sometimes) up to 30-40 secs to start the application (until we arrive at the start GUI in our app).
    If we run our application, close it down, and then restart
    without rebooting, things are a lot better. It then usually takes
    something like 15 - 20 sec. which is "acceptable". Not good, but acceptable,
    Any ideas why?
    I have googled it, and some links seems to suggest that the reason could be disk cache. Where vital jar are already in disk cache on th warm start? Does that make any sense? Virus scanners presumable runs in both cases.
    People still think that 15 - 20 sec in start up on the warm start is an awful long time, even though there is a lot, a lot, of functionality in the application.
    We got a suggestion to use IBMs JRE - as it can do some tricks (not sure what) our SUN JRE cant do concerning the warm and cold start problem. But thats is not an option for us. And noone has come up with any really good suggestions with the SUN JRE so far?
    On the Java Quick Starter (JQS) -
    improves initial startup time for most java applets and applications.
    Which might be helpful? People on the internet seem more interested
    in uninstalling the thing than actually installing it though?
    And it seems very proprietary, where we cant give our Jar files to it?
    We could obviously try to "hide" the problem in some way and make it "seem" quicker. Where perceived performance can be just as good as actual performance. But it does seem a bad solution. So for the cold start we will probably try reading the jar files and thereby have them in disk cache before startup of our application. And see if that helps us.
    Still, ok the cold start is the real killer, but warm start isn't exactly wonderfull either.
    People have suggested that we read more on the JVM and performance.
    java.sun.com.javase/technologies/performance.jsp
    java.sun.com.docs/hotspot/gc5.0/gc_tuning_5.html
    the use of JVM flags "-Xms" "-Xmx" etc etc.
    And here comes the question .. da da ...
    Concerning various suggested reading material.
    it is very much appreciated - but we will like to ask people here - if it is possibe to get more specific pointers. to where the gold might be buried.
    I.e. in a an ideal world we would have time to read and understand all of these documents in depth. However, in this less than ideal world we are also doing a lot of very timeconsuming profiling in our own java code.
    E.g. java garbage collection is is a huge subject - and JVm settings also. Sure, in the end we will probably have to do this all very thoroughly. But for now we are hoping for some heuristics on what other people are doing when facing a problem like ours..?
    Young generation, large memory pages, garbage collection threads ect. all sounds interesting - but what would you start with?
    If you don't have info to decide - what kind of profiling would you be running and then adjust what JVM setting in your trials?
    In this pressed for time scenario. Ignorance is not bliss. But makes it hard to pinpoint the or those JVM parameters to adjust. So some good pointers from experienced JVM "configurators" will be much appreciated!
    Actually, If we can establish that finetuning of these parameters is a good idea, it will certainly also be much easier to allocate the time for doing so. - reading, experimenting etc. in our project.
    So, All in all , what kinds of performance improvements can we hope for? 5 out of 20 secs on the warm start? Or is it 10 % nitpicking? Whats the ball park figure for what we can hope to achieve here given our setup? What do you think based on above?
    Maybe someone out there have done some finetuning of JVM parameters in a similiar PC environments like, with similiar fat clients...? Finetuning so and so - gave 5 secs. So start your work with these one-two parameters?
    Something like that - some best practices? Thats what we are hoping for.
    best wishes
    -Simon

    Thanks for helpful answer from both you and kajbj.
    The app doesn't use shared network drives.
    What are you doing between main starts to get executed and the UI is
    displayed?
    Basicly, Calculating what to show in the UI. Accessing server - not so much, there are some reads from a cache, but the profiling doesnt indicate that it should be a problem. Sure, I could shift the startup time to some other slot, but sofar I havent found a place where the end-user wouldnt be annoyed.> Caching of something would seem most obvious. Normal VM stuff >seems unlikely. With profiling i basicly find that ''everything'' takes a lot longer in the cold start scenario. Some of our local java methods are going to be rewritten following our review. But what else can be tuned?You guys dont think the Java Quick Start approach, with more jars in disk cache will give something? And how should that be done/ what does people do?I.e. For the class loader I read something about
    1.Bootstrap class loader
    2.Extensions class loader
    3.System class loader
    and is wondering if this has something to do with the cold start problem?
    The extensions class loader loads the code in the extensions directories (<JAVA_HOME>/lib/ext
    So, we should move app classes to ext? Put them in one jar file? (We have many). Best practice about that?
    Otherwise it seems to me that it must be about finetuning the JVM?
    I imagine that it is a question about:
    1. the right heap size
    2. the right garbage collection scheme
    Googling heap size for XP
    CHE22 writes:
    You are right; -Xms1600M works well, but -Xms1700M bombs
    Thats one best practice or what?
    On garbage collection, there are numerous posts, and much "masters of Java black art" IMHO, And according to profiling GC is not really that much of a problem anyway? Still,
    Based on my description I was hoping for a short reply like "try setting these two parameters on your xp box, it worked for me" ...or something like that. With no takers on that one, I fear people are saying that there is nothing to be gained there?
    we read:
    [ -Xmx3800m -Xms3800m
    Configures a large Java heap to take advantage of the large memory system.
    -Xmn2g
    Configures a large heap for the young generation (which can be collected in parallel), again taking advantage of the large memory system. It helps prevent short lived objects from being prematurely promoted to the old generation, where garbage collection is more expensive.
    Unless you have problems with pauses, try granting as much memory as possible to the virtual machine. The default size (64MB) is often too small.
    Setting -Xms and -Xmx to the same value increases predictability by removing the most important sizing decision from the virtual machine. On the other hand, the virtual machine can't compensate if you make a poor choice.
    The -XX:+AggressiveHeap+ option inspects the machine resources (size of memory and number of processors) and attempts to set various parameters to be optimal for long-running, memory allocation-intensive jobs]
    So is Setting -Xms and -Xmx and -XX:AggressiveHeap
    best practice? What kind of performance improvement should we expect?
    Concerning JIT:
    I read this one
    [the impact of the JIT compiler is obvious on the graph: at startup the time taken is around 500us for the first few values, then quickly drops to 130us, before falling again to 70us, where it stays for 30 minutes,
    for this specific issue, I greatly improved my performances by configuring another VM argument: I set -XX:CompileThreshold=50]
    The size of the cache can be changed with
    -Xmaxjitcodesize
    This sounds like you should do something with JIT args, but reading
    // We disable the JIT during toolkit initialization. This
    // tends to touch lots of classes that aren't needed again
    // later and therefore JITing is counter-productiive.
    java.lang.Compiler.disable();
    However, finding
    the sweet spots for compilation thresholds has been tricky, so we're
    still experimenting with the recompilation policy. Work on it
    continues.
    sounds like there is no such straigth forward path, it all depends...
    Ok, its good, when
    [Small methods that can be more easily analyzed, optimized, and inlined where necessary (and not inlined where not necessary). Clearly delineated uses of data so that usage patterns and lifetimes are apparent. ]
    but when I read this:
    [The virtual machine is responsible for byte code execution, storage allocation, thread synchronization, etc. Running with the virtual machine are native code libraries that handle input and output through the operating system, especially graphics operations through the window system. Programs that spend significant portions of their time in those native code libraries will not see their performance on HotSpot improved as much as programs that spend most of their time executing byte codes.]
    I have the feeling that we might not able to improve performance that way?
    Any comments?
    otherwise i was wondering about
    -XX:CompileThreshold=50 -Xmaxjitcodesize (large, how large?)
    Somehow, we still feel that someone out there should have experienced similiar problems? But obviously there is no guarantee that the someone should surf by here!
    In c++ we used to just write everything ourselves. Here it does seem to be a question about the right use of other peoples stuff?
    Where you are kind of hoping for a shortcut, so you dont have to read endless number of documents, but can find a short document that actually addresses your problem ... well.
    -Simon
    Edited by: simoncpm on Mar 15, 2010 3:43 PM
    Edited by: simoncpm on Mar 15, 2010 3:53 PM

  • JPanel not displaying components

    i am working on a simple html renderer- at the moment all i am trying to do is to add JTextPane components to two different JPanels (search and content). I can add the text panes to the search bar, however none of the components are displayed in the content panel. I get no compile time errors, im really at a loss as to what the problem could be.
    this is the code im using-
    public class Demo extends JFrame
        private JPanel search, content;
        private JSplitPane splitPane;
        //private ArrayList<JTextPane> textCollection;
        //private ArrayList<JTextPane> preCollection;
        //specifies the universal font size the content JPanel
        private final int fontSize = 18;
        //specifies the universal font size for the search JPanel
        private final int searchFontSize = 9;
        /** Creates a new instance of Main */
        public Demo()
          this.setTitle("DEMO!");
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          //sets default size
          this.setSize(500, 500);
          //init panel controls- these will hold all rendered controls
          search = new JPanel();
          //use BoxLayout to ensure controls are positioned correctly
          search.setLayout(new BoxLayout(search, BoxLayout.Y_AXIS));
          search.setBackground(Color.white);
          content = new JPanel();
          content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
          content.setBackground(Color.white);
          //init JScrollPanes for both containers- allows for scrolling content of unlimited width/length
          JScrollPane contentScroller = new JScrollPane(content);
          JScrollPane searchScroller = new JScrollPane(search);
          //create a split pane container to contain both scroll panes
          splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchScroller, contentScroller);
          //search bar recieves 25% of screen size
          splitPane.setDividerLocation(this.getWidth() / 4);
          this.getContentPane().add(splitPane);
          //show controls
          this.setVisible(true);
        * Creates a new text component- text contained will be line wrapped as the user resizes the JFrame
        public void newText(String text)
          //init properites of new JTextPane
          JTextPane tp = newTextPane(text);
          tp.setBackground(Color.blue);
          //line wrap add to content panel
          tp.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
          tp = getLines(tp, this.getWidth() - splitPane.getDividerLocation());
          content.add(tp);
          //resize text for search panel, line wrap and add to search panel
          tp.setFont(new Font("Times New Roman", Font.PLAIN, searchFontSize));
          tp = getLines(tp, splitPane.getDividerLocation());
          search.add(tp);
        * Creates a new preformated text component- this will not be line wrapped
        public void newPre(String preformattedContent)
            JTextPane tp = newTextPane(preformattedContent);
            tp.setBackground(Color.red);
            //add to content panel
            tp.setFont(new Font("Courier New", Font.PLAIN, fontSize));
            content.add(tp);
            //resize text for search panel and add to search panel
            tp.setFont(new Font("Courier New", Font.PLAIN, searchFontSize));
            search.add(tp);
        * Small method that init's a JTextPane component with common properites used by the newText/Pre methods
        private JTextPane newTextPane(String s)
          JTextPane tp = new JTextPane();
          //set text
          tp.setText(s);
          //may not be editied
          tp.setEditable(false);
          //align correctly
          tp.setAlignmentY(Component.TOP_ALIGNMENT);
          tp.setAlignmentX(Component.LEFT_ALIGNMENT);
          //set maximum size to preferred size, this makes sure the JTextComponent will not "stretch" when the JFrame is resized drastically
          tp.setMaximumSize(tp.getPreferredSize());
          return tp;
        * Sets the appropriate preferred height & width of a given JTextPanel, essentially word wrapping any text contained within
        private JTextPane getLines(JTextPane tp, int paneSize)
          //get preferred size of the text panel - this is the smallest size the text panel may be and still visibly display its text content
          Dimension d = tp.getPreferredSize();
          double prefWidth = d.getWidth();
          double prefHeight = d.getHeight();
          //factor will determine if line wrapping is required
          double factor = prefWidth / (double) paneSize;
          //if factor is greater than 1, the preferred width is greater than the size available in the pane
          if (factor >= 1){
            //set width so that it matches the size available on the screen
            d.setSize((double) this.getWidth() - paneSize, factor * prefHeight);
            tp.setMaximumSize(d);
            tp.setPreferredSize(d);
          //else- do nothing! resizing is not required
          return tp;
         * @param args the command line arguments
        public static void main(String[] args)
          Demo d = new Demo();
          d.newText("this is some content ooh look content i hope this is long enough to test the wrapp esfsdfsdf sdf sdfsdfsd fsdf sdfsdfsdfd sfsdf sdfsdxf sdf sdf sdfsd fsd fsdf ing");
          d.newPre("a     pre          formatted           lump of    =  text! !  !");
        public void paint(Graphics g)
            super.paint(g);
            System.out.println("update called");
            //preferred.setSize(this.getWidth() - (this.getWidth() / 4), this.getHeight());
            //max.setSize(this.getWidth(), this.getHeight());
    }

    Do you need to keep adding JTextPane's to the content and search panes or do you just need to append text to the existing panes?
    If the later, you may want to create the JTextPanes in the constructor and use a set method to append/edit/remove text. As follows:
    import javax.swing.*;
    import java.awt.*;
    public class Demo extends JFrame
        private JPanel search, content;
        private JSplitPane splitPane;
        private JTextPane contentTextPane;
        private  JTextPane searchTextPane;
        //private ArrayList<JTextPane> textCollection;
        //private ArrayList<JTextPane> preCollection;
        //specifies the universal font size the content JPanel
        private final int fontSize = 18;
        //specifies the universal font size for the search JPanel
        private final int searchFontSize = 9;
        /** Creates a new instance of Main */
        public Demo()
          this.setTitle("DEMO!");
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          //sets default size
          this.setSize(500, 500);
          //init panel controls- these will hold all rendered controls
          search = new JPanel();
          //use BoxLayout to ensure controls are positioned correctly
          search.setLayout(new BoxLayout(search, BoxLayout.Y_AXIS));
          search.setBackground(Color.white);
          content = new JPanel();
          content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS));
          content.setBackground(Color.white);
          //init JScrollPanes for both containers- allows for scrolling content of unlimited width/length
          JScrollPane contentScroller = new JScrollPane(content);
          JScrollPane searchScroller = new JScrollPane(search);
          //create a split pane container to contain both scroll panes
          splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, searchScroller, contentScroller);
          //search bar recieves 25% of screen size
          splitPane.setDividerLocation(this.getWidth() / 4);
          /*add the textpanes to the JPanels*/
          contentTextPane = new JTextPane();
          content.add(contentTextPane);
          searchTextPane = new JTextPane();
          search.add(searchTextPane);
          this.getContentPane().add(splitPane);
          //show controls
          this.setVisible(true);
        * Creates a new text component- text contained will be line wrapped as the user resizes the JFrame
        public void newText(String text)
          //init properites of new JTextPane
          JTextPane tp = newTextPane(text);
          tp.setBackground(Color.blue);
          //line wrap add to content panel
          tp.setFont(new Font("Times New Roman", Font.PLAIN, fontSize));
          tp = getLines(tp, this.getWidth() - splitPane.getDividerLocation());
          content.add(tp);
          //resize text for search panel, line wrap and add to search panel
          tp.setFont(new Font("Times New Roman", Font.PLAIN, searchFontSize));
          tp = getLines(tp, splitPane.getDividerLocation());
          search.add(tp);
        public void addToContent(String text){
             contentTextPane.setText(text);
        * Creates a new preformated text component- this will not be line wrapped
        public void newPre(String preformattedContent)
            JTextPane tp = newTextPane(preformattedContent);
            tp.setBackground(Color.red);
            //add to content panel
            tp.setFont(new Font("Courier New", Font.PLAIN, fontSize));
            content.add(tp);
            //resize text for search panel and add to search panel
            tp.setFont(new Font("Courier New", Font.PLAIN, searchFontSize));
            search.add(tp);
        * Small method that init's a JTextPane component with common properites used by the newText/Pre methods
        private JTextPane newTextPane(String s)
          JTextPane tp = new JTextPane();
          //set text
          tp.setText(s);
          //may not be editied
          tp.setEditable(false);
          //align correctly
          tp.setAlignmentY(Component.TOP_ALIGNMENT);
          tp.setAlignmentX(Component.LEFT_ALIGNMENT);
          //set maximum size to preferred size, this makes sure the JTextComponent will not "stretch" when the JFrame is resized drastically
          tp.setMaximumSize(tp.getPreferredSize());
          return tp;
        * Sets the appropriate preferred height & width of a given JTextPanel, essentially word wrapping any text contained within
        private JTextPane getLines(JTextPane tp, int paneSize)
          //get preferred size of the text panel - this is the smallest size the text panel may be and still visibly display its text content
          Dimension d = tp.getPreferredSize();
          double prefWidth = d.getWidth();
          double prefHeight = d.getHeight();
          //factor will determine if line wrapping is required
          double factor = prefWidth / (double) paneSize;
          //if factor is greater than 1, the preferred width is greater than the size available in the pane
          if (factor >= 1){
            //set width so that it matches the size available on the screen
            d.setSize((double) this.getWidth() - paneSize, factor * prefHeight);
            tp.setMaximumSize(d);
            tp.setPreferredSize(d);
          //else- do nothing! resizing is not required
          return tp;
         * @param args the command line arguments
        public static void main(String[] args)
          Demo d = new Demo();
          d.newText("this is some content ooh look content i hope this is long enough to test the wrapp esfsdfsdf sdf sdfsdfsd fsdf sdfsdfsdfd sfsdf sdfsdxf sdf sdf sdfsd fsd fsdf ing");
          d.newPre("a     pre          formatted           lump of    =  text! !  !");
          d.addToContent("testing the content panel");
        public void paint(Graphics g)
            super.paint(g);
            System.out.println("update called");
            //preferred.setSize(this.getWidth() - (this.getWidth() / 4), this.getHeight());
            //max.setSize(this.getWidth(), this.getHeight());
    }If this is not the case let me know and Ill take another look. ;-)

Maybe you are looking for

  • Need to Restore MBR

    I was trying to install a modified version of XP using Boot Camp. After partitioning the drive, I couldn't get it to install. In an act of desperation, I followed some ill-advised "support" on another forum, and ended up manually deleting the Boot Ca

  • .DOC to .PDF conversion with the format maintainence

    Hi, My requirement is to convert the exact text witht he formating in the .DOC file to PDF file. I have done this using POI and IText ar files but I am unable to maintain the formating , tried and search the net but unable to find the solution. Pleas

  • Passing Parameters to Bounded Task Flow from JSPX

    Hi All, 1. Created a JSPX page using UIShell template.  This page contains 4 UI Components (InputComboBoxListOfValues) in SingleObjectContextArea.  Created a Managed Bean for this page and capture the selected value in ValueChangeListner and added th

  • Firefox won't load certain websites.

    Firefix won't load some certain websites. I even have to use google chrome now, to ask advice. I did all the things said in the help page but it only seemed to turn internet connection slower! It seems that FF is having problems with save websisites

  • How to get select statment in debug mode

    hi all i make debug in forms 10g and in debug mode and in a specified point , i want to see tha last select statment in debuger thanks