Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Aphorismen
Applications
Business Economics & Admin.
My Computers
Cooking
Devices
Folders
Food
Hardware
Infos
Software Development
Sports
Operation Instructions
Todos
Test
Help
Glossary
Community portal
adaptions
Sidebar anpassen
Wiki RB4
Search
Search
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
JavaLanguage
(section)
Page
Discussion
English
Read
Edit
View history
Toolbox
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Packages and Imports== Java allows you to group classes in a collection called package. Just as you have nested subdirectories on your disk, you can organize packages using levels of nesting. To add a file to a package insert the line '''package''' <PackageName>; to your file. It must be the first line after any comment. Java code that is part of a package has access to all classes (public and non-public) in the package and to all non-private methods and fields in all those classes. Everything in the java.lang package is automatically imported into every Java program. There you do not need to specify a package prefix in front of e.g. the system object. The java.lang packages contains the following parts: Math ... You can import special classes of a package or all classes of a package (s. example (x)), e.g.: '''import''' ['''static'''] <Part1>.<PartN>.('''*'''|<ClassName>)''';''' import java.applet.Applet; import java.awt.*; // * is only allowed for a single package Importing all classes in a package is simpler. It has no negative effect on compile time or code size, so there is generally no reason not to do it. Wenn es zwei packages gibt, die eine Klasse mit dem gleichen Namen enthalten, können nicht beide importiert werden, sondern eine muss über den voll qualifizierten Namen verwendet werden. Wenn die Klasse die importiert wurde nicht als *.class file vorliegt, wird sie implizit durch das import statement übersetzt. Kann sie z.B. wegen Syntaxfehlern nicht übersetzt werden, wird auch die importierende Datei nicht übersetzt. All files of a package must be located in a subdirectory that matches the full package name. These subdirectories need not branch off from the root directory; they can branch from any directory in the CLASSPATH environment variable. JVM looks for <CLASSPATH>\<PACKAGENAME_PART1>\..\<PACKAGENAME_PARTN>\<CLASSNAME>.CLASS. The files can also be located in a CLASSES.ZIP file with the correct path information. If no package statement is specified the class is thrown into a default package with all other package-less classes and all the non-private members are visible there. In 1.4 you can no longer import a class from the default package. You can only import a class that is in a named package. If your classes are in the default package, you do not need to use the import statement. Otherwise, you will need to package the classes or only use the default package.
Summary:
Please note that all contributions to Wiki RB4 may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Uwe Heuer Wiki New:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width