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
pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Harold Ramis Drugs posted:

Edit: Durf, totally solved my own problem. Don't use x == y to compare strings, use x.equals(y)

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.

Adbot
ADBOT LOVES YOU

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

No Safe Word posted:

Always use equals() to compare everything but primitive types

And references :).

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Sab669 posted:

Why is equals() better than ==? I'm a huge noob at all of this... and in related news! The reason why I came to this thread.

It's not a matter of being "better" than one another. You're simply comparing two different things.

== is used to compare primitive types, or references. That's all it should be used for. The .equals() methods of classes is meant to compare the data within the object. So for example, you have two String objects (call them a and b), and both have "hello" in them. String has various data in it; it doesn't JUST contain the string "hello". In order to directly compare the strings, you need to call the .equals() method. So to properly compare a's "hello" and b's "hello", you call a.equals(b);

Sab669 posted:

Trying to write a try-catch statement to verify some input from the user. Unlike a try-catch from what I'm used to, this REQUIRES some sort of error to throw- I can't just print out my own error message.

Basically

code:

try{
difficulty = kb.nextInt();
}
catch{
System.out.println("Error: only enter 1-3");
}

I guess I'm not sure what the most "proper" way of doing this is?

e; Looks like I've just got to make my own class that interfaces* Exception?
*Is that the proper term? I can never keep abstract/interface/whatever else straight

If you want to be terrible about it, you can just write:

code:
try {
   difficulty = kb.nextInt();
} catch (Exception ex) {
   ex.printStackTrace();
   System.out.println(ex.getMessage());
   System.out.println("Error: only enter 1-3");
}
But, you should be more specific and probably use whatever kb.nextInt() throws (which I'm guessing is the Scanner method).

code:
Throws:
    InputMismatchException - if the next token does not match the Integer regular expression, or is out of range 
    NoSuchElementException - if input is exhausted 
    IllegalStateException - if this scanner is closed
Catch one of those bitches and do proper error output or correction, etc.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

tyang209 posted:

Totally confused by this compiler error. I'm using DrJava and Eclipse and I'm pretty sure it's an error with something within Dr Java.

Code Snippet



I can't use next() without getting this error and the program should compile. This should compile as I grabbed this off my course website as an example program and it did compile on Dr Java for Mac but I'm getting that ambiguous invocation error on my PC. Totally confused as to why. Could anyone drop some knowledge on me?

Post the entire code, including your import statements. And for gods sake, use the [code] BBcode, man.

EDIT: Also, on another note, you should probably do some error checking via a try/catch or calling hasNext().

pliable fucked around with this message at 10:08 on Nov 10, 2011

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

rhag posted:

Oh please, JavaFX is shiny, I'll give you that, but swing is where the real action takes place. And, personally, I don't see why is swing deprecated. What doesn't it have that you'd wish to see there? JavaFX is pushed by Sun Oracle, but that doesn't deprecate Swing at all. And, best of all, it doesnt need a runtime, it comes with the JRE itself since forever (JRE1.2 actually, JRE 1.7 does include JavaFX runtime as well).

Personally, from all the GUI frameworks I've tried (and i played with a few: AWT, SWT, MFC, wxWidgets, QT) the swing architecture is in my opinion the best out there. Easy to learn, easy to master, there are very few simple rules that have to be followed. Can it be improved? Of course. That's where The Application framework (http://en.wikipedia.org/wiki/Swing_Application_Framework) kicks in, though is not really needed. Try your hand at JavaFX if you want, but you're not going to lose anything by going with Swing. It's a very good framework.

My only experience with Swing was with an Object Oriented class years ago and I remember thinking it was the biggest piece of poo poo ever. It seemed cumbersome, redundant...just a pain in the dick to write. Then again, I hardly write any GUI's, so...

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Tesseraction posted:

WALL O DEBUGGIN'

drat son, you're a kind coder. One hell of a post :)

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Onean posted:

I'm looking to teach myself Java. The only programming I've ever done was some HTML and CSS about 7 years ago, which I picked up pretty quickly but have completely forgotten by now. After reading through some past pages, are Oracle's Java tutorials still the best place to start? I'm planning on putting together a Minecraft mod as a personal introduction to Java as I'm going back to school this fall for an IT degree, and I want a basic handle on Java before starting.

I took a quick glance at some of the beginning lessons, but it looks like a pretty good start, especially for being free. Personally, I would learn this: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html before you learn the Object-oriented concepts. The page I linked teaches you more about basic mechanics of programming, which you need to know before anything about Object orientation.

Also, oddly, the best way to go about it is immerse yourself in it. I suggest downloading BlueJ, as it also helps you learn what "classes" are (Object oriented stuff), and use that to code the examples in the tutorial.

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe
This is part of my ongoing confusion with Java's pass-by-value/reference dealio:

Say I have an ArrayList of some object, and say that object implements Comparable so it can be sorted via Collections.sort(). Why the gently caress does that even work, if Java passes by value? For example:

code:
ArrayList<myObject> myObjects = new ArrayList<myObject>();

//code to populate myObjects

Collections.sort(myObjects);

//now my poo poo is sorted hooray!
Why does this work? Thanks y'all <3

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

carry on then posted:

e: it's a very subtle distinction, but it's one worth making.

Yeah, and its subtlety still trips me up. But awesome, that clarifies...thank you much!

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Egorger Le Chef posted:

I am taking a class in java and I have a few questions (I am not asking for homework help)

Background I have openJDK 7 installed on debian and I have a slightly older version of eclipse installed from the repos. The teacher had everyone install java 1.8 JDK and the new windows version of Eclipse(not in the debian repos). My question is: Has enough changed that I should bother trying to code in a virtualBox XP install with all the standard software, or will I probably be fine coding with openJDK-7 and an older version of eclipse? Should I try to code java in VIM instead of eclipse? Anything I should know going ahead?

P.S. The prof doesn't care which IDE or text editor I use, however I believe most professors in the CS department use eclipse with java.

Yeah like others said, one of the new features of Java 8 is closures, which, would be impressive if they ended up teaching it (I didn't even learn about closures until my upper division courses, so...).

And call me spoiled but I can't program in Java without eclipse. There are too many useful features that make programming in Java much easier (eg: automatic building, code completion, etc). I only use Vim when programming in C (and sometimes Python, but I mostly use PyCharm for Python).


Thanks for the help anyway :)

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Zaphod42 posted:

You don't have to use Eclipse, but in 2014 you do have to use an IDE. Vi and Emacs aren't IDEs.

If you're really hardcore, you can use a simple text editor. I don't recommend it at all, but it's certainly possible and I've seen it done. I have a buddy that uses Vim for all his Python, and simply utilizes Vim tabs and splits to look at everything.

You don't *have* to use an IDE, but it makes life much, MUCH easier. I'm also well aware that Vim and Emacs aren't IDEs ;).

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Kenishi posted:

Java should be easier to learn than python in some respects because Java doesn't handle tuples and lists natively.

Huh? :confused:

ArrayList, LinkedList, Vector, Stack...

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Kenishi posted:

Those are part of the Java standard library. If I have to import the thing to use it then its not natively part of the language. Plus I've always found the manipulation of lists/tuples in Python to be a lot easier than using the Java library ones.

Oh, I consider anything part of the standard library to be "native", but I see what you mean. And yeah, I completely agree that lists/tuples in Python are way easier than Java.

Before I used Python, I came from a C/Java background, and tuples blew the poo poo out of my mind. The ability to return tons of things as one tuple is sexy as gently caress

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

Yhag posted:

And this for the other one:
code:
                    int pxA = (int) (xA);
                    int pyA = (int) (yA);
                    int pxB = (int) (xB);
                    int pyB = (int) (yB);
                    int pxC = (int) (xC);
                    int pyC = (int) (yC);

                    pnlPlot1.setxA(pxA);
                    pnlPlot1.setyA(pyA);
                    pnlPlot1.setxB(pxB);
                    pnlPlot1.setyB(pyB);
                    pnlPlot1.setxC(pxC);
                    pnlPlot1.setyC(pyC);
                    
                    pnlPlot1.repaint();
I don't know if that's the fastests/easiest way, but it works.

Is there a particular reason why you're casting all those ints, storing them into ints, then passing those ints along to your setxx methods instead of just casting them and passing them straight?

Like this:

code:
                    

                    pnlPlot1.setxA((int)xA);
                    pnlPlot1.setyA((int)yA);
                    pnlPlot1.setxB((int)xB);
                    pnlPlot1.setyB((int)yB);
                    pnlPlot1.setxC((int)xC);
                    pnlPlot1.setyC((int)yC);
                    
                    pnlPlot1.repaint();
It's not a huge deal but, I'm curious.

pliable fucked around with this message at 11:26 on Sep 11, 2014

Adbot
ADBOT LOVES YOU

pliable
Sep 26, 2003

this is what u get for "180 x 180 avatars"

this is what u fucking get u bithc
Fun Shoe

TheresaJayne posted:

Well i have seen stuff like this in the past

code:
           int a = 10;
           int b = 0;
           b = (int)a;
Apparently this is because the person used to be a C++ developer and thats how they code C++ but i just think they had a problem with casting once and now cast everything just to be sure.

I'm a C coder as well and maybe I'm fortunate enough to have gone to a great university, but if any of my professors saw this after 101, they would fail us immediately.

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