Presentation is loading. Please wait.

Presentation is loading. Please wait.

Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and.

Similar presentations


Presentation on theme: "Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and."— Presentation transcript:

1 Packages

2 Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and in the package protected keyword Package (“Friendly”) Available in the package only No access specifier Private Available in class only (private keyword) Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and in the package protected keyword Package (“Friendly”) Available in the package only No access specifier Private Available in class only (private keyword)

3 What’s a Package? A set of classes (.class files) in the same directory Similar to C++ namespaces Don’t have to use import A “substitute” for friend in C++ The directory must match the package name Can have multiple segments (dot-separated) java.util corresponds (loosely) to the subdirectory java/util Use the package keyword Must be first non-comment line of file A set of classes (.class files) in the same directory Similar to C++ namespaces Don’t have to use import A “substitute” for friend in C++ The directory must match the package name Can have multiple segments (dot-separated) java.util corresponds (loosely) to the subdirectory java/util Use the package keyword Must be first non-comment line of file

4 The Class Path A search path Consists of directories or JAR files All package directories must be subdirectories of a directory in the class path -classpath option CLASSPATH environment variable A search path Consists of directories or JAR files All package directories must be subdirectories of a directory in the class path -classpath option CLASSPATH environment variable

5 The Unnamed Package The “default” package All classes not in a named package are in this package Can span multiple directories Uses the classpath The “default” package All classes not in a named package are in this package Can span multiple directories Uses the classpath

6 JAR Files “Java Archive” A way of collecting/compressing.class files For faster loading of applets And for distributing pre-compiled software Can run from command-line with the “java” command java –jar MyJar.jar “Java Archive” A way of collecting/compressing.class files For faster loading of applets And for distributing pre-compiled software Can run from command-line with the “java” command java –jar MyJar.jar


Download ppt "Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and."

Similar presentations


Ads by Google