• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

need help to understand packages

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 80212
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it and see what happens
 
Serap Elbeyoglu
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80212
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Ranch Hand
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 80212
423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oposs.............many many apologies...............
now onward i will not type my mail address over there.............

 
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic