Welcome to Dream.In.Code
Getting Java Help is Easy!

Join 132,692 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,311 people online right now. Registration is fast and FREE... Join Now!




tips on how to write a class

 
Reply to this topicStart new topic

tips on how to write a class

Mojalefa
post 4 Sep, 2008 - 05:08 AM
Post #1


New D.I.C Head

*
Joined: 4 Sep, 2008
Posts: 1

Good day i am a new in programming world and would like to persue a caree in this category. please assist me in writing a class and its tester, methods, objects, objects references, variables( instabt, local and perimeter), arrays and implementation of all these. I have an idea on how all these are but they are all in a puzzle form. Please refer me to a book that is much more simple to understand. please help out because i really have a strong passion for it, the lectures just bomberd us with lots of work at the same time and make very complicated to interprete1

yours trully
M.J.Lebea
User is offlineProfile CardPM

Go to the top of the page

BetaWar
post 4 Sep, 2008 - 09:37 AM
Post #2


#include <soul.h>

Group Icon
Joined: 7 Sep, 2006
Posts: 1,987



Thanked 78 times

Dream Kudos: 1175
My Contributions


Classes can be created in a few differet ways.

First, you can create them in their own file where the filename is the same as the class name (without the .java).

Second, you create a primary class (which follows the rules above) and then you add a subclass to the class. This doesn't require additional files but is "bad practice".

If you want to post some code I will help you out further.
User is offlineProfile CardPM

Go to the top of the page

abgorn
post 4 Sep, 2008 - 11:25 AM
Post #3


Hello Crap for Brains

Group Icon
Joined: 5 Jun, 2008
Posts: 866



Thanked 4 times

Dream Kudos: 25
My Contributions


One of the easiest ways to make your code more easy to use is to label it with "//". Though if you do it too much, your code will become cluttered and that would just defeat the purpose of it.
User is online!Profile CardPM

Go to the top of the page

pbl
post 4 Sep, 2008 - 02:10 PM
Post #4


D.I.C Lover

Group Icon
Joined: 6 Mar, 2008
Posts: 2,982



Thanked 190 times

Dream Kudos: 75
My Contributions


QUOTE(BetaWar @ 4 Sep, 2008 - 10:37 AM) *

Second, you create a primary class (which follows the rules above) and then you add a subclass to the class. This doesn't require additional files but is "bad practice".


Why would it be a "bad practice" ?

If the second class will only be referenced by its father (classes that implement ActionListener are a good example) there is no need to put them in a separate file. And when you read back your code (or somebody else code) you know that this class is not referenced by anybodey else.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:43AM

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month