Terry McKee

Ranch Hand
+ Follow
since Sep 29, 2000
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Terry McKee

As long as the MyInner class references variables that are accessible it will work properly. Let's say that doStuff method is called, executed and exited. In the process, an instance of MyInner class is created and is usable by an unrelated class (ClassA). If ClassA then calls seeOuter - it will work properly as long as z is final because the Java runtime can guarantee that the value will never change. In Java 8, the concept of effectively final was introduced. From the Java Tutorials Trail: A variable or parameter whose value is never changed after it is initialized is effectively final. So if you're using Java 8+, you may not necessarily need to include the final keyword.

Also, the inner class can be made accessible by a variety of means - returned from the method, inserted in a shared, accessible collection or class, etc. The excerpt that you provided from the book probably could have been made a little more clear by including how the inner class is made accessible to other objects.
Since you are using the default StringBuffer constructor, it will hold enough space for 16 characters. As you add lines form the log file to the buffer, it will have to create new backing character arrays that are larger. This causes the JVM to waste a lot of memory since the old backing arrays may not be gc'd right away. One way to optimize your code is to preallocate a larger capacity for StringBuffer. For instance, using new StringBuffer(100000) will create an initial backing character array that can hold 100,000 characters. You may need to increase the max heap size that you start your process with so you don't run in to OutOfMemory errors.

As a side note, you may want to switch to a StringBuilder if your code is thread-safe.
9 years ago
printf is a method of the PrintWriter class. Your first step should be to look at the API documentation: Java 6 - Print Writer API Documentation. There are two signatures to consider:

1) printf(String format, Object... args)
2) printf(Locale l, String format, Object... args)

If you don't care about the locale then you just need to use the first one.

There are different formats that can be specified in the first string, but the one you are concerned with is "%f". That says - Hey, format this as a float. Taking it a step farther, I suspect you are interested in limiting the precision. You can do this by doing something like "%.2f" This will set the precision to 2 digits. Here is a revised working example:

[edit]Add code tags. CR[/edit]
[ October 10, 2008: Message edited by: Campbell Ritchie ]
15 years ago
In your Polynomial class you have the following constructor defined:

public Polynomial(int[] coefficients)

In your PolynomialTester class you use the following constructor:

new Polynomial();

Hmmm... I wonder what coefficients the tester class wants to use.
15 years ago
Hi Edward,
The Scanner class is used for parsing of String data using regular expressions. The locale can affect how characters are interpreted in relationship to regular expressions that you may use with the scanner.

The Scanner class doesn't have anything to do with displaying of characters. I suspect that you are using additional code such as System.out.println() statements. Depending on the environment that you are working on it may or may not have support for displaying of Chinese characters.

Could you provide more details on what you are trying to accomplish?
15 years ago
Has anyone else noticed that downloads seem to be unavailable from the http://java.sun.com site?

I have tried downloading the NetBeans IDE as well as the JDK 1.6U4, but receive an error.
16 years ago
Sorry for the ambiguity. I don't really have a particular audience in mind other than myself. I am just trying to figure out some approaches to this problem. The examples that are provided above really help to solidify a couple of ways that this can be modeled. Much appreciated.
The Travel Agent is only used in the reservation process. That would indicate to me that it could be an association class, but I do like Ilja's suggestion.

Any other thoughts on how this could be setup? If the Travel Agent were used outside of the reservation process, how would that potentially change the model?
Hey Ilja,
Thanks for the quick replay. You pose an interesting alternative. I'll have to see if it fits in with the rest of my conceptual model.

I got to thinking about this issue after reviewing the Applying UML And Patterns book (Third Edition). In the book, they have both cases, but not together.

What do you think of my solution. Can you think of a way that doesn't use an association class? I'd like to make this as simple as possible.
I have scoured the internet and a number of books, but am unable to find out how to model a specific concept.

A customer can book a hotel room directly using an internet website. (Easy to model: Customer -> Reservation)

But what if you wanted to model both of these cases:
A customer can book a hotel room directly using an internet website OR A customer can book a hotel room through a travel agent. In this case, I have two associations between Customer and Reservation.

1) Association One

Customer
|
| {noTravelAgentUsed}
|
Reservation

2) Association Two - (n-ary association)

Customer
|
| {usedTravelAgent}
|
|---Travel Agent
|
Reservation

So in the first association, I have a guard indicating that a Travel Agent isn't used. In the second, a guard indicating that a Travel Agent is used.

Does this make sense? Are there any better ways to model this? Is there a way to get rid of the n-ary association which makes the diagram more complex? I was thinking of a CustomerProxy class, but I wasn't sure how to fit this in correctly.
Yes. A .class file is bytecode. Bytecode is interpreted by the Java Runtime Environment so that it can be executed by the hardware on your machine. Here is more information about bytecode:

http://en.wikipedia.org/wiki/Bytecode
16 years ago
I am new to NetBeans 5.5. Is there an easy way to exclude a file or package from your source directory? I can do it by modifying the build-impl.xml file directly, but if I make any changes to the project this file will be regenerated.
Hi Erik, I haven't finished my exam yet, but if you look around at some of the posts you'll find that many people have modified the Business Domain Model and have done very well. It seems to be more important to document your decisions in the assumptions document. I hope this helps.
I really like Enterprise Architect...so much so that I bought a copy of the Professional Edition. It doesn't have all of the extras that Rational Rose provides, but it is more than adequate. You could even buy a copy of the desktop edition and upgrade later. I am a little frustrated with the support. They have a forum where questions are answered, but there isn't a huge amount of user activity. Nevertheless, I find it better than any of the other products out there.
Hey David,

If you browse through the posts here, you will see that people have done it a variety of ways. Most of the posts that I have read indicate that you shouldn't put implementation specific classes into the diagram (like controllers, EJBs, etc.). In fact, many that have done this have had to resubmit their assignment later.

As Francis indicated, reading more about software design (architecture) will help you to make decisions about what is important to put in the class diagrams. People have passed by modifying and people have passed by not modifying the original Business Domain Diagram. The key then is not in so much the decisions you make (although if you make a crazy class model you clearly won't pass), rather, (1) how consistent you are acoss all of your documents and (2) how clearly you justify your decisions in your documentation.