Computer Science 209 Software Development Packages What Is
- Slides: 14
Computer Science 209 Software Development Packages
What Is a Package? • A package organizes related resources (interfaces and classes) into a conceptual unit • Like a module in other languages • Examples: – – java. lang (basic Java resources, no need to import) java. util (scanners, collections, arrays, random numbers) java. io (I/O, file processing) javax. swing, java. awt (GUIs)
Using a Package: Typical Imports import java. util. Scanner; import java. util. Arrays; public class Circle. Area{ public static void main(String[] args){ int[] numbers = new int[3]; Scanner input = new Scanner(System. in); for (int i = 0; i < numbers. length; i++) numbers[i] = input. next. Int(); Arrays. sort(numbers); for (int n : numbers) System. out. println(n); } } Bring in specific classes only
Using a Package: Fully Qualified Imports import java. util. Scanner; import static java. util. Arrays. sort; public class Circle. Area{ public static void main(String[] args){ int[] numbers = new int[3]; Scanner input = new Scanner(System. in); for (int i = 0; i < numbers. length; i++) numbers[i] = input. next. Int(); sort(numbers); for (int n : numbers) System. out. println(n); } } Bring in specific classes and static methods only
Using a Package: The Wildcard Gets All import java. util. *; public class Circle. Area{ public static void main(String[] args){ int[] numbers = new int[3]; Scanner input = new Scanner(System. in); for (int i = 0; i < numbers. length; i++) numbers[i] = input. next. Int(); Arrays. sort(numbers); for (int n : numbers) System. out. println(n); } } Bring in all classes with wildcard
Using a Package: No Imports Needed public class Circle. Area{ public static void main(String[] args){ int[] numbers = new int[3]; java. util. Scanner input = new java. util. Scanner(System. in); for (int i = 0; i < numbers. length; i++) numbers[i] = input. next. Int(); java. util. Arrays. sort(numbers); for (int n : numbers) System. out. println(n); } } Use fully qualified names with no imports
Packages and Files • In Python, a module is typically a single file, which may define several related classes • In Java, a package is a directory, which may include several related classes in source code files and byte code files
File Organization within a Package • Source files for classes should be in a directory whose name is the package name • When byte code is generated, it is placed in a directory with the package’s name • These directories should be just below the directories of the source or byte code files that use them
Example: The Student Class studentexample Student. Tester. java Student. Tester. class student Student. java Student. class
Defining a Package Define package student; public class Student{ // Blah blah } Use import student. Student; public class Student. Tester{ // Blah blah }
Creating a Package from the Terminal • Place the. java files in a directory whose name is the package name • Attach to this directory and run javac *. java • Place the package directory in the directory where your client program will be • Run javac or java from this client program’s directory as needed
All Classes in One Package student Student. Tester. java Student. Tester. class Student. java Student. class
Defining a Package Define package student; public class Student{ // Blah blah } Use package student; public class Student. Tester{ // Blah blah }
Compile and Run > cd student > javac *. java > java student. Student. Tester Need qualified name to locate main class within package
- Wordle 209
- 735 ilcs 5/13-209
- Lesson 2 add integers page 209 answers
- Ece 209
- El participio presente p 209
- 2 half lives
- Ece 209
- Gis software packages
- Unlike application software programs
- Why science is my favourite subject
- Software engineer vs software developer
- Computer science software engineering
- Computer science software engineering
- Computer-aided software engineering
- Mi plan latino double play