
-----------------------------------
wtd
Sat May 27, 2006 5:20 pm

[Tip] Packages
-----------------------------------
Learn to use packages well, and learn it early in your Java education.

-----------------------------------
cool dude
Sat May 27, 2006 5:24 pm


-----------------------------------
by packages do u mean the different things you can import i.e. 

import java.io.*;

i think there are a lot of those where can i find some of them? any links?

-----------------------------------
wtd
Sat May 27, 2006 5:28 pm


-----------------------------------
http://java.sun.com.  

Look at the API references.

You should also know how to create your own packages.

-----------------------------------
cool dude
Sat May 27, 2006 5:45 pm


-----------------------------------
1) how do u create packages?

2)there are quite a lot of packages there! what are usually the main ones people use?

-----------------------------------
MysticVegeta
Mon May 29, 2006 1:30 pm


-----------------------------------
by packages do u mean the different things you can import i.e. 

import java.io.*;

i think there are a lot of those where can i find some of them? any links?

Packages are actually bundles of classes, so if you import an entire package, you can use any class inside of that package but if you just want to use 1 or more specific classses from a package, then people usually import those classes specifically and not th eentire package... eg:

if you import java.io package, you import classes:

BufferedInputStream 
BufferedOutputStream 
BufferedReader 
BufferedWriter 
ByteArrayInputStream 
ByteArrayOutputStream 
CharArrayReader 
CharArrayWriter 
DataInputStream 
DataOutputStream 
File 
FileDescriptor 
FileInputStream 
FileOutputStream 
FileReader 
FileWriter 
FilterInputStream 
FilterOutputStream 
FilterReader 
FilterWriter 
InputStream 
InputStreamReader 
LineNumberInputStream 
LineNumberReader 
ObjectInputStream 
ObjectOutputStream 
ObjectStreamClass 
OutputStream 
OutputStreamWriter 
PipedInputStream 
PipedOutputStream 
PipedReader 
PipedWriter 
PrintStream 
PrintWriter 
PushbackInputStream 
PushbackReader 
RandomAccessFile 
Reader 
SequenceInputStream 
StreamTokenizer 
StringBufferInputStream 
StringReader 
StringWriter 
Writer 


if you just need 1 of the class say, BufferedInputStream and not hte entire package, then you would go

import java.io.BufferedInputStream;

I may not be the best explainer because I am pretty new to java myself, hopefully wtd will correct me anywhere I made a mistake...

-----------------------------------
cool dude
Mon May 29, 2006 4:29 pm


-----------------------------------
wat difference would it make if i just import the whole package?

-----------------------------------
wtd
Mon May 29, 2006 4:42 pm


-----------------------------------
Well, let's say you have package foo with class Bar, and package baz with classes Bar, Ninja and Wooble.  What happens if you import all of both packages, then try to use the Bar class from package foo?

-----------------------------------
rizzix
Mon May 29, 2006 7:59 pm


-----------------------------------


Packages are actually bundles of classes, so if you import an entire package, you can use any class inside of that package but if you just want to use 1 or more specific classses from a package, then people usually import those classes specifically and not th eentire package... eg:
(A common mistake, but it needs to be corrected. Java's import (packages) does not behave like C++'s using (namespaces), although they both finally bring a "name" into scope.)

You Do Not (and Can Not) import packages in Java. You can only import classes

import java.io.*; Read: "Import all classes in the java.io package". 
The asterisk (*) represents all classes. If you wish you may import just one particular class from a package.
import java.io.Reader;Here we import the Reader class from the java.io package.

-----------------------------------
rizzix
Mon May 29, 2006 8:16 pm


-----------------------------------
Another tip: Following the java naming conventions, all package names should be in lowercase, while Class names should be in word case.
(note: package names are not wordcase)

As a general rule: avoid underscores.

Method and variable names on the other hand are also word case, but they should begin with a lowercase letter.
