"자바 패키지 컴파일 및 실행"의 두 판 사이의 차이

(새 문서: ==개요== ;자바 패키지 컴파일 및 실행 {{소스헤더|animal/Dog.java}} <syntaxhighlight lang='php'> package animal; public class Dog { public void bark() { System.out....)
 
34번째 줄: 34번째 줄:
<syntaxhighlight lang='console'>
<syntaxhighlight lang='console'>
testuser@localhost:~/project1$ javac -d . mypackage/MyClass.java
testuser@localhost:~/project1$ javac -d . mypackage/MyClass.java
testuser@localhost:~/project1$ find
.
./mypackage
./mypackage/MyClass.java
./mypackage/MyClass.class
./animal
./animal/Dog.class
./animal/Dog.java
</syntaxhighlight>
<syntaxhighlight lang='console'>
testuser@localhost:~/project1$ java mypackage.MyClass
testuser@localhost:~/project1$ java mypackage.MyClass
Woof!
Woof!
</syntaxhighlight>
<syntaxhighlight lang='console'>
testuser@localhost:~/project1$ java mypackage/MyClass
testuser@localhost:~/project1$ java mypackage/MyClass
Woof!
Woof!
</syntaxhighlight>
</syntaxhighlight>

2021년 10월 7일 (목) 19:50 판

개요

자바 패키지 컴파일 및 실행
animal/Dog.java
PHP
Copy
package animal;
public class Dog {
	public void bark() {
		System.out.println("Woof!");
	}
}
mypackage/MyClass.java
PHP
Copy
package mypackage;
import animal.*;
public class MyClass {
	public static void main(String args[]) {
		Dog mydog = new Dog();
		mydog.bark();
	}
}
Console
Copy
testuser@localhost:~/project1$ find
.
./mypackage
./mypackage/MyClass.java
./animal
./animal/Dog.java
Console
Copy
testuser@localhost:~/project1$ javac -d . mypackage/MyClass.java
testuser@localhost:~/project1$ find
.
./mypackage
./mypackage/MyClass.java
./mypackage/MyClass.class
./animal
./animal/Dog.class
./animal/Dog.java
Console
Copy
testuser@localhost:~/project1$ java mypackage.MyClass
Woof!
Console
Copy
testuser@localhost:~/project1$ java mypackage/MyClass
Woof!