Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need help to understand packages

 
rajesh baba
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what a package should contain .java file or a .class file .i hope its a .class file but in jdk 1.4 i see that i had .java files in java package that we use to import various other packages like (example:import java.math.* this folder or package consists of .java files why can any one explain?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take the time to choose the correct forum for your posts. The banner on this forum states;
This forum is intended for questions and comments about this web site, www.javaranch.com.
It is not for questions about the Java language - that's what all our other forums are for.


This post has been moved to a more appropriate forum.
 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Packages are used to organize your Java programs.

Putting your .java source-code files into a package is not required, but it is highly recommended. Even if you are just learning Java, you should get into the habit of having a package declaration at the beginning of each .java file.



This example is trivial and doesn't really need the package declaration because there isn't much to organize, but it's recommended by Java experts that you get into the habit of using package declarations as early as you can.

Notice that I didn't have an "import" statement. This is because the package: "java.lang" is imported automatically.

In the example above, the class file must be named HelloWorld.java (this filename is case-sensitive).

Because of the package declaration, my .java file will be stored within a hierarchy of directories:

./src/com/kaydell/test/HelloWorld.java

Having a hierarchy here is over-kill, but it is essential in larger programs where you have a .java file for every public class and for every public inerface.

After compiling the .java file, a .class file is created. This can go different places depending upon the options that you specify. It can go into the same directory as the .java source-code, or it might go into another directory such as:

./bin/com/kaydell/test/HelloWorld.class

Hope that helps.

Kaydell
[ May 25, 2007: Message edited by: Kaydell Leavitt ]
 
Serap Elbeyoglu
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all of you,

What is the logic behind of "import" word? If I don't use import javax.swing.JButton, while creating a button, what will happen?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try it and see what happens
 
Serap Elbeyoglu
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell,

In fact, I want to learn the logic of package names and using import keyword. Who wants to answer?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Try it and see what happens
There's an answer. What happened when you tried?

You might find something in the Java™ Tutorials, here, or here (try the "using package members" link).
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the logic behind of "import" word?
If I don't use import javax.swing.JButton, while creating a button, what will happen?

import tells the compiler where to look for class files..........................\
so .......javax.swing.JButton......means.......

javax is a name of package and in that package look for swing class and in swing class look for Jbutton

if you remove import javax.swing.JButton,............then there is compiler error..........
because compiler is not able to find where to look for Button specific method..

compiler doesnot understand addButton() etc methods...............

replace javax.swing.JButton with.......javax.swing.*;
will work........becouse this will load the functionality of all my class..............
anything else...........ask me on *****@*****l.com
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did it say in those Java™ Tutorials links I gave you? What did you understand and not understand of it?

Don't ask people to e-mail you; I have deleted your address.
 
Shanky Sohar
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oposs.............many many apologies...............
now onward i will not type my mail address over there.............

 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic