Java classpath usage

Posted on 20 Kasım 2016 in Programlama by

We will create following classes:
firstClass
\___ abc.java
secondClass
\___ xyz.java

Create a class with package name as p1.p2.p3 at firstClass directory

package p1.p2.p3;
public class abc {
    public void printName(String name) {
        System.out.println("your name is "+name);
    }
}

and compile it using following command:
javac abc.java -d .

lets add another class that uses abc class at secondClass directory

public class xyz extends p1.p2.p3.abc{
    public static void main(String prm[]) {
        System.out.println("xyz class");
        tt deneme = new tt();
        deneme.printName("Trump");
    }
}

and following command is used to compile it:
javac -classpath ../firstClass/ xyz.java

To execute compiled binary use following command:
java -cp .:../firstClass xyz

Please give us your valuable comment

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image