Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

how can divide my single programs in multifiles

jargonjargon Posts: 1Member
I want to know that in java how can we divide our program among multifiles and then execute it.

for eg:
I made a new directory and inside that created these

//hello.java
class hello
{
public prnthello()
{
System.out.println("hello");
}
}
//hel.java
class hel
{
public static void main(String args[])
{
hello h=new hello();
h.prnthello();
}
}

then on command prompt i did:
c:/>javac hello.java hel.java
c:/>java hel.java
it compiled successfully but gave the following runtime errors
D:PROGRA~1JAVA_P~1 rial>java hel.java
Exception in thread "main" java.lang.NoClassDefFoundError: hel/java
Caused by: java.lang.ClassNotFoundException: hel.java
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: hel.java. Program will exit.

can anyone plz tell me the correct method to this

Comments

Sign In or Register to comment.