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
Stinkyhead
Jul 6, 2007

that's a pretty stinky looking head
Is Java a good first programming language? I plan to take a class in it this year and would like to know if there is anything I should do to prepare for this. Would running through a few tutorials be best?

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

Stinkyhead posted:

Is Java a good first programming language? I plan to take a class in it this year and would like to know if there is anything I should do to prepare for this. Would running through a few tutorials be best?

I would say yes, it is a good first programming language. Eclipse is an awesome IDE. These tutorials cover most of the basics. Once you get through that I'd say jump right in head first and start doing stuff on Google App Engine as they have some great tools and tutorials to start doing some really neat things. If you get stuck, ask some questions here! The people in this thread are very helpful and friendly.

fletcher fucked around with this message at 20:10 on Jul 31, 2010

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Just to add to what fletcher said, if you find yourself struggling with the basics of Java or you'd like to see more immediate feedback, try out Processing. It's Java programming, but you're allowed to ignore some of the OO boilerplate and jump right into drawing dots and lines.

RitualConfuser
Apr 22, 2008

Stinkyhead posted:

Is Java a good first programming language? I plan to take a class in it this year and would like to know if there is anything I should do to prepare for this. Would running through a few tutorials be best?
Are you a Computer Science major or are you more someone who is interested in learning about programing?

If you're the former I'd say that there are reasons why you should learn a lower level language like C first before moving to a language like Java. There are also arguments for learning a language like Java or Python first. This seems to be widely debated, so take that with a grain of salt.

If you're the latter or you're just getting started with programming, you also might want to look into Python. If a class based on Python is not available, a Java based class would still be a good introduction to programming. The only advice I'd give, as others had said, is to ask in this thread as some of the concepts are not all that clear.

Detetsu
Jan 14, 2006

Your loyal assistant Dr. Meowgon is all over this one.

fletcher posted:

How come something like this works:
code:
public static String[] test() {
	String[] stuff = { "stuff" };
	return stuff;
}
but this does not:
code:
public static String[] test() {
	return { "stuff" };
}
(not that I want to use it, just curious)

I'd chalk that up to "stuff" being a static return, while stuff isn't.

Chairman Steve
Mar 9, 2007
Whiter than sour cream

RitualConfuser posted:

If you're the former I'd say that there are reasons why you should learn a lower level language like C first before moving to a language like Java. There are also arguments for learning a language like Java or Python first. This seems to be widely debated, so take that with a grain of salt.

This. I'd rather claw my eyes out with a spork than write C for a living (I write Java at the moment), but taking a semester on C in college gave me such a better understanding of memory and pointer management than I ever got in the two Java classes I had taught before it. There's sometimes value in learning where you've come from.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Steve: C makes even more sense if you learn assembly and understand how the calling convention maps onto the stack. There's a ton of educational value to learning C, but I'm not sure I'd encourage it as a first language.

Fly
Nov 3, 2002

moral compass

Internet Janitor posted:

Steve: C makes even more sense if you learn assembly and understand how the calling convention maps onto the stack. There's a ton of educational value to learning C, but I'm not sure I'd encourage it as a first language.
For the dilettante I miss the ready availability of things like BASIC and 6502 or 6800 assembly language as a very simply start, but those may be more suitable to someone in grade school anyway.

I would recommend Python or Java rather than C as a first language for an adult, but C would be good after mastering an assembly language.

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
Simple question: How do I access elements of an String array inside an ArrayList?

E.G, I have an ArrayList called aList and then I have an set of arries of Strings with 2 elements per array called tempArray, looking something like this:

code:
ArrayList aList = new ArrayList();
String tempArray = new String[2];
...
for(...) //This loops X times, putting something new in someString and someOtherString every time
{
tempArray[0] = someString;
tempArray[1] = someOtherString;

aList.add(tempArray);
}
Now, lets say I want to access the 2nd element of the 3rd array in the array list. How do I do this?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
That looks like a horrible data structure but to do it:
code:
aList.get(3)[2]

Mustach
Mar 2, 2003

In this long line, there's been some real strange genes. You've got 'em all, with some extras thrown in.
Well he couldn't do that, because his crazy example doesn't use generics.

Also your snippet would give an ArayIndexOutOfBoundsException in his case

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

Mustach posted:

Well he couldn't do that, because his crazy example doesn't use generics.

Also your snippet would give an ArayIndexOutOfBoundsException in his case

In my defense he was asking for those specific indexes. But yeah, gotta cast that get().

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer

TRex EaterofCars posted:

That looks like a horrible data structure

After working with it a bit more, I now see that what I have created it a monstrosity among the gods of coding and ought to be considered sacrilege. I abandoned it in favor of just sticking the data into an ArrayList of type <Stuff>, which simply holds 2 strings. It makes it considerably easier to work with. I do appreciate the help though regardless!

Enderzero
Jun 19, 2001

The snowflake button makes it
cold cold cold
Set temperature makes it
hold hold hold
Does anyone know where I can get a copy of rt.jar with all debugging information included? I've been trying to roll my own for 2 days and when it all finished it works but still won't let me see local variables. This has been an open bug for 8 years!

Fly
Nov 3, 2002

moral compass

Canine Blues Arooo posted:

After working with it a bit more, I now see that what I have created it a monstrosity among the gods of coding and ought to be considered sacrilege. I abandoned it in favor of just sticking the data into an ArrayList of type <Stuff>, which simply holds 2 strings. It makes it considerably easier to work with. I do appreciate the help though regardless!

Be sure you create a new Stuff object inside the loop. Your example above creates "tempArray" outside the loop, so it's adding the same array to the ArrayList multiple times, and you are losing all of the previous values you stuffed into tempArray.

Your example will end up with a structure such that

aList.get(0)[1] == aList(n)[1] && aList.get(0)[2] == aList.get(n)[2] for all valid values of n because aList.get(0) == alist.get(n).

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

Enderzero posted:

Does anyone know where I can get a copy of rt.jar with all debugging information included? I've been trying to roll my own for 2 days and when it all finished it works but still won't let me see local variables. This has been an open bug for 8 years!

If you get the JDK from Oracle (feels weird saying that, pourin' out a 40 for Sun) it should come with it. It works for me in Eclipse and Netbeans.

Enderzero
Jun 19, 2001

The snowflake button makes it
cold cold cold
Set temperature makes it
hold hold hold

TRex EaterofCars posted:

If you get the JDK from Oracle (feels weird saying that, pourin' out a 40 for Sun) it should come with it. It works for me in Eclipse and Netbeans.

Nah, that version doesn't have full debugging support, just partial. It can't see local variables. I managed to get it working, it turns out that when I copied the newly compiled class files over the old folder structure it did not replace the files. If anyone is really interested I can write up what you need to do.

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I kind of am, that sounds like something I'm about to do :(

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

Enderzero posted:

Nah, that version doesn't have full debugging support, just partial. It can't see local variables. I managed to get it working, it turns out that when I copied the newly compiled class files over the old folder structure it did not replace the files. If anyone is really interested I can write up what you need to do.

Yeah I wanna see this too because I've never had an issue debugging rt.jar.

Enderzero
Jun 19, 2001

The snowflake button makes it
cold cold cold
Set temperature makes it
hold hold hold

TRex EaterofCars posted:

Yeah I wanna see this too because I've never had an issue debugging rt.jar.

Like following control flow or actually examining everything you would be able to in a class you defined and compiled with debug support? I can follow the control flow, but documents and editor kits are so complex that I was unable to tell what the hell is going on without local variables, which were missing.

Edit: I'll write it up tomorrow, I'm leaving work pretty soon and it's quite involved - I don't want to get any details wrong.

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE
Anyone have a recommendation for a decent GUI Swing editor in Eclipse?

epswing
Nov 4, 2003

Soiled Meat
I used it more than 2 years ago, but Swing Designer was pretty darn good.


-----------------So good that they were purchased by Google http://www.instantiations.com/ and are currently cockblocking us from getting at their software, which was an Eclipse plugin.

NEVERMIND!

necrobobsledder
Mar 21, 2005
Lay down your soul to the gods rock 'n roll
Nap Ghost
So I like python decorators. Is there a Java library that can provide some of the sugar to do something like it? I've realized that what I've written to strip a lot of boilerplate in my class hierarchies is better expressed in that manner. I'm not terribly familiar with Spring, but maybe I could use method injection in libraries like Guice or Tie to do something like a Python decorator in reuse of code through an annotation. DI is so awesome but it's hard to design with DI in mind sometimes and you'd rather wait until you actually need DI before your unit tests and mock objects get out of hand. So I'd try to make sure whatever solution I use doesn't conflict with Guice or Spring annotations. Last I remember both libraries do some bytecode weaving and the thought of breaking tools like that scares me.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Have you looking into Java-based AOP tools yet? Spring itself comes with spring-aop and there is a standalone library called AspectJ that both do AOP.

covener
Jan 10, 2004

You know, for kids!

necrobobsledder posted:

So I like python decorators. Is there a Java library that can provide some of the sugar to do something like it? I've realized that what I've written to strip a lot of boilerplate in my class hierarchies is better expressed in that manner. I'm not terribly familiar with Spring, but maybe I could use method injection in libraries like Guice or Tie to do something like a Python decorator in reuse of code through an annotation. DI is so awesome but it's hard to design with DI in mind sometimes and you'd rather wait until you actually need DI before your unit tests and mock objects get out of hand. So I'd try to make sure whatever solution I use doesn't conflict with Guice or Spring annotations. Last I remember both libraries do some bytecode weaving and the thought of breaking tools like that scares me.

FWIW JSR299 (Contexts and dependency injection for java) is part of EE6

Jick Magger
Dec 27, 2005
Grimey Drawer
I feel retarded. I've got a while loop that won't seem to break:

code:
public void runGame(){
		Random generator = new Random();
		int level;
	    for(level = 1; level < 10; level++){
	    	for(int i = level; i >0;i--){
	    		this.flipPieces(generator.nextInt(size), generator.nextInt(size));
	    	}

       //for the love of god work!
	    	while(field.getFlipped() > 0);
       //
	    	repaint();
	    }
	    
	}
If I do something like this, however:

code:
while(field.getFlipped() > 0){
     System.out.print("");
}
it exits properly.


the getFlipped() function returns the proper value, but the original while loop just won't loving terminate when it reaches 0.


I'm about to graduate with a CS degree, and I can't write a while loop properly.
:saddowns:

Jick Magger fucked around with this message at 04:38 on Aug 20, 2010

lamentable dustman
Apr 13, 2007

🏆🏆🏆

Jick Magger posted:

I'm about to graduate with a CS degree, and I can't write a while loop properly.
:saddowns:

no worries, most programmers you meet on the job can't either

kes
Jan 4, 2006

Jick Magger posted:

I feel retarded. I've got a while loop that won't seem to break:

code:
public void runGame(){
		Random generator = new Random();
		int level;
	    for(level = 1; level < 10; level++){
	    	for(int i = level; i >0;i--){
	    		this.flipPieces(generator.nextInt(size), generator.nextInt(size));
	    	}

       //for the love of god work!
	    	while(field.getFlipped() > 0);
       //
	    	repaint();
	    }
	    
	}
If I do something like this, however:

code:
while(field.getFlipped() > 0){
     System.out.print("");
}
it exits properly.


the getFlipped() function returns the proper value, but the original while loop just won't loving terminate when it reaches 0.


I'm about to graduate with a CS degree, and I can't write a while loop properly.
:saddowns:


haha


a customer complained that our code was crashing and sent in a stack trace. it looks something like this:

java.lang.ioexception

at com.apache.log4j.blahblahblah

at com.apache.log4j.blahblahblah1

...

at com.apache.log4j.etc

at our.code.function.call.<init>(ourfile.java:136)

the only problem is we don't use log4j anywhere....and line 136 is a function definition:

136: function( A, B)
137: {
138: return 0;
139: }

i checked A and B and they also do not use any logging in their constructors

what the gently caress is going on, is the stack trace inaccurate or did the customer wreck our code or what. how can our code, which never uses log4j anywhere, be the caller of the log4j functions in the stack trace?

kes fucked around with this message at 05:15 on Aug 20, 2010

Contra Duck
Nov 4, 2004

#1 DAD

Jick Magger posted:

I feel retarded. I've got a while loop that won't seem to break:

code:
public void runGame(){
		Random generator = new Random();
		int level;
	    for(level = 1; level < 10; level++){
	    	for(int i = level; i >0;i--){
	    		this.flipPieces(generator.nextInt(size), generator.nextInt(size));
	    	}

       //for the love of god work!
	    	while(field.getFlipped() > 0);
       //
	    	repaint();
	    }
	    
	}
If I do something like this, however:

code:
while(field.getFlipped() > 0){
     System.out.print("");
}
it exits properly.


the getFlipped() function returns the proper value, but the original while loop just won't loving terminate when it reaches 0.


I'm about to graduate with a CS degree, and I can't write a while loop properly.
:saddowns:

Indent your code properly god drat.

zootm
Aug 8, 2006

We used to be better friends.

kes posted:

what the gently caress is going on, is the stack trace inaccurate or did the customer wreck our code or what. how can our code, which never uses log4j anywhere, be the caller of the log4j functions in the stack trace?
Is the customer using the same build of the code as the one you're looking at? When the line numbers and the stack trace information don't align, it usually means that you're not looking at the correct version of the source file. <init> means that you're looking for code in the initialisation of the object, so either the constructor or some other initialisation value (like the initial value of a field). If the code you're looking isn't in such a block at that line, you're not looking at the code that was compiled to make the system the user is running.

In any case a bunch of libraries use log4j themselves (for a while it was the only game in town) so it's possibly some library trying to use log4j in vain. Obviously log4j is on the classpath somehow (you wouldn't get a stacktrace including it otherwise) so you're either distributing it with your system or it's installed into the user's system somehow. If you're distributing it, it's probably because it's the dependency of some library, which might well be your culprit.

But in general, your next step is to figure out what version of the code the user is using.

zootm
Aug 8, 2006

We used to be better friends.

Jick Magger posted:

the getFlipped() function returns the proper value, but the original while loop just won't loving terminate when it reaches 0.
Not entirely sure what's going on here, but in general:

You're busy-waiting (i.e. spinning) on a value change, which is likely to just make your computer use all its CPU cycles checking a value over and over. This probably means that whichever thread is setting the flipped value barely gets any CPU time. Do you know for a fact that the flipped value ever gets to 0 in the case where this doesn't terminate? How long do you wait? Does some other thread report the value of flipped?

When you put the System.out.println call in it causes an IO operation which will probably yield to the other thread almost immediately, stopping this problem in a bit of a horrid way.

covener
Jan 10, 2004

You know, for kids!

kes posted:


at our.code.function.call.<init>(ourfile.java:136)

the only problem is we don't use log4j anywhere....and line 136 is a function definition:

136: function( A, B)


can you show a less obfuscated backtrace? .<init> is code inserted by the compiler that helps the JVM finds its way to your constructors, but you're showing that it's bolted onto a function call rather than a class even in the exception.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Jick Magger: In addition to what zootm said, I think you're looking at the architecture for this incorrectly.

For every level in the game you randomly set up a board, wait in a polling loop for the level to complete, repaint the board and then generate the next level. It seems like it would make more sense to create a method:

code:
private int level = 1;
private Random generator = new Random();
private void generateLevel() {
  if (level > 9) {
    // show a game over screen or something
  }
  for(int i = level; i >0;i--) {
    this.flipPieces(generator.nextInt(size), generator.nextInt(size));
  }
  level++;
}
That gets called at the beginning of the game and every time you reach the win condition. In general, if you find yourself polling for something, you should consider a different approach.

Jick Magger
Dec 27, 2005
Grimey Drawer
zootm: The value does reach zero, but what you're saying makes sense.

Internet Janitor: Yeah that's a much better way of doing it. I should know better.

Contra Duck: sorry my 8 lines of code weren't perfect for you :C

OddObserver
Apr 3, 2009

Jick Magger posted:


Contra Duck: sorry my 8 lines of code weren't perfect for you :C

Your code wasn't "imperfect" --- it has the sort of indentation that's at most acceptable in the first introductory course and only because the grader is a softy.
If you really produce code like this, and it's not just some weird copy-paste artifact, I weep for people who have to work with you.

Fly
Nov 3, 2002

moral compass

Jick Magger posted:

I feel retarded. I've got a while loop that won't seem to break:

code:
public void runGame(){
		Random generator = new Random();
		int level;
	    for(level = 1; level < 10; level++){
	    	for(int i = level; i >0;i--){
	    		this.flipPieces(generator.nextInt(size), generator.nextInt(size));
	    	}

       //for the love of god work!
	    	while(field.getFlipped() > 0);
       //
	    	repaint();
	    }
	    
	}
If I do something like this, however:

code:
while(field.getFlipped() > 0){
     System.out.print("");
}
it exits properly.


the getFlipped() function returns the proper value, but the original while loop just won't loving terminate when it reaches 0.


I'm about to graduate with a CS degree, and I can't write a while loop properly.
:saddowns:
It might be that getFlipped() is returning a value that is set by another thread, and unless that value is declared as volatile, or there is some synchronization that happens when you call it, your busy loop may continue to see the unchanged version of that variable because the Java memory model specifies that threads can have their own local copies of memory unless the value is declared volatile.

Printing something probably does some synchronization somewhere or makes the thread reload the shared data that is being checked.

edit: tl/dr volatile or synchronized

Fly fucked around with this message at 19:09 on Aug 20, 2010

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe

OddObserver posted:

Your code wasn't "imperfect" --- it has the sort of indentation that's at most acceptable in the first introductory course and only because the grader is a softy.
If you really produce code like this, and it's not just some weird copy-paste artifact, I weep for people who have to work with you.

In Netbeans ALT-SHIFT-F will make you happy.

heat
Sep 4, 2003

The Mad Monk
This is a jython question but I suppose here is as good of a place as any to ask it. I took some programming classes one million years ago so apparently that qualifies me to write custom scripts at work :rolleyes: I'm using KNIME to convert some databases, and what I need to do is find any row that has a value greater than 1 in the column "Block" and make x copies of that row where x is the value of the cell. I've sort of mashed this together in a JPython node:

code:
dts = inData0.getDataTableSpec()
inputColumnIndex = dts.findColumnIndex("Block")
iterator = inData0.iterator()

while iterator.hasNext():
	row = iterator.next()
	cell = (row.getCell(inputColumnIndex)).getIntValue()
	while cell > 1:
		outContainer.addRowToTable(row)
		cell = cell - 1
The problem I can't seem to solve is this error: org.knime.core.util.DuplicateKeyException: Encountered duplicate row ID "Row14" at row number 4

Elsewhere in KNIME when two tables are being concatenated there is an option to append a suffix onto duplicate row keys, but I don't know how to do it here. For all I know I could solve that problem and it still won't run, so any help at all would be greatly appreciated. Thanks!

lamentable dustman
Apr 13, 2007

🏆🏆🏆

MEAT TREAT posted:

In Netbeans ALT-SHIFT-F will make you happy.

ctrl+shift+f in eclipse

Adbot
ADBOT LOVES YOU

kes
Jan 4, 2006

zootm posted:

Is the customer using the same build of the code as the one you're looking at? When the line numbers and the stack trace information don't align, it usually means that you're not looking at the correct version of the source file. <init> means that you're looking for code in the initialisation of the object, so either the constructor or some other initialisation value (like the initial value of a field). If the code you're looking isn't in such a block at that line, you're not looking at the code that was compiled to make the system the user is running.

In any case a bunch of libraries use log4j themselves (for a while it was the only game in town) so it's possibly some library trying to use log4j in vain. Obviously log4j is on the classpath somehow (you wouldn't get a stacktrace including it otherwise) so you're either distributing it with your system or it's installed into the user's system somehow. If you're distributing it, it's probably because it's the dependency of some library, which might well be your culprit.

But in general, your next step is to figure out what version of the code the user is using.

that was the conclusion i reached too. as it turns out, apparently they threw away the custom code we wrote for them and went back to the stock product, so i was looking at the wrong stuff. but nobody told me.

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