PDA

Click to See Complete Forum and Search --> : [RESOLVED]Combining


Ebiru
Oct 2nd, 2008, 07:51 PM
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

ComputerJy
Oct 2nd, 2008, 08:40 PM
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

Ebiru
Oct 3rd, 2008, 06:13 AM
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

ComputerJy
Oct 3rd, 2008, 09:04 AM
without the quotes.

If so, there is no reason to be getting errors, just make sure javaA is compiled before javaB

Ebiru
Oct 3rd, 2008, 09:15 AM
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;

ComputerJy
Oct 3rd, 2008, 09:43 AM
class javaA.java:
public class javaA
{
public static void main(String[] args)
{
javaB b = new javaB();
System.out.println(b.add(2, 5));
}
}

class javaB.javapublic 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