Parametrized class into parametrizd class

Hello,
I was wondering about the following: imagine you have a parametrized class SomeClass<A, B, C> with an inner (public, private or protected, doesn't matter) class, which is a collection of B-elements. Until now, I would declare SomeClass and the innter class as followed:
class SomeClass<A, B, C>
     SomeCollection coll = new SomeCollection();
     class SomeCollection extends java.util.AbstractCollection<B>
}However, while browsing through the JDK 1.5 source, I noticed the developers implement parametrized inner classes of a parametrized class as followed:
class SomeClass<A, B, C>
     SomeCollection<B> coll2 = new SomeCollection<B>();
     class SomeCollection<E> extends java.util.AbstractCollection<E>
}Is choosing between the first or the latter definition of the inner class SomeCollection a matter of personal preference, or is there a subtle difference between the two definitions? In other words, are they in every situation 100% equivalent?
I understand that one doesn't have to change the implementation of the second SomeCollection (ie. SomeCollection<D>) if he decides, for whatever reason, to have a collection of, for example, A-elements instead of B-elements (SomeCollection<B> coll2 = new SomeCollection<B>(); becomes SomeCollection<A> coll2 = new SomeCollection<A>();). Is this the only reason to prefer the second definition above the first definition?
Another example:
interface SomeInterface<X, Y>
class SomeClass<A, B, C>
     class SomeCollection extends java.util.AbstractCollection<SomeInterface<A, C>>
}thanks!

Thanks for your answer Bruce.
However, I think I found a difference, which hasn't anything to do with personal preference (flexibility for further use, ...) or the scoop of static classes. I'll give the code first:
class SomeClass<A, B, C, D>
     public Iterator<SomeInterface<A, B>> iterator()
          return new IteratorImpl();
     private class IteratorImpl implements Iterator<SomeInterface<A, B>>
          public boolean hasNext()
               return false;
          public SomeInterface<A, B> next()
               return null;
          public void remove()
class SomeClass<A, B, C, D>
     public Iterator<SomeInterface<A, B>> iterator()
          return new IteratorImpl<SomeInterface<A, B>>();
     private class IteratorImpl<T> implements Iterator<T>
          public boolean hasNext()
               return false;
          public T next()
               return null;
          public void remove()
}Semantically, the two fragments are identical. However, in the first fragment in the next()-function of the Iterator, there is the following type unsafety warning:
Type safety: The return type SomeInterface<A,B> of the method next() of type SomeClass<A,B, C,D>.IteratorImpl needs unchecked conversion to conform to the return type E of inherited method.
Can anybody explains this warning? IteratorImpl implements Iterator<SomeInterface<A, B>>, so why is it unsafe to have SomeInterface<A, B> as the return type of the next()-function? I don't understand this.
I noticed this while studying the JDK 1.5 source. So I would like to add another question: why did the developers leave a typesafety warning, if it can be easily fixed with the 'walk around' as given in the second fragment?
thanks,
Peter

Similar Messages

  • How to override attributes of one class into another class in OOPS ABAP

    I was trying to override attribute(data memeber) defined in super class into subclass ,
    but I didnt find any solution to that.
    Please tell me ho to do that?
    Ex
    Class ABC definition
          Public section
             data : x type i.
       end class
    Calss XYZ definition inheriting from ABC.
        Publec section.
           data : x type  i.                                            <<----
    here is the problem
    endclass.

    when you define a subclass all the properties of superclass are inherited into class.
    You dont need to define it again.
    data : x type i " delete this line.
    Object of your subclass will be able to recognize x.
    Regards,
    Lalit Mohan Gupta.

  • Using one class into other class??

    Hey,I need to pass one class's object to another class's constructor.problem is which class I should compile first because both classes are using each other so when i compile any of these file it gives error in refering other as other file is not compiled.I am using as follows:
    package p;
    class test1
    //statements
    test2(this);
    Here is my second class:
    package p;
    class test2
    test2(test1 t)
    //some statements

    surely you can put them on one page/file and compile?? (i m just givin a suggestion, i am by no means an expert! :) )

  • Is it possible to copy multiple classes into one class?

    Hi there,
    My environment is 2007 R2. We have two class: Class1 and Class2. Both are populated by a script discovery. Now I want to create another class: Class3 which should contain the object of BOTH Class1 and Class2. Of cause I can create another script discovery
    for class3. But since the objects are already discovered in class1 and class2, I just need to copy them into class3, is there any other way? I tried to avoid introducing more script discovery.

    Thanks for the reply. But the group one doesn't work well. The main reason for this is because I want to create ONE SINGLE state view and alert view for my application. There are few classes: web servers, portal servers, db server and etc. Using group works
    on alert view. However state view doesn't.
    Those class are NOT generating from the same seed class. However they all have similar properties: name, role, lob and etc.
    Any suggestion?

  • Splitting class into multiple classes (simple fix I think)

    Here is the class, images, and library for blueJ in a .rar file:
    http://www.mediafire.com/file/467dunvcmtfd67f/Ucigame_pong.rar
    If you don't use blueJ or just want the code, it's just the one class:
    import ucigame.*;
    public class Pong extends Ucigame
        Sprite ball;
        Sprite paddle;
        public void setup()
            window.size(250, 250);
            window.title("Pong");
            framerate(30);
            Image bkg = getImage("images/background.png");
            canvas.background(bkg);
            ball = makeSprite(getImage("images/ball.gif", 255, 0, 0));
            paddle = makeSprite(getImage("images/paddle.png"));
            ball.position(canvas.width()/2 - ball.width()/2,
                          canvas.height()/2 - ball.height()/2);
            ball.motion(6, 3);
            paddle.position(canvas.width() - paddle.width() - 10,
                           (canvas.height() - paddle.height()) / 2);
        public void draw()
            canvas.clear();
            ball.move();
            ball.bounceIfCollidesWith(paddle);
            ball.bounceIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.stopIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.draw();
            ball.draw();
        public void onKeyPress()
            // Arrow keys and WASD keys move the paddle
            if (keyboard.isDown(keyboard.UP, keyboard.W))
                paddle.nextY(paddle.y() - 2);
            if (keyboard.isDown(keyboard.DOWN, keyboard.S))
                paddle.nextY(paddle.y() + 2);
            if (keyboard.isDown(keyboard.LEFT, keyboard.A))
                paddle.nextX(paddle.x() - 2);
            if (keyboard.isDown(keyboard.RIGHT, keyboard.D))
                paddle.nextX(paddle.x() + 2);
    }and the library: http://ucigame.org/ucigame-source.zip
    All I want to do is have the Pong class call the setup(), draw(), and onkeypress() from different classes. Or is it better the way it is? There is no main() or run() class the way ucigame makes the examples.
    Thank you,
    Joey

    This isn't necessarily the best solution since I don't know all the details of your project, but if you wanted to put the methods in a separate class and call them from the main() method in the Pong class, you could do as follows
    import ucigame.*;
    public class Pong extends Ucigame
        public static voic main(String args[]){
            GameUtil gameUtilClass = New GameUtil();
            gameUtilClass.setup();
            gameUtilClass.draw();
            gameUtilClass.onKeyPress();
    // new class to hold methods
    public class GameUtil
        Sprite ball;
        Sprite paddle;
        public void setup()
            window.size(250, 250);
            window.title("Pong");
            framerate(30);
            Image bkg = getImage("images/background.png");
            canvas.background(bkg);
            ball = makeSprite(getImage("images/ball.gif", 255, 0, 0));
            paddle = makeSprite(getImage("images/paddle.png"));
            ball.position(canvas.width()/2 - ball.width()/2,
                          canvas.height()/2 - ball.height()/2);
            ball.motion(6, 3);
            paddle.position(canvas.width() - paddle.width() - 10,
                           (canvas.height() - paddle.height()) / 2);
        public void draw()
            canvas.clear();
            ball.move();
            ball.bounceIfCollidesWith(paddle);
            ball.bounceIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.stopIfCollidesWith(TOPEDGE, BOTTOMEDGE, LEFTEDGE, RIGHTEDGE);
            paddle.draw();
            ball.draw();
        public void onKeyPress()
            // Arrow keys and WASD keys move the paddle
            if (keyboard.isDown(keyboard.UP, keyboard.W))
                paddle.nextY(paddle.y() - 2);
            if (keyboard.isDown(keyboard.DOWN, keyboard.S))
                paddle.nextY(paddle.y() + 2);
            if (keyboard.isDown(keyboard.LEFT, keyboard.A))
                paddle.nextX(paddle.x() - 2);
            if (keyboard.isDown(keyboard.RIGHT, keyboard.D))
                paddle.nextX(paddle.x() + 2);
    }The methods really shouldn't have a class for each one.
    Edited by: JDScoot on May 23, 2011 3:33 PM

  • Combining multiple programs into one class

    So I have three classes, each with a program that does something different. I have to combine all three of them into one class, that gives an initial user interface asking which of the three programs would the user like to run, then runs the chosen program. How do I combine all three program classes into one class and have them run in such a way.
    Everything must be within ONE class.

    I know that.
    My issue is actually doing it in a way that isn't really ugly. Right now I just used a few huge if statements and put all my programs in those. I need to break it up into separate...methods I think it is.
    Here's my ugly ugly code.
    import java.util.*;
    import java.text.*;
    public class AssignmentFour {
         public static void main(String[] args) {
              Scanner sc1 = new Scanner(System.in);
              System.out.println("What program would you like to run:" );
              System.out.println("1. Long Distance Charges ");
              System.out.println("2. Internet Provider Charges ");
              System.out.println("3. Math Tutor ");
              System.out.println("4. Quit ");
              System.out.println("=> ");
              String numb = sc1.next();
              int num1 = new Integer(numb).intValue();
              if (num1 == 1) {Scanner sc2 = new Scanner(System.in);
              System.out.print("Please Enter the Starting Time of your call: ");
              String clock = sc2.nextLine();
              Scanner sc3 = new Scanner(System.in);
              System.out.print("Please Enter the Length of your call: ");
              String length = sc3.nextLine();
              float clock1 = Float.parseFloat(clock);
              int length1 = new Integer (length).intValue();
              double cost1 = 0;
              if (clock1 < 6.59) {cost1 = 0.14;}
              if (clock1 < 19.00 && clock1 > 7.00) {cost1 = 0.42;}
              if (clock1 < 23.59 && clock1 > 7.01) {cost1 = 0.28;}
              if (clock1 > 0.59 && clock1 < 0.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 1.59 && clock1 < 1.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 2.59 && clock1 < 2.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 3.59 && clock1 < 3.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 4.59 && clock1 < 4.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 5.59 && clock1 < 5.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 6.59 && clock1 < 6.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 7.59 && clock1 < 7.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 8.59 && clock1 < 8.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 9.59 && clock1 < 9.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 10.59 && clock1 < 10.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 11.59 && clock1 < 11.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 12.59 && clock1 < 12.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 13.59 && clock1 < 13.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 14.59 && clock1 < 14.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 15.59 && clock1 < 15.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 16.59 && clock1 < 16.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 17.59 && clock1 < 17.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 18.59 && clock1 < 18.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 19.59 && clock1 < 19.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 20.59 && clock1 < 20.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 21.59 && clock1 < 21.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 22.59 && clock1 < 22.99) {System.out.println("Error! Improper input!");}
              if (clock1 > 23.59) {System.out.println("Error! Improper input!");}
              if (length1 < 300) {length1 = length1;}
              if (length1 < 1) {System.out.println("Error! Improper input!");}
              if (length1 > 300) {System.out.println("Error! Improper input!");}
              double finalcost = (cost1*length1);
              DecimalFormat format = new DecimalFormat("0.00");
              String finalcostprint = (format.format(finalcost) + " ");
              if (clock1 > 0.00 && clock1 < 0.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 1.00 && clock1 < 1.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 2.00 && clock1 < 2.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 3.00 && clock1 < 3.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 4.00 && clock1 < 4.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 5.00 && clock1 < 5.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 6.00 && clock1 < 6.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 7.00 && clock1 < 7.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 8.00 && clock1 < 8.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 9.00 && clock1 < 9.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 10.00 && clock1 < 10.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 11.00 && clock1 < 11.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 12.00 && clock1 < 12.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 13.00 && clock1 < 13.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 14.00 && clock1 < 14.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 15.00 && clock1 < 15.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 16.00 && clock1 < 16.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 17.00 && clock1 < 17.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 18.00 && clock1 < 18.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 19.00 && clock1 < 19.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 20.00 && clock1 < 20.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 21.00 && clock1 < 21.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 22.00 && clock1 < 22.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (clock1 > 23.00 && clock1 < 23.59 && length1 < 300 && length1 > 0) {System.out.println("The charge for your call is " + finalcostprint + "");}
              if (num1 == 2) {
                   Scanner sc4 = new Scanner(System.in);
                   System.out.print("Enter customer billing information (First Name Last Name Package Hours Used): ");
                   String firstname = sc1.next();
                   String lastname = sc1.next();
                   String package1 = sc1.next();
                   String hours = sc4.next();
                   String packaged = package1.substring(0,1);
                   int hour = new Integer(hours).intValue();
                   double costa = (12.95 + 1.50*(hour-10));
                   double costb = (16.95 + 0.85*(hour-20));
                   double costc = (29.95);
                   char pack = packaged.charAt(0);
                   double cost = 0;
                   char A = 'A';
                   char B = 'B';
                   char C = 'C';
                   if (pack == A) {cost = 12.95 + 1.50*(hour-10);}
                   if (pack == B) {cost = 16.95 + 0.85*(hour-20);}
                   if (pack == C) {cost = 29.95;}
                   DecimalFormat format = new DecimalFormat("0.00");
                   String costprint = (format.format(cost));
                   if (pack == A) {System.out.println("Charges for " + firstname + " " + lastname + " (" + package1 + ") are $" + costprint + "");}
                   if (pack == B) {System.out.println("Charges for " + firstname + " " + lastname + " (" + package1 + ") are $" + costprint + "");}
                   if (pack == C) {System.out.println("Charges for " + firstname + " " + lastname + " (" + package1 + ") are $" + costprint + "");}
                   double saved = 0;
                   float costprinty = new Float(costprint).intValue();
                   if (costprinty>costa) {saved = cost - costa;}
                   if (costprinty>costb) {saved = cost - costb;}
                   if (costprinty>costc) {saved = cost - costc;}
                   char packy = 'A';
                   if (cost>costa) {packy = A;}
                   if (cost>costb) {packy = B;}
                   if (cost>costc) {packy = C;}
                   if (cost>costa && cost>costb && costa>costb) {saved = cost - costb;}
                   if (cost>costa && cost>costb && costb>costa) {saved = cost - costa;}
                   if (cost>costa && cost>costc && costa>costc) {saved = cost - costc;}
                   if (cost>costa && cost>costc && costb>costa) {saved = cost - costa;}
                   if (cost>costb && cost>costc && costb>costc) {saved = cost - costc;}
                   if (cost>costb && cost>costc && costc>costb) {saved = cost - costb;}
                   DecimalFormat format2 = new DecimalFormat("0.00");
                   String savey = (format.format(saved));
                   if (saved > 0) {System.out.println("" + firstname + " " +lastname+ " could have saved $" + savey + " by switching to package " + packy + ".");
                   if (num1 == 3) {
                        Random r = new Random();
                        int a = r.nextInt(99);
                        int b = r.nextInt(99);
                        int c = (a + b);
                        int d = (a * b);
                        int z = r.nextInt(2);
                   Scanner sc5 = new Scanner(System.in);
                   if (z == 0) System.out.print("" + a + " + " + b + " = ");
                   if (z == 1) System.out.print("" + a + " * " + b + " = ");
                   String answer = sc5.next();
                   int answery = new Integer(answer).intValue();
                   if (c == answery && z == 0) {System.out.println("Congratulations! You are a math whiz!");}
                   else if (d == answery && z == 1) {System.out.println("Congratulations! You are a math whiz!");}
                   else {System.out.println("Wrong!");}
                   if (num1 == 4) {
                        System.out.println("Goodbye");
                   else {System.out.println("Improper input!");
    }

  • Importing Class to Custom Class

    I'm writing my own class. (The Peacock class if you want to
    know.) I want to use the Tween class in my class, but I don't know
    how to import another class into my class. How do I go about that.
    Thanks.

    It makes a fan of peacock feathers. It is mostly just an
    excuse to practice my AS2. (David "Seething Cauldron" Still has
    lured me to the dark side!) I've got the strut() and modesty()
    methods down. I'm closing in on shimmy(). But there are two bits I
    haven't really worked out yet, neither really has to do with AS 2.
    Any good approach for having slight variations in color? I'm
    using the drawing API to draw the spots/eyes and want to have each
    one vary a bit in color. Any good approaches or places I should
    check out?
    The other is that crazy modulo math. I need to generate the
    following sequence:
    -1, 1, -2, 2, -3, 3, -4, etc.
    and or alternately:
    0, 1, 1, 0, 0, 1, 1, 0, 0, repeating
    I've got a nasty hacky bit, but I'm sure there is an elegant
    way, but my mind just doesn't go that way.
    When I get it polished up a bit more I would be happy to post
    a copy if you want to see it.

  • Use Non Class VIs within Class

    I suppose this is a theory of OOP question.
    Say I have 2 classes, 1 is used to set the voltage on a power supply, and another is used to update a user interface.  They are not really related at all in that there is no common parent class and there is essentially no relationship between them.
    Now, I write a subVI that is some sort of specialized random number generator.  What if I want to use that VI within a method of each of the two classes I created above.  Where does this subVI belong?
    I can think of the following options, but I'm not sure what the best one is.  I would really love to hear your suggestions because it's been bugging me for a while:
    1) Create a method within each class that has the random number generator functionality.  I don't like this idea because I will be duplicating code.
    2) Simply choose to store the VI as part of my project and not include it within the classes.  What I don't like about this is that if I decide to reuse my code/class in another project, I will need to copy VIs that are not part of my class with it.
    3) Create some sort of "utilities" class that would hold all of these miscellaneous VIs and then use methods from this class.  I could pass an object of this utilities class into each class so I would have access to the methods.  But this seems to be pretty complicated.
    So that's the dilemma.  I'm wondering how all of you have chosen to solve this problem.  Thanks!
    Solved!
    Go to Solution.

    Create a reuse library.  I recommend looking at VI Package Manager.  You can create "packages" of reuse code and "install" them into each version of LabVIEW.  Then anybody can use them since they are in one nice location.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Import other class from other class file

    let say, i got class student in the file name "student.class".
    my main program is school.class.
    how to import student.class into school.class so i can use student class.?
    what is the directory i had to store the 2 file?

    School.java:
    class School {
        Student a, b, c;
        public static void main(String[] args) {
            a = new Student("fred","foobar");
            b = new Student("fred","barbaz");
            c = new Student("fred","bazqux");
            System.out.println("Student a is "+a.name+" "+a.surname);
            System.out.println("Student b is "+b.name+" "+b.surname);
            System.out.println("Student c is "+c.name+" "+c.surname);
    class Student {
        String name, surname;
        public Student(String nam, String sur) {
            name = name;
            surname = sur;
    }

  • How can i use JWSDP1.6 from Ant tool to convert .wsdl file into Java class

    Hi All,
    i m very new in the development field.plese help me...
    i have a .wsdl file and i have to make some modification in the file and return this file with build file used in Ant tool.
    means my requirement is to conver the .wsdl file into java class,modify it and convert back to wsdl file.how can i do it using JWSDP1.6 and Ant tool.
    thanks in advance...
    Vikram Singh

    lemilanais wrote:
    hello!
    I have developpe an animation with flash. before give it to othe person in order to use it, i would like to secure it by integrated a security module inside the software.Secure it from what? Being played? Copied? Deleted? Modified?
    Because, i am a java developper, i have choose Netbeans 6.1 to secure it.That has to be the most random thing I've read in some time.
    do you know how can i do to integrate my animation .swf inside my java class?Java can't play SWF files and Flash can't handle Java classes, so what you're suggesting here doesn't make a lot of sense.

  • How to convert .class into .jar file

    Hi,
    How to convert .class into .jar file

    jsf_VWP5.5.1 wrote:
    Hi,
    How to convert .class into .jar fileFrom a command prompt, cd to the location of your .class file(s).
    If you want to create a simple jar, use: jar -cf Whatever.jar Whatever.class
    If you want to compile all .class files in a directory into a jar, use *.class instead.
    Now, I'm going to assume you want to create an executable jar... here's how to do that:
    1) Create a blank text file; for this example, lets call it main.txt.
    2) In the first line of main.txt, type: Main-class: Whatever ('Whatever' should be the name of the class in your program where the main() method is located)
    3) Press enter to go to the next line (someone please correct me if I'm wrong, but if you don't insert the line break/CR after the Main-class: statement, this will not work... in my experience, this is true)
    4) Make sure you save this file in the same directory as your .class file(s).
    5) Type: jar -cmf Whatever.jar main.txt Whatever.class
    ...and that's about it. For more information on the usage of the jar command and to understand the switches (such as -cmf), try jar --help.
    Hope that helps.

  • How can I split a class into 2 files?

    I converted a C++ program to Java recently and it works fine, but I ran into a problem.
    One file is very large and I need to add more functionality. Unlike with C++ where you can just put new functions in another file, I don't see a way to do it in Java.
    I made another file, and therefore another class, but the compiler complains that it can't call a static function from non-static context. (I did not declare it static so I guess it's assuming it) But I understand why. So I made the new class "extend" the old one so "this" would exist but that doesn't work -- Is it because the new class is a subclass of the original class?
    There must be a way to do this. But I don't see what is likely obvious. HELP! And thanks.

    JavaIsBetterThanCPP wrote:
    There must be a way to do this. But I don't see what is likely obvious. HELP! And thanks.Unfortunately Java has no concept of "partial classes" like C# has. Generally, however, a class that is large enough to split up into separate files is either one class that should be modularized further into separate classes, or it already is modularized and all that code is the result of many inner classes. What some people do is promote those inner classes to top-level members in their own file, and mark them as package-private. Using a package you can basically have two classes that know everything about each other and have full access to each other.
    But personally, and until I see justification otherwise, semantics in Java being unbreakingly tied to a certain file structure and naming is the most bonehead and, frankly, non-Java thing about Java.
    There's probably a pre-processor out there that will let you split a class into multiple files and will combine them into a single source file just-in-time to pass to the compiler.

  • Object Creation Of One class into another and vice versa

    Hello Everyone,
    My name is Prashant Sharma from Jaipur [Rajasthan]
    Can u people help me
    How to create of one class into another and vice versa
    Eg,
    I am having class A and class B
    I want to create object of class A into class B and vice versa
    Plz help me out of this problem as soon as possible....

    Read this: [Creating Objects|http://java.sun.com/docs/books/tutorial/java/javaOO/objectcreation.html]
    Then, do one of these three:
    1. Create an instance of the class
    2. Extend the class
    3. Access methods within the class
    Try it out. Post the problem code if you're having trouble.

  • Can't import class into JSP

    Hi,
    I am trying to import a class into my JSP and am getting the following error at runtime:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: -1 in the jsp file: null
    Generated servlet error:
    [javac] Compiling 1 source file
    [javac] D:\jwsdp-1.2\work\Catalina\localhost\pe\org\apache\jsp\guestbook_jsp.java:7: '.' expected
    [javac] import MessageGetter;
    My import statement in the JSP is simply:
    <%@ page import="MessageGetter" %>
    and I am placing the class in the WEB-INF/classes directory. This is stumping me - if you've come across this or a similar problem, please let me know. Thanks.
    P

    Try posting your question in the JSP forum (http://forum.java.sun.com/forum.jsp?forum=45)
    cheers,
    Mike

  • How to restructure this code into separate classes?

    I have C# code that initializes a force feedback joystick and plays an effect file(vibrates the joystick). I have turn the console application into library
    code to make a dll so that I can use it in LabVIEW. 
    Right now all the code is written under one class, so went I put the dll in LabVIEW I can only select that one class. labVIEW guy told me that I need to
    restructure my C# code into separate classes. Each class that I want to access from LabVIEW needs to marked as public. Then I can instantiate that class in LabVIEW using a constructor, and call methods and set properties of that class using invoke nodes and
    property nodes.
    How can I do this correctly? I tried changing some of them into classes but doesn't work. Can you guys take a look at the code to see if it is even possible
    to break the code into separate classes? Also, if it is possible can you guide me, suggest some reading/video, etc.
    Thank you
    using System;
    using System.Drawing;
    using System.Collections;
    using System.Windows.Forms;
    using Microsoft.DirectX.DirectInput;
    namespace JoystickProject
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    private System.Windows.Forms.Label label1;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;
    private Device device = null;
    private bool running = true;
    private ArrayList effectList = new ArrayList();
    private string joyState = "";
    public bool InitializeInput()
    // Create our joystick device
    foreach(DeviceInstance di in Manager.GetDevices(DeviceClass.GameControl,
    EnumDevicesFlags.AttachedOnly | EnumDevicesFlags.ForceFeeback))
    // Pick the first attached joystick we see
    device = new Device(di.InstanceGuid);
    break;
    if (device == null) // We couldn't find a joystick
    return false;
    device.SetDataFormat(DeviceDataFormat.Joystick);
    device.SetCooperativeLevel(this, CooperativeLevelFlags.Exclusive | CooperativeLevelFlags.Background);
    device.Properties.AxisModeAbsolute = true;
    device.Properties.AutoCenter = false;
    device.Acquire();
    // Enumerate any axes
    foreach(DeviceObjectInstance doi in device.Objects)
    if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
    // We found an axis, set the range to a max of 10,000
    device.Properties.SetRange(ParameterHow.ById,
    doi.ObjectId, new InputRange(-5000, 5000));
    // Load our feedback file
    EffectList effects = null;
    effects = device.GetEffects(@"C:\MyEffectFile.ffe",
    FileEffectsFlags.ModifyIfNeeded);
    foreach(FileEffect fe in effects)
    EffectObject myEffect = new EffectObject(fe.EffectGuid, fe.EffectStruct,
    device);
    myEffect.Download();
    effectList.Add(myEffect);
    while(running)
    UpdateInputState();
    Application.DoEvents();
    return true;
    public void PlayEffects()
    // See if our effects are playing.
    foreach(EffectObject myEffect in effectList)
    //if (button0pressed == true)
    //MessageBox.Show("Button Pressed.");
    // myEffect.Start(1, EffectStartFlags.NoDownload);
    if (!myEffect.EffectStatus.Playing)
    // If not, play them
    myEffect.Start(1, EffectStartFlags.NoDownload);
    //button0pressed = true;
    protected override void OnClosed(EventArgs e)
    running = false;
    private void UpdateInputState()
    PlayEffects();
    // Check the joystick state
    JoystickState state = device.CurrentJoystickState;
    device.Poll();
    joyState = "Using JoystickState: \r\n";
    joyState += device.Properties.ProductName;
    joyState += "\n";
    joyState += device.ForceFeedbackState;
    joyState += "\n";
    joyState += state.ToString();
    byte[] buttons = state.GetButtons();
    for(int i = 0; i < buttons.Length; i++)
    joyState += string.Format("Button {0} {1}\r\n", i, buttons[i] != 0 ? "Pressed" : "Not Pressed");
    label1.Text = joyState;
    //if(buttons[0] != 0)
    //button0pressed = true;
    public Form1()
    // Required for Windows Form Designer support
    InitializeComponent();
    // TODO: Add any constructor code after InitializeComponent call
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    if( disposing )
    if (components != null)
    components.Dispose();
    base.Dispose( disposing );
    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    public void InitializeComponent()
    this.label1 = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // label1
    this.label1.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
    this.label1.Location = new System.Drawing.Point(8, 8);
    this.label1.Name = "label1";
    this.label1.Size = new System.Drawing.Size(272, 488);
    this.label1.TabIndex = 0;
    // Form1
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.BackColor = System.Drawing.SystemColors.ControlText;
    this.ClientSize = new System.Drawing.Size(288, 502);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
    this.label1});
    this.Name = "Form1";
    this.Text = "Joystick Stuff";
    this.ResumeLayout(false);
    #endregion
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    using (Form1 frm = new Form1())
    frm.Show();
    if (!frm.InitializeInput())
    MessageBox.Show("Couldn't find a joystick.");

    Imho he means the following.
    Your class has performs two tasks:
    Controlling the joystick.
    Managing the joystick with a form.
    So I would recommend, that you separate the WinForm from the joystick code. E.g.
    namespace JoystickCtlLib
    public class JoystickControl
    private Device device = null;
    private bool running = true;
    private ArrayList effectList = new ArrayList();
    private string joyState = "";
    public string State { get { return this.joyState; } }
    public bool InitializeInput() { return true; }
    public void PlayEffects() { }
    private void UpdateInputState() { }
    So that your joystick class does not reference or uses any winform or button.
    btw, there is a thing which is more important than that: Your polling the device in the main thread of your application. This will block your main application. Imho this should be a job for a thread like background worker.

Maybe you are looking for

  • Calling infotype 0002 in ALV  report for showing employee photo

    Hi all, The requirment from business side is a report in which employees personal data shuold be shown with employee photo, I had tried for employee photo in ALV report but it didnt sucessed, then I went for other solution like calling transaction in

  • Photos washed out in Lightroom

    Hi - I relatively new to color management and am struggling with Lightroom. I'm shooting raw images on a 40D and bringing them into lightroom converting to DNG. I've recently upgraded my computer and am running Vista. I've calibrated my monitor with

  • I bought the recent season of the bachelorette and the 4th episode is not downloading

    I bought the most recent season of the bachelorette and the 4th epesode is not downloading.  HELP

  • How to create file based on date value

    Hi Hope you'll help me. I can't find right way to tackle the problem. I need to read a file which name is created based on month and years' value. File name format is as follows: INMMYY.log. So to read it I must create File object using this file nam

  • Trouble with Complex Object example

    From the 3.5 Tutorial. I have all of the .xml files in d:\oracle\home\labs, the .cmd file to start the cache using the POF is in the same directory. When I run the .cmd file, I get an Illegal State Exception: Missing POF configuration The POF configu