Hi,
I have executed the sample package program and it executes fine in some conditions.I have a doubt in my program .
My directory structure is:/javaprograms/world/HelloWorld.java
A folder name :world
A java filename:HelloWorld.java
package world;
import java.io.*;
import java.util.*;
public class HelloWorld{
public static void main(String args[])throws IOException{
System.out.println("Package Program With Example");
}
public static String show(){
return "Hai how are you";
}
}
This program is executed fine.
In javaprograms folder
A filenamed :ex_Hello
Importing package world and use in the program .It also executes fine.
Because the world folder is inside the javaprograms folder.
import java.io.*;
import world.*;
class ex_Hello
{
public static void main(String args[])throws IOException{
String output;
System.out.println("Import packages from the source folder world");
output=HelloWorld.show();
System.out.println("The output of the program is "+output);
}
}
-------------------------------------------------------------------------------
My doubt is when i keep the program ex_Hello.java outside the javaprogram folder and it doesnot work.Eventhough i hava specified the javaprogram folder in the import.
Forex:
import java.io.*;
import javaprograms.world.*;
class ex_Hello
{
public static void main(String args[])throws IOException{
String output;
System.out.println("Import packages from the source folder world");
output=HelloWorld.show();
System.out.println("The output of the program is "+output);
}
}
It displays the error like:
ex_Hello.java:9: cannot access HelloWorld
bad class file: ./HelloWorld.java
file does not contain class HelloWorld
Please remove or make sure it appears in the correct subdirectory of the classpath.
output=HelloWorld.show();
Can anyone say why this error appearing ?
Thank you,
With Regards,
Prem