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
Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
It's likely that this is under my nose and I'm an idiot, but am I able to download the whole java API documentation so that I can reference it sans internet? In a simple way? (javadocs.zip?)

I mean this website: http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

Adbot
ADBOT LOVES YOU

Max Facetime
Apr 18, 2009

Newf posted:

It's likely that this is under my nose and I'm an idiot, but am I able to download the whole java API documentation so that I can reference it sans internet? In a simple way? (javadocs.zip?)

I mean this website: http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html

It's not directly linked from the online API docs, but you can find the link on the Downloads page way down under Additional Resources.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Here is the download for the Java7 javadocs.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
Thanks!

ComptimusPrime
Jan 23, 2006
Computer Transformer

Sinestro posted:

I am a Python programmer, and I need to learn semi-basic Java. All the books I see online are really old, designed for people that have no idea how to program, and/or designed for people who are already know Java to hone their skills.

What do you mean by basic? Core Java is a pretty good place to go if you want something that will get you up to speed. Just skip the parts you don't need.

RADmadness
Feb 17, 2011
Lets say I have a do-while loop:

code:
     do { Math.pow(ridiculous equation not worth mentioning,n)
    } while ( n ) // n can only be a range, lets say between 1 and 5
how would I go about setting n in a certain range?

To clarify I only need help with setting a range on n. The actual script compiles and works but I cannot find a way to stop n from being too high/low.

RADmadness fucked around with this message at 18:02 on Mar 2, 2012

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
ew, do-while

1 <= n && n <= 5, assuming you're being inclusive

RADmadness
Feb 17, 2011
We gotta start somewhere, this is week 6 of my java course. But thanks for the help.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

RADmadness posted:

We gotta start somewhere, this is week 6 of my java course. But thanks for the help.

php:
<?
for (int i=0;i<5;i++) {
    System.out.println(i);
}
?>

Tots
Sep 3, 2007

:frogout:
Is do-while ever useful?

Mobius
Sep 26, 2000

Tots posted:

Is do-while ever useful?

Its purpose is to have a block of code that is always executed at least once, then repeated if necessary. So, it's useful in those situations. It's also usually (always?) possible to do the same thing with a while or for loop. It's just a style preference.

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;
}

aleph1
Apr 16, 2004

No Safe Word posted:

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

I think you meant:

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

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
I prefer:

php:
<?
boolean done = false;
while (!done) {
  //do loop stuff
  if (something)
     done = true;
}
?>

Tots
Sep 3, 2007

:frogout:

fletcher posted:

I prefer:

php:
<?
boolean done = false;
while (!done) {
  //do loop stuff
  if (something)
     done = true;
}
?>

I've coded a total of about 2 things so far, and this is what I've used.

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Tots posted:

Is do-while ever useful?

I've used it once ever in real code. Usually I just use a while loop with a flag already mentioned.

Still something you should learn

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

aleph1 posted:

I think you meant:

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

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.

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:

Computer viking
May 30, 2011
Now with less breakage.

I'm almost afraid to ask (since I happily use them, if not often) - is there an good reason to avoid do/while loops?

Tots
Sep 3, 2007

:frogout:

Computer viking posted:

I'm almost afraid to ask (since I happily use them, if not often) - is there an good reason to avoid do/while loops?

I don't think so. I think the issue that people take with them is that if you sufficiently understand while loops then they are unnecessary. If you like using them then I don't see any reason why you shouldn't use them. Of course I'm new to the game so I could be very wrong, but that's how it looks to me.

Paolomania
Apr 26, 2006

Computer viking posted:

I'm almost afraid to ask (since I happily use them, if not often) - is there an good reason to avoid do/while loops?

No. If a do-while gives you the behavior you want then by all means use it. It also has the benefit of semantic clarity that it will run at least once without the reader needing to evaluate the initial conditions, as well as generates bytecode that is more sexy (to a compiler geek).

awkward while bytecode:
code:
Block A
Conditional Jump Block C
Block B
Jump back to Conditional
Block C
sexy do-while bytecode:
code:
Block A
Block B
Conditional Jump Block B
Block C

Bob Morales
Aug 18, 2006


Just wear the fucking mask, Bob

I don't care how many people I probably infected with COVID-19 while refusing to wear a mask, my comfort is far more important than the health and safety of everyone around me!

Book recommendation? I don't want to sludge through 122 pages and there isn't one in the OP/first page.

I have some creaky old 'Learning Java' from 10 years ago but I'll just buy something new. I know C and Ruby (and did -some- basic Java a long, long time ago) so I don't need anything geared toward complete beginners.

Strangely enough there are only a few Java books at the local Barnes and Noble for me to look through and they are all 4 years old, and there are so many books on Amazon I don't know which to begin looking through.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Bob Morales posted:

Book recommendation? I don't want to sludge through 122 pages and there isn't one in the OP/first page.

I have some creaky old 'Learning Java' from 10 years ago but I'll just buy something new. I know C and Ruby (and did -some- basic Java a long, long time ago) so I don't need anything geared toward complete beginners.

Strangely enough there are only a few Java books at the local Barnes and Noble for me to look through and they are all 4 years old, and there are so many books on Amazon I don't know which to begin looking through.

http://www.deitel.com/Books/Java/JavaHowtoProgram7e/tabid/1191/Default.aspx

I know there's some mixed feelings but I've gone through 2 editions of this book and if you like looking up a topic and seeing code examples EVERYWHERE as well as detailed explanations as to what's going on, then this is the book for you.

The latest editions took away those stupid rear end covers with bugs doing dumb poo poo, but I kinda liked them.

etcetera08
Sep 11, 2008

Bob Morales posted:

Book recommendation? I don't want to sludge through 122 pages and there isn't one in the OP/first page.

I have some creaky old 'Learning Java' from 10 years ago but I'll just buy something new. I know C and Ruby (and did -some- basic Java a long, long time ago) so I don't need anything geared toward complete beginners.

Strangely enough there are only a few Java books at the local Barnes and Noble for me to look through and they are all 4 years old, and there are so many books on Amazon I don't know which to begin looking through.

I'm using Horstmann's Big Java for a class right now and finding it pretty helpful and thorough. Expensive though.

Aafter
Apr 14, 2009

A is for After.

poemdexter posted:

http://www.deitel.com/Books/Java/JavaHowtoProgram7e/tabid/1191/Default.aspx

I know there's some mixed feelings but I've gone through 2 editions of this book and if you like looking up a topic and seeing code examples EVERYWHERE as well as detailed explanations as to what's going on, then this is the book for you.

The latest editions took away those stupid rear end covers with bugs doing dumb poo poo, but I kinda liked them.

Been working through the nineth edition with my class. I really like it. Its got quite a few exercises at the end that really pound concepts into you.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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"?

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).

lamentable dustman
Apr 13, 2007

🏆🏆🏆

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"?

Either make the list an Integer type and add the value part later or write your own comparer

ComptimusPrime
Jan 23, 2006
Computer Transformer

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"?

Well... When you are doing something like this you could just change the code to...

code:
List<Integer> myList = new ArrayList<Integer>();

myList.add(110);
myList.add(1);
myList.add(50);
myList.add(5);

Collections.sort(myList);

String myString = "value " + StringUtils.join(myList, ", value ");
System.out.println(myString);

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

No Safe Word posted:

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).

Nope, it's not always "value XX". I'll go with the custom comparator.

Sab669
Sep 24, 2009

Am I creating an array of objects incorrectly, or something?

code:
public class Player{
	int age;
	String name;

	<<Setters and Getters generated by the IDE>>
}
code:
Scanner kb = new Scanner(System.in);		
Player[] players = new Player[10];		
		
	for(int i = 0; i < players.length; i++)
	{
		System.out.println("Enter your age: ");
		players[i].setAge(kb.nextInt());
			
		System.out.println("Enter your name: ");
		players[i].setName(kb.nextLine());
	}
Throws a NullPointerException on the setAge line.


edit; I figured out my problem! :downs:
I needed to add
code:
players[i] = new Player();
To the for loop

Sab669 fucked around with this message at 04:12 on Mar 8, 2012

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.
I very nearly posted the stupidest question in the history of the thread but I've just figured it out.


Now I have to post it anyway because I've had a good laugh at the situation and I'm on a real streak of INCREDIBLY DUMB programming errors (an hour where corresponding files weren't in the same directory, an hour shouting at a program that wouldn't run because it didn't have a main method, and now this):

Me, last night posted:

Why won't eclipse auto-import this? Even trying the imports manually I can't get it to work???

None of java.util.WeightedGraph, java.WeightedGraph, java.DataStructures.WeightedGraph seem to be found and I can't figure out the proper import from the documentation for some reason?

Does day-to-day programming ever get over this kind of boneheadedness? I'm sure that I spend half of my 'coding time' on these types of errors.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Newf posted:

I very nearly posted the stupidest question in the history of the thread but I've just figured it out.


Now I have to post it anyway because I've had a good laugh at the situation and I'm on a real streak of INCREDIBLY DUMB programming errors (an hour where corresponding files weren't in the same directory, an hour shouting at a program that wouldn't run because it didn't have a main method, and now this):


Does day-to-day programming ever get over this kind of boneheadedness? I'm sure that I spend half of my 'coding time' on these types of errors.

Usually the solution is to stop using eclipse.

ComptimusPrime
Jan 23, 2006
Computer Transformer

Newf posted:

Does day-to-day programming ever get over this kind of boneheadedness? I'm sure that I spend half of my 'coding time' on these types of errors.

Yes and no. They will become less frequent but there will always be times when something obvious becomes incredibly difficult due to either being tired, a cache bug, or something else miniscule that will cost you a couple of hours.

cenzo
Dec 5, 2003

'roux mad?

TRex EaterofCars posted:

Usually the solution is to stop using eclipse.

Having only used NetBeans besides, what's wrong with Eclipse? We're stuck with Rational Application Developer (which is always a few versions behind on the Eclipse framework) because of the need for the Websphere runtime.

Luminous
May 19, 2004

Girls
Games
Gains
Nothing is wrong with Eclipse. Some people just don't like certain IDEs.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Eclipse is a decent program bogged down by half implemented and bug ridden plugins, overly aggressive caching and a horrible UI.

Intellij is better for nearly every professional level development task.

Newf
Feb 14, 2006
I appreciate hacky sack on a much deeper level than you.

TRex EaterofCars posted:

Usually the solution is to stop using eclipse.

But I just started last night! AHHHHHH!

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Eclipse is fine, people just get defensive about IDEs. Having used all 3 I still stick with Eclipse. It is also helpful when on a team because they are most likely also using Eclipse.

Adbot
ADBOT LOVES YOU

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
It's true that on a team Eclipse is usually the lowest common denominator, but it really is a really bad program. I've tried very hard to not hate it and sound like some "emacs vs vi" grade zealot, so I used it daily for it for like 7 years. It simply has not given me any indication that quality is a development priority.

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