|
question: when I write an inernet enabled java program for my PC, my firewall (zone alarm) asks me if it is OK for javaw.exe to access the internet. How do I tell my firewall that I want that particular java program to access the internet but perhaps not other programs running under the java virtual machine? 11:16:53 PM |
|
"The only safe methods to call inside a constructor are those that are final in the base class " There are cases where an instance method can be called before the constructor. This gives odd results. For example the following code: public class SpecialFish extends Fish{public String species = "Walleye"; void printSpecies(){ System.out.println("the species is: "+species);} public static void main(String[] args) {SpecialFish sf = new SpecialFish(); sf.printSpecies(); } } class Fish {String defaultSpecies = "Carp"; public Fish() {printSpecies(); } void printSpecies(){ System.out.println("This is the species: "+defaultSpecies);} } You might expect the above to print "Carp" and then "Walleye", but it prints "null" and then "Walleye" The reason for this is that by default, Java waits until run-time to decide what object it is working on. Making a method final is the way to ensure that it is bound at compile time instead of run time. Final is telling java that this method cannot be overridden. Without making the printSpecies() method final, java has no clue if Fish or Special Fish will be using it, so it waits until run-time and then prepares (constructs) the base class so that it is ready to morph into any class, base or derived, that it might need to be. In other words, it executes in the following order:
So, the base-class constructor is called and inside that constructor you have a call to the printSpecies method. Being a SpecialFish, the overridden printSpecies method gets called before the SpecialFish is even a twinkle in it's daddy's eye. It's like asking a kid to take the SAT seconds before he is conceived. So, the rule is, don't call a method that could be overriden from inside the constructor. 11:41:34 PM |
|
While every article about application development impresses upon us the importance of separating the data, logic and presentation layers, MS Excel gleefully mixes the three. While this gets sneers from most developers, it is precisely the reason that so many people use it and love it and get themselves into all kinds of trouble with it... and then ask me to help. So I was very excited to get my copy of Excel Hacks today. Among other things, it has a lot of tips for separating the data from the formulas and the data from the presentation, making a complex Excel spreadsheet more maintainable. Other things I was glad to see:
I am working my way through each of the 100 hacks and in almost every one, I am saying to myself, "Gee, I didn't know excel could do that" In summary, the O'Reilly hacks series has produced some excellent books and this one is one of the best. It is clear, concise, error free, and doesn't assume you have the most recent version of Excel. It is full of nuggets such as the fact that Excel purposely doesn't recognize that the year 1900 was a leap year (link blames it all on Lotus!). Who knows, you might encounter that some day. 10:56:46 AM |
|
I wanted to remove a range of items from a list using the List.subList method. I tried the following:
That got me the java.util.ConcurrentModificationException The documentation says that a subList is dependent on the List that it is sublisting from. So, while a sublist is open, it is manipulating the parent list and seems to have a lock on it. Instead, you can create a brand new ArrayList and fill it with the subList, thus freeing up the sublist so that a future call can modify the original List: ArrayList sl = new ArrayList(al.subList(10,40));
al.removeAll(sl);
So why does get you a different animal than
because in the first snippet, I haven't instantiated a new object, I just created a reference to an existing object. In the second snippet, I created a brand new object. That's what the word "new" gets me. 6:06:45 PM |
|
IntelliJ IDEA If you use IntelliJ 4.0 to check out projects from CVS make sure you click the "Change keyword substitution" to binary button in the CVS checkout procedure. Failure to do this could cause your project to fail to compile since the jar files will be corrupt. 3:03:37 PM |
|
IntelliJ IDEA, the Java development tool that I am liking more and more, uses log4J to build a log file that is stored as : USER_HOME\.IntelliJIdea\system\log\idea.log (On my windows installation, USER_HOME is C:\Documents and Settings\timcguir ) This file has lots of information about the internal workings of IDEA and has error messages that explained to me why the IDEA GUI Builder wasn't working like I expected. 11:19:57 AM |
|
1 exerting force by reason of weight alone without motion 2 showing little change
6:55:17 PM |
|
My Findings on HashMaps:
12:20:32 PM |
|
Here is the javascript function I used to disable the link that people often click more than once:
12:52:50 PM |
|
For two weeks I had this really frustrating problem: When users submitted the online fisheries exam, sometimes they would get an error page while the results would be emailed with no problems. I kept testing it and never got the error. I wondered if the database was crapping out because of too many open connections, I wondered about browsers caching error pages. Then I watched someone submit the exam. They were like, "it sometimes takes several clicks before it submits"..... click click click. It is second nature to me not to submit a form more than once, no matter how long it takes the server to process the form. So, when testing, click all the buttons more than once, because it's a sure bet your users will. In any case, there should be some code that handles this problem, but I didn't write the thing, I just inherited it. 9:39:39 AM |
|
The Apache Software Federation now has Planet Apache, a set of web logs for their members. (From Rogers Cadenhead) 8:41:23 AM |
|
I had the hardest time using an ArrayList. I had an ArrayList full of Fish objects and getting them out with ArrayList.get() and wanting to do some Fish type operations such as printing out data about the Fish and comparing it to another Fish. To get the third Fish out of the ArrayList it is in, I tried currentFish = myArrayList.get(2); The trick is that ArrayLists (and other containers) store all objects as Objects instead of as Fish or Dogs or Cats or Cars or Strings. This behavior happens for all types of java Collections. So when you call an object back out of an ArrayList, you have to cast it back into whatever object it is supposed to be currentFish = (Fish)myArrayList.get(2); Further confusion happens because every object has toString() over-ridden and automatically available so that when you think you are getting a string back from an ArrayList and want to print it out, it works fine. I even had it print out the results of getClass() on the Object I was retrieving from myArrayList and even that told me it was a Fish! But still, it was being treated like an Object until the cast. 7:57:53 AM |
|
Added notes on using IntelliJ IDEA GUI builder. 2:50:36 PM |