Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
No Safe Word
Feb 26, 2005

Jam2 posted:

Harvard CTO, Jim Waldo is coming in to speak to my intro java class tomorrow. He was on the team that developed the Java programming language at Sun back in the day.

What question, if anything at all, should I ask him? Is there anything you guys want to know about Java or Sun?

"What on god's green earth were you guys thinking when you wrote the Calendar class?"

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

MEAT TREAT posted:

Just show them how to convert everything into a Runtime exception :unsmigghh:.

Why bother when you can just add throws Exception everywhere?

No Safe Word
Feb 26, 2005

pliable posted:

Pffffffft, amateur. Yeah, that's definitely tripped me up a few times, but once you learn...it's so valuable.

Always use the equals() methods to compare your strings, kiddies.

Always use equals() to compare everything but primitive types

No Safe Word
Feb 26, 2005

hootimus posted:

Another stupid Java question:

Is there something I can do in Eclipse so that I don't have to include the library path when I'm launching a jar? What I mean is this:
code:
java -jar -Djava.library.path=/usr/local/lib application.jar
Is my only option to symlink or copy the library modules into a place where my system usually looks? How can I find out where the system is looking for these library modules? I added /usr/local/lib to the $PATH but it does not help. This is on OS X by the way... ugh.

You should just be able to add external JARs to your project. Right-click on your project and I think it's under "Source" there should be an option to add an external JAR.

No Safe Word
Feb 26, 2005

Mobius posted:

It's also usually (always?) possible to do the same thing with a while or for loop.

Always. You can trivially transform any do/while into a simple while.

code:
do {
   ... stuff ...
} while (<condition>)
to:

code:
run_once = false;
while (<condition> AND run_once) {
    ... stuff ...
    run_once = true;
}

No Safe Word
Feb 26, 2005

Jabor posted:

I think you mean:

code:
run_once = true;
while (run_once OR <condition>) {
    ... stuff ...
    run_once = false;
}
otherwise you're evaluating the condition once before the loop actually runs, which is not what do..while does.

Yes, this is what I meant :doh:

No Safe Word
Feb 26, 2005

fletcher posted:

code:
List<String> myList = new ArrayList<String>();
myList.add("value 110");
myList.add("value 1");
myList.add("value 50");
myList.add("value 5");

Collections.sort(myList);

System.out.println(StringUtils.join(myList, ","));
This spits out "value 1,value 110,value 5,value 50". How can I get it to sort it as "value 1,value 5,value 50,value 110"?

Is it always "value XX"? If so, consider just using a list of Integers and transforming the output elsewhere. Then the sort will work fine.

Otherwise, you'll have to write a custom comparator to pass into Collections.sort or just write your own sort (which would be kind of silly).

No Safe Word
Feb 26, 2005

Brain Candy posted:

Use JodaTime.

This should be in the OP, if not be the entirety of the OP.

No Safe Word
Feb 26, 2005

Internet Janitor posted:

Computers are fast, man. Don't worry about the overhead of compressing and decompressing a 1mb file at compile time until you try it and it's actually a bottleneck.

Premature optimization something something

Adbot
ADBOT LOVES YOU

No Safe Word
Feb 26, 2005

baka kaba posted:

I did it on Android because my memory use was creeping up on a draw list in a render loop! Just saying that there are sometimes situations where you might care about these things, but in general don't bother and go with the nice easy readable version

Yes but don't confuse "more performant in some scenarios" with "cleaner". The foreach style loop is pretty much objectively "cleaner" from a code standpoint.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply