Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java Notes

Directories and Files

[an error occurred while processing this directive]

Put all source files into a directory, one class per file

When you start a new project, create a new directory for the source files. The directory name should be lowercase letters, with no blanks or other punctuation. The directory is used as the package.

Each class should be defined in its own .java file

Put each of your classes in its own file. It's easy to do. Here are a couple of minor rules.

  • Make sure all classes (.java files) are in the same directory (folder).
  • You need separate import statements for each class.
  • You may have to compile a class that is referenced before the class that uses it. Whether you have to do this or not depends on which devopment system you're using.
  • When you run the program, you may have to have the class that contains main(. . .) be visible in your development system (depends on the development system.

There are some exceptions (inner classes), but this is the general rule that applies to almost all Java programming.

It's possible to put more than one class in a file and have everything work. I did this for a long time for small programs, but have given it up because it doesn't scale up as you create larger programs and use more better development tools. A common development tool, Ant, works best when each class is in its own source file.

Packages

Multiple classes of larger programs are usually grouped together into packages. See Packages - Defining for how and why to use packages.

Ask programming questions?

 

 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name

 

 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.

[an error occurred while processing this directive]