Results 1 to 6 of 6

Thread: [RESOLVED]Combining

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Resolved [RESOLVED]Combining

    i have two java program. lets call them javaA and javaB both are .java files. how do i import javaA into javaB.

    ps
    incase some people start saying i dont understand. for the sake of this lets say javaA just take the input and doubles and returns the value. now how can i use javaA in javaB
    Last edited by Ebiru; Oct 6th, 2008 at 12:39 PM.

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Combining

    put a simple "import javaA;" at the beginning of class javaB, this will do the trick, but in case javaA is in a different folder you need to add it's path (the path of the compiled .class file) to the class-path parameter when compiling javaB
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: Combining

    Quote Originally Posted by ComputerJy
    put a simple "import javaA;" at the beginning of class javaB, this will do the trick, but in case javaA is in a different folder you need to add it's path (the path of the compiled .class file) to the class-path parameter when compiling javaB
    atm i cant compile but i have a few questions
    1) w/ or w/o the ""
    2) i think i try that before but get the error "." is missing and its in the same folder
    Last edited by Ebiru; Oct 3rd, 2008 at 06:16 AM.

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Combining

    without the quotes.

    If so, there is no reason to be getting errors, just make sure javaA is compiled before javaB
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: Combining

    Quote Originally Posted by ComputerJy
    without the quotes.

    If so, there is no reason to be getting errors, just make sure javaA is compiled before javaB
    i get the fellowing
    .java:3: '.' expected
    import javaB;

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Combining

    class javaA.java:
    Code:
    public class javaA
    {
    	public static void main(String[] args)
    	{
    		javaB b = new javaB();
    		System.out.println(b.add(2, 5));
    	}
    }
    class javaB.java
    Code:
    public class javaB
    {
    	public int add(int a, int b)
    	{
    		return a + b;
    	}
    
    }
    See, an import statement is not needed if both classes are in the same package which seems to be the case here.. Sorry if I wasn't clear :P
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width