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
Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
rjmccall, what's the point of using asserts in your code if they are can and usually are disabled in production?

Adbot
ADBOT LOVES YOU

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Kamakaze9 posted:

On a related note, when is error checking and such usually taught? I am only in programming II (university level). And we haven't touch on it at all. And it appears that the rest of the class will focus on GUI. Which, in my opinion, seems less important.

If you are lucky you'll touch on it in your software engineering classes, but most likely never.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
As for the name of the method (main), it's a convention that is used so that the java virtual machine can always find the right starting point for your program.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Deep Winter posted:

Hypotheticaly speaking, would it be against the rules to ask for help on my java programming final?

Hypotheticaly you could :getout:. But that's mean, so I'll just say that I don't think anyone in CoC would help you.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I have a similar method for closing SQL connections, statements and result sets.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
In netbeans simply copying the res folder to the src folder will copy them to the build directory whenever you build the project. I think Eclipse works the same way, and you get the benefit of having your res folder be a folder in the jar.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Internet Janitor posted:

What feature does most he wish had been left out of the Java language?

Optional bitchy question: Why the gently caress do Swing and AWT classes implement Serializable?

So you can send them over the wire and have a truly networked application! :pseudo:

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

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

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Jabor posted:

The also introduced some bugs, if your code has loops in it.

What bug is that?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I kind of like using the interface name in the implementation class name. i.e. I made an interface called ComponentCommunicator, and it defines the type of messages you can send to Component. Then the implementations are called things like RestfulComponentCommunicator, SoapComponentCommunicator, ProtobufComponentCommunicator.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

tripwire posted:

Except for the glaring lack of compile-time immutable collections, and the violating liskov substitution principle thing.

It's a shame really, because those would have been infinitely more useful than unmodifiableList and its ilk.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Scabies posted:

It might just not like JDK 7 for some reason, try reverting to six-point-whatever.

Did you not read his post? Also the Greenfoot website says it requires the Java 6 or Java 7 JDK.

edit for actual useful information: Uninstall anything called Java in your program files. Then download this JDK 6.27 and install it. Then download this Greenfoot Jar and you should be able to double click the file.

Janitor Prime fucked around with this message at 16:06 on Oct 4, 2011

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Internet Janitor posted:

Java 5 added the modern Collections framework, generics and the foreach loop, among other more minor details. Honestly, Java 6 and Java 7 haven't added many critical features that significantly change how things are done.

I would say that Java 6 didn't change anything, but Java 7 certainly added new syntax.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
You just need to do an HTTP POST to the URL. The body of the message is an XML with the fields that are defined in the wsdl.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Check out this method Collections.sort.

What you really need to learn is how to create your own Comparator which does what you want. Once you've figured out how to create the comparator, you just tell the Collections.sort method to use that and it will do the rest.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

HFX posted:

I know which one you are talking about. I would not define that as works.

You are correct, that Netbeans does have great Maven support and a worthwhile reason to use it. I end up using the command line because the Eclipse plugins are so terrible.

If it's any consolation the mercurial plugin for NetBeans loving owns. If I rename a or move a file it will also do an hg rename. It makes refactoring code 100% easier than before. One of my favorite little features is CTRL+ALT clicking an interface and having it show me the list of implementing classes.

The only bug I frequently encounter is that the index doesn't get updated after fixing a compilation bug and having it mark the file in red. I have to delete my users .netbeans/var/cache/index folder completely for it to go away.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Here's how it's done manually Adding Classes to the JAR File's Classpath and using an IDE just makes it easier.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
code:
Integer i = 4;
// This returns the string, but is only useful when working with Integers not ints.
i.toString();
The fact that String has a valueOf method and Integer has a toString method is confusing. I can't decide which is better, but i'm leaning towards Integer.toString.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
code:
/**
 * @throws IllegalArgumentException if the given height is negative
 */
public void setHeight(double height) {
    if(height < 0.0){
        throw new IllegalArgumentException("Can't have a negative height.");
    }                
    this.height = height;
}
Whenever you throw a RuntimeException you should indicate it in the documentation of the method.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Because otherwise other people that use your code won't have any clue that the method will throw that exception until someone actually passes in a negative value.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
src/main/resources

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
This is going to sound counter to what you guys want, but learn loving maven and be done with it. If you want to do anything with the Java ecosystem you're going to run into it, and it basically replaces all that setup that the IDE does, so I think it's worthwhile for beginners to learn and use it.

By placing all of your source files in the correct directories maven, will compile and generate a jar file containing the compiled sources. You can use that jar file directly from the command line and not have to deal with all the classpath bullshit. There is no benefit to know how to do that poo poo by hand, it's a huge waste of time and ultimately detracts from what you actually want to learn.

One of the main features of maven is its dependency resolution, but for your baby's first program you probably won't require any dependencies. As you start doing more complex things that aren't part of the standard api you'll want to use them and maven can help.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Going to chime in with I've only seen it when redeploying a project with a lot of Web Services in GlassFish. After many redeploys it will barf on that and require a restart. I think it's because the GC doesn't reclaim stuff in the permgenspace.

edit: I've also seen it when compiling a project in Netbeans a bunch of times. LOL

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I never thought to use my IDE for source control. The only thing it does implicitly and I'm OK with because it does it correctly is rename files.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
TRex, what ComptimusPrime is describing is independent of your source control. It happens anytime you make a nontrivial amount of changes to your files; Netbeans can't figure it out.

I just realized that I always make sure to close Netbeans whenever I switch branches to avoid those kinds of problems and it's worked well for me so far. I just clean an build the project and Netbeans is happy. It's become so ingrained I just don't think about it anymore.

The only time I ever have to clear that cache folder is when I notice that Netbeans doesn't refresh the the stupid Red X icons on your files that don't compile no matter how many restarts you've done.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Aleksei Vasiliev posted:

returning void is a sin (outside of static methods)

This sounds like stupid dogma to me. You're going to have to backup this claim with some examples.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Blacknose posted:

Something subclassed from InvalidStateException, I reckon.

IllegalStateException, but FYI that extends RuntimeException. If the clients of that method can't reasonably recover from that error then by all means use it. If they can handle it, then you should subclass from Exception so that they have to handle it.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Dr. Gitmo Moneyson posted:

Where do the "JOptionPane"s go? Everywhere the "b"s are now?

Yes, that's the standard way of referring to class constants.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Hidden Under a Hat posted:

My software is all of the sudden uncompilable to NetBeans. Here is the error I get upon trying to run it:

code:
Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: Uncompilable source code - missing method body, or declare abstract
        at com.labrx.icon.BioreactorCode.<init>(BioreactorCode.java:75)
Now if I remove all reference to this class, it will just say the same thing about another class, and so on with every class in my program. Keep in mind this code worked just fine an hour ago. From the time it worked until now when I get this error, I had created and worked on a new class that extends JPanel and has lots of GroupLayout that I coded myself without using the GUI builder. Since I thought the new class was probably the issue, I deleted it but I still get the same error. If I clean and build it, the program runs fine though. Anyone encounter this before?

If a clean a build fixes it, then that means your code is fine and NetBeans is at fault. Try closing NetBeans, and deleting the var/cache/index/ folder of NetBeans. It's normally stored in your home directory under .netbeans/version/

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Hidden Under a Hat posted:

I can't find this folder anywhere. I'm using Mac OS X 10.6.

On Linux systems, directories starting with a dot are hidden, maybe OS X is the same?

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
It's right there in the loving main method's signature
code:
public static void main (String[] args)
If someone runs your program from the command line then args will have the array with the values. Obviously they are Strings and you need to convert them to numbers.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I'd say that Java UI applications are a dead end to begin with.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I completely disagree with your assessment of Effective Java. It's the book for you to read at this point. It will cover everything you should know to be a better java programmer. It might not cover every API and language construct, but it does cover the most important ones that you will run into frequently.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Dijkstracula posted:

The assertion fails with 6 instead of 3, I read, because HashSet::addAll() calls HashSet::add() under the hood, so addCount gets incremented more times than it should be.

The progression of calls I was expecting was InstrumentedHashSet::addAll -> HashSet::addAll -> HashSet::add() x 3. That is, I was under the impression that super() kind of acts like a superclass cast, where once you call super() the HashSet object has no notion that it's not at the end of the class hierarchy. What's the right way to think about this?
As you verified with your code the progression was this: InstrumentedHashSet::addAll -> HashSet::addAll -> InstrumentedHashSet::add() x 3

Even though HashSet calls what it thinks is its own add() method, InstrumentedHashSet's method is the one that is called because that's the type of object that you instantiated.

Anytime you overwrite methods in a sub class, all of those methods will be used in any subsequent calls, even if it's from a super class. This is why Bloch says that you have to allow for inheritance explicitly because you don't know what some sub class is going to end up overwriting and loving your poo poo up.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Just wanted to add that WebServices also love to chew through the permgen space when you redeploy them a lot.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

trex eaterofcadrs posted:

a configuration where the jvm is not allowed to reclaim objects in permgen.

I'm pretty sure it's this, or else GlassFish's class loader has the leak, can't be arsed to find out.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Great post Internet Janitor, I just also wanted to add that understanding how the Java serialization framework works is also one of those language features with lots of gotchas there's also the little known Weak References and finally I'd also say that a Java wizard should know how the different garbage collectors work and know how to tune some basic JVM parameters.

Janitor Prime fucked around with this message at 18:38 on Jul 28, 2012

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

Aleksei Vasiliev posted:

Also you can do double-checked locking in Java 5, it's in Effective Java 2E. Pretty sure he knows what he's talking about.
The IBM article is under Java 4 and using a slightly different form.

Since you didn't mention it, Bloch says that the best way to do a Singleton is by extending Enum. :shepface:

Java code:
public enum Foo {
   INSTANCE;
}

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

mister_gosh posted:

I could also Override the TreeMap method... there's ways around this, but it just seems like you shouldn't need to patch code just for the remainder of a major release.

Which is reasonable I agree, but time has proven once again that you can't count on any new update not breaking your poo poo. There is wisdom in not updating your platform every time a major update comes along. You're lucky that you still have access to the source code of your program and can fix it.

Adbot
ADBOT LOVES YOU

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

ManlyWeevil posted:

Is there any significant difference between

code:
try {
...
} catch (Exception e) {
    if (e instanceof SomeException) {
        doSomething(e);
    } else if (e instanceof SomeOtherException) {
        doSomethingElse(e);
    }
}
And the usual

code:
try {
...
} catch (SomeException e) {
    doSomething(e);
} catch (SomeOtherException e) {
    doSomethingElse(e);
}

It's a faux pas

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