[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Class design
If you do not declare the classes as 'public' they are only visible within the package. To make them public you would say:
public final class PortEntry {...}
-----Original Message-----
From: cfowler [mailto:cfowler@outpostsentinel.com]
Sent: Tuesday, October 08, 2002 2:41 PM
To: Ed Jenkins
Cc: ajug-members@ajug.org
Subject: Re: Class design
Ed,
Maybe you can help me with this part.
I have 28 classes in one java file called ConfigDataTypes.java
The look like this
final class PortEntry{
}
final class UserEntry {
}
Thes are basically our representation of C structures that I use on the
embedded device. However java doc complains there are no public classes
in this file. Is this the correct way to do this? I want the classes
to be available to anyone who needs them but not changeable.
Thanks,
Chris
On Tue, 2002-10-08 at 13:44, Ed Jenkins wrote:
> I used to optimized my fields like that too, when I moved from C++ to Java.
> But I think the Java compiler is not bound to creating variables in the same
> order as specified. The compiler might rearrange and optimize them for you.
> And if you have more object references than primitive data types, then it
> really doesn't matter.
>
> I wouldn't worry too much about it, but here's something you might try.
> Order them one way and compile it. Note the file size of the compiled
> .class file. Change the order and compile again. Compare sizes. See if
> anything changed in the physical layout of the class file. This is not a
> very useful trick, though, as the runtime implementation of the class will
> differ from the class file representation, but you can try it and see what
> happens. You can find out what an object looks in memory by using a
> debugger or by writing some reflection code, but it's still just a general
> idea; I don't thing it is required to be accurate in regard to field order.
> The real thing is a black box full of magic and you're not supposed to worry
> about it. A good profiler might be able to point out holes in memory
> allocation, but I don't know for sure.
>
> When in doubt, download the source code for the JDK and look at the compiler
> and the classloader and see how they work. Another excellent resource is
> the book "Java Virtual Machine".
>
> Ed
>
> ---
>
> From: cfowler <cfowler@outpostsentinel.com>
> To: ajug-members@ajug.org
> Subject: Class design
> Date: 08 Oct 2002 10:05:09 -0400
>
> I'm creating classes for each of my structure types in my C program that
> will provide XML to the main program. I want to make sure that I'm on
> the right track. I want to keep these classes as small and tight as
> possible because it is possible for a 32 port device to have 32
> PortEntry objects. If I have 100 x 32port devices then I will have 3200
> PortEntry objects accessible within one Java program. Any suggestions
> would be appreciated. I could expand the class to have methods of get
> and set for each variable but then that would not be wise with memory
> usage in large number of objects.
>
>
>
> final class PortEntry {
>
> public int number; // Port Number
> public String name; // Port Name
> public int speed; // Port speed
> public boolean modem; // Modem enabled or disabled
> public boolean bsIsDel; // Is Backspace Del?
> public int trigger; // Trigger record number
> public int initrString; // Modem Init String
> public int flow; // Flow Control Settings
>
>
> /**
> * Function is an empty constructor
> * That initializes the object
> */
> public PortEntry() {
>
> // Init numbers
> flow = initrString = trigger = speed = number = 0;
>
> // Init boolean values
> modem = bsIsDel = false;
>
> // Init Strings
> name = "";
> }
>
> /**
> * Function will display the port number in the
> * representation of a string
> *
> * @return String Port number in representatin of string
> */
> public String toString() {
>
> // If number is 0 then this
> // class has not been populated
> // return a null
> if(number == 0)
> return null;
>
> return "" + number;
> }
>
> /**
> * Function will return the string representation of
> * the current flow settings
> *
> * @return String String representation of flow
> */
> public String getFlow() {
>
> switch(flow) {
> case 1: return "software";
> case 2: return "hardware";
> case 3: return "none";
> default: return null;
> }
> }
>
>
> /**
> * Function will return the state of modem being
> * enabled on prot
> *
> * @return boolean Modem enabled or disabled
> */
> public boolean isModem() {
> return modem;
> }
> }
>
>
> Thanks,
> Chris Fowler
>
>
> _________________________________________________________________
> Chat with friends online, try MSN Messenger: http://messenger.msn.com
>
>
>