×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    [moved] j2me linking of class files

    I know j2me.. I can make apps in j2me.. I use a certain of class linking.. But i want to know is there any other way of linking classes in j2me... The way i use is somewhat like this.. a of b are two class files here..
    a.java:
    .
    public class a
    {
    b bb;
    public a()
    {
    bb = new b(this);
    }
    public void doSomething()
    {
    // its a method of class a
    }
    }
    .
    b.class:
    .
    public class b
    {
    a aa;
    public b(a aa)
    {
    this.aa = aa;
    }
    public void doneSomething() //method of class b
    {
    aa.doSomething(); //calling method of a.class into b.class
    }
    }
    .
    Please reply..

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: [moved] j2me linking of class files

    In Java, there is no statical linking of code. When running a multi-class application, you simply have all the required .class files available, and that is all.
    For keeping things easier to manage, the .jar (Java ARchive) files are used, which are actuall .zip files containing .class files and some optional descriptor files.

    Even if you use inner classes (class defined inside an other class, in a single .java file), the inner classes will become separate .class files after compilation.

  3. #3
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: [moved] j2me linking of class files

    But then if my class a has a method name doSomething if i want to use the same method in any other class file then what will i do.. Then only way then is by joining the two class files.. The one way i used i had shown it above but if there is any other way then tell me please..

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,572

    Re: [moved] j2me linking of class files

    Sorry, I probably misunderstood the original question (the word 'linking' has an other, well defined meaning in many other programming languages, like C, C++, assembly).

    The way you show in the code is absolutely normal, in Java objects use each other via having references to the other object(s).

    On the class level you can also operate with static methods
    Code:
    public class ClassA
    {
        public static void doSomething() {...}
    }
    
    public class ClassB
    {
        public void someMethod()
        {
            ClassA.doSomething();
        }
    }
    here ClassA.doSomething always exists, so it can be used without creating an object with "new ClassA()". Utility classes often use this approach, check for example the Math class. In desktop Java an other example is the 'main' method which starts the application.

    And also on class level you can think about inheritance
    Code:
    public class ClassA
    {
        public void doSomething() {...}
    }
    
    public class ClassB extends ClassA
    {
        public void someMethod()
        {
            doSomething();
        }
    }
    this is how you create a Midlet for example, you extend the Midlet class, and use its methods when necessary.
    Note that these topics are far better and deeper explained in various Java tutorials which you can find on the Internet.

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Thumbs up Re: [moved] j2me linking of class files

    Thank you sir.. It worked like a charm..

  6. #6
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: [moved] j2me linking of class files

    Sir a last question which i have is that how to make inheritance between two class files one inside a package and one outside.. For example class a is inside a package named nokia and b is outside the package.. Then how will i join them..

  7. #7
    Regular Contributor
    Join Date
    Dec 2012
    Location
    Indonesia,DKI Jakarta
    Posts
    87

    Re: [moved] j2me linking of class files

    Quote Originally Posted by subha095 View Post
    Sir a last question which i have is that how to make inheritance between two class files one inside a package and one outside.. For example class a is inside a package named nokia and b is outside the package.. Then how will i join them..
    It does not matter if the b outside the package just extends b and import b. Make method in b class as public. Don't use protected keyword it just can access on the same package.

  8. #8
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Re: [moved] j2me linking of class files

    Sir i have a problem in your joining of class files.. If i join by the way you told:
    i) then every variable should be static which is not possible..
    II) I have create an instance of the variables in every method of the class where it is needed.. It is very time consuming and a lengthy method.. For example i have Form f;
    Then wherever i use this variable i have to create and instance of it.. And if i create an instance of it in the constructor the midlet compiles but it shows "midlet running nothing to display" when i open the midlet.
    .
    Please help me to tackle these situations

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: [moved] j2me linking of class files

    ok wild guess are you calling the show method on your form ??

    Form f = new Form();
    f.show() ;

    If you are not calling then the midlet is running blah blah message comes !!

  10. #10
    Registered User
    Join Date
    Aug 2013
    Posts
    37

    Thumbs up Re: [moved] j2me linking of class files

    Thanks a lot friends i have solved my problem.. Thanks for your valuable time in replying to my thread and helping me....

  11. #11
    Nokia Developer Champion
    Join Date
    Mar 2003
    Posts
    4,105

    Re: [moved] j2me linking of class files

    Quote Originally Posted by subha095 View Post
    I know j2me. I can make apps in j2me
    And if you have a bit of spare time, I recommend to go through the Java Tutorial.

Similar Threads

  1. [moved] NFC linking problem with Nfc reader
    By vineethbabutech in forum Near Field Communication
    Replies: 2
    Last Post: 2013-01-10, 07:23
  2. LINKING OF 2 MIDLET FILES
    By Jibrael in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2010-03-24, 14:29
  3. Problem with linking implrment dialog class
    By TheChups in forum Symbian
    Replies: 6
    Last Post: 2007-03-17, 18:20
  4. problem linking more than 23 C++ files
    By Corfa in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 4
    Last Post: 2005-09-16, 14:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •