Executing java inside java example program

Executing java inside java:

MyJava.java

[java]
class MyJava{

public static void main(String[] args){
Javadomain jd = new Javadomain();
jd.main(null);
}

}
[/java]

Now we are going to execute this below java program(Javadomain.java) inside the above the java program(MyJava.java),

Javadomain.java:

[java]
class Javadomain{
public static void main(String[] args){
System.out.println("I am executed successfully, Java inside java success");
}
}
[/java]

Output:

[plain]
I am executed successfully, Java inside java success
[/plain]

Note:
Ensure you have both the above java programs in the same path.

Leave a Reply