Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [Tip] Packages
Index -> Programming, Java -> Java Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sat May 27, 2006 5:20 pm   Post subject: [Tip] Packages

Learn to use packages well, and learn it early in your Java education.
Sponsor
Sponsor
Sponsor
sponsor
cool dude




PostPosted: Sat May 27, 2006 5:24 pm   Post subject: (No subject)

by packages do u mean the different things you can import i.e.
code:

import java.io.*;


i think there are a lot of those where can i find some of them? any links?
wtd




PostPosted: Sat May 27, 2006 5:28 pm   Post subject: (No subject)

http://java.sun.com.

Look at the API references.

You should also know how to create your own packages.
cool dude




PostPosted: Sat May 27, 2006 5:45 pm   Post subject: (No subject)

1) how do u create packages?

2)there are quite a lot of packages there! what are usually the main ones people use?
MysticVegeta




PostPosted: Mon May 29, 2006 1:30 pm   Post subject: (No subject)

cool dude wrote:
by packages do u mean the different things you can import i.e.
code:

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:

Quote:
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

code:
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




PostPosted: Mon May 29, 2006 4:29 pm   Post subject: (No subject)

wat difference would it make if i just import the whole package?
wtd




PostPosted: Mon May 29, 2006 4:42 pm   Post subject: (No subject)

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




PostPosted: Mon May 29, 2006 7:59 pm   Post subject: (No subject)

MysticVegeta wrote:


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

Java:
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.
Java:
import java.io.Reader;
Here we import the Reader class from the java.io package.
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Mon May 29, 2006 8:16 pm   Post subject: (No subject)

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.
Display posts from previous:   
   Index -> Programming, Java -> Java Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: