|
I completely agree with what you are saying, I'm just saying that as far as I understand the problem, he needs to permute a list of distinct integers (or objects) to seed a tournament. You can't have the same team playing twice at the same stage, or leave teams out. Like I say I might be completely misunderstanding him. I think #cobol (who uses IRC in this day and age?!) probably suggested he shuffle an array to get around this without noticing that he had his Random inside the loop. There are other ways to achieve this, I was just showing him how to use Collections.shuffle(). oh no computer fucked around with this message at 20:36 on Nov 4, 2008 |
# ? Nov 4, 2008 20:32 |
|
|
# ? May 11, 2024 16:29 |
|
BELL END posted:I completely agree with what you are saying, I'm just saying that as far as I understand the problem, he needs to permute a list of distinct integers (or objects) to seed a tournament. You can't have the same team playing twice at the same stage, or leave teams out. Like I say I might be completely misunderstanding him. If that's the problem to be solved then that makes perfect sense. I think I might have skipped over the "tournament" part and focused on the "random" - if he truly wants randomly placed distinct integers, the shuffle you posted is definitely the way to go and the Random should've been taken out of consideration entirely. #cobol really dropped the ball here <> quote:#cobol (who uses IRC in this day and age?!) I do, when my cable modem can go five minutes without pissing itself
|
# ? Nov 4, 2008 20:46 |
|
Shuffling should solve the problem. Here's what my output looks like now:code:
code:
|
# ? Nov 4, 2008 20:56 |
|
The Light Eternal posted:Shuffling should solve the problem. Here's what my output looks like now: Do exactly what BELL END posted, starting at 1. e: unless you're trying to describe some hidden pattern, I can't tell if that '6 7 8' at the end was intentional. What precisely is it that you want? BELL END's method will get you a sequence of numbers from 1 to num, inclusive, that are shuffled randomly.
|
# ? Nov 4, 2008 21:01 |
|
csammis posted:Do exactly what BELL END posted, starting at 1. I made some minor changes to fix all the errors. code:
|
# ? Nov 4, 2008 21:05 |
|
List is an interface, you can't instantiate it. What errors was my code throwing out of interest?
|
# ? Nov 4, 2008 21:12 |
|
The Light Eternal posted:What do I put for the second List? I'm getting an error there that says something about List being a parameterized type. What second list? There's only one in the code you posted. Is it a compiler error or an exception? Copy and paste it here. e: Oh code:
|
# ? Nov 4, 2008 21:13 |
|
BELL END posted:List is an interface, you can't instantiate it. What errors was my code throwing out of interest? ArrayList cannot be resolved to a type.
|
# ? Nov 4, 2008 21:14 |
|
The Light Eternal posted:I made some minor changes to fix all the errors. The error about List being parameterized is that you'll have to write new List<Integer>(num), because List expects a type parameter and Java has no mechanism for inferring them from context. Except you'll actually have to write something like new ArrayList<Integer>(num), because as BELL END wrote, List is not a concrete implementation: it's just an abstract interface. EDIT: and you'll need to add import java.util.ArrayList; to the top of your file.
|
# ? Nov 4, 2008 21:15 |
|
The Light Eternal posted:ArrayList cannot be resolved to a type. Make sure you're importing java.util, and also using Java 5 or higher. ArrayList javadoc.
|
# ? Nov 4, 2008 21:15 |
|
csammis posted:Make sure you're importing java.util, and also using Java 5 or higher. Awesome, the program works perfectly. Thanks everyone for your help.
|
# ? Nov 4, 2008 21:45 |
|
I'm beating my head into the wall trying to figure out what I'm doing wrong here. Check this out:code:
|
# ? Nov 5, 2008 22:18 |
So i'm working on a highway routing problem and it's looking fairly unavoidable that i'm going to be creating somewhere upwards of 300,000 objects (for the NY map, let alone the US) representing intersections that will be shrunk to allow faster queries. I have heard variously that this is a bad idea in java--object creation has a large overhead and the garbage collector will go crazy trying to keep track of everything. What can be done to ameliorate this? Should I just go ahead and create objects for the new virtual intersections (that represent an aggregate of multiple real intersections) and call finalize() each time an intersection gets concatenated onto another? Can I allocate memory that is beyond the reach of the garbage collector and do my own memory management?
|
|
# ? Nov 6, 2008 00:20 |
|
huge sesh posted:So i'm working on a highway routing problem and it's looking fairly unavoidable that i'm going to be creating somewhere upwards of 300,000 objects (for the NY map, let alone the US) representing intersections that will be shrunk to allow faster queries. I have heard variously that this is a bad idea in java--object creation has a large overhead and the garbage collector will go crazy trying to keep track of everything. In order (for me, at least) to help in any real capacity, can you answer these questions: How large are the objects? How much RAM do you have to work with? Do you predict these objects will be very short lived or will they persist throughout the life of the appplication? Also, is this a desktop, server or mobile app?
|
# ? Nov 6, 2008 00:28 |
|
XRoja posted:I'm beating my head into the wall trying to figure out what I'm doing wrong here. Check this out: It seemed to work fine for me... I replaced your "chrom = m.group()" with "System.out.println(m.group())" and it printed "10".
|
# ? Nov 6, 2008 01:10 |
TRex EaterofCars posted:Who told you this? Any modern jvm is very very good at creating objects and keeping gc to minimum. This is a desktop app running on machines with probably at most 4 gigs of space. I just checked and apparently the USA map has 23 million intersections. These objects will be short-lived -- as soon as i'm finished with each map contraction step I can aggregate them into a single object. anyways, I'll go ahead and proceed with the naive implementation and see how that works with NY and the US.
|
|
# ? Nov 6, 2008 01:29 |
|
huge sesh posted:This is a desktop app running on machines with probably at most 4 gigs of space. I just checked and apparently the USA map has 23 million intersections. These objects will be short-lived -- as soon as i'm finished with each map contraction step I can aggregate them into a single object. anyways, I'll go ahead and proceed with the naive implementation and see how that works with NY and the US.
|
# ? Nov 6, 2008 12:32 |
|
My professor has me doing his sweat shop programming to help his 120 class that are using GameMaker (long story/school sucks). Basically, he wants me to write the chapter examples in the gamemaker book in java. The last one he's given has a guy that runs around an environment top/down style and what you see in the screen is relative to the position of the character. Is it possible to have a JFrame the size of the screen with a JPanel the size of the level and just have the JPanel repainted in the JFrame to a certain point? It's hard to describe what I'm asking, but if you think about a roguelike, the character approaches the side of the screen but the level shifts over so you can see more to one side. I'm basically trying to recreate this in Java but am not sure how to do the moving environment thing with JFrame/JPanel/JWhatever.
|
# ? Nov 9, 2008 03:27 |
|
poemdexter posted:Is it possible to have a JFrame the size of the screen with a JPanel the size of the level and just have the JPanel repainted in the JFrame to a certain point? It's hard to describe what I'm asking, but if you think about a roguelike, the character approaches the side of the screen but the level shifts over so you can see more to one side. I'm basically trying to recreate this in Java but am not sure how to do the moving environment thing with JFrame/JPanel/JWhatever. I've never done exactly this, but try using JViewport, which is designed to do this sort of thing inside scrolling panes.
|
# ? Nov 9, 2008 06:45 |
|
I think I'm having a very fundamental misunderstanding about Java. I have a servlet which calls another class in a neighboring JAR. The first time this is executed, everything works great, and my output stream is returned to the caller perfectly. Any subsequent requests have problems though. The servlet call goes fine, but once the other class is called, problems are found and my application fails. If I restart Tomcat, execute again, everything is fine until I submit again. So, I think this is a java class perhaps never picking up after itself and staying instantiated(?). If that's the case, how do I kill it upon successful completion?
|
# ? Nov 11, 2008 02:37 |
|
mister_gosh posted:I think I'm having a very fundamental misunderstanding about Java. You'll have to be more specific than that. Post the code, and the exact text of the error. An instance of a class *can* stay instantiated, but that means you have to be holding on to a reference somewhere. Sometimes this is what you want, sometimes it isn't. (Edit: technically speaking an instance with no references to it can still be sitting around before the garbage collector gets to it, but if your code doesn't still have a reference to it, it shouldn't be able to use it, so you should be able to ignore this situation.) Actually, in addition to posting your code, you should also post a plain English description of what you *think* it does. It sounds like the sort of problem where you are writing code and expecting it to DWIM. Mill Town fucked around with this message at 11:23 on Nov 11, 2008 |
# ? Nov 11, 2008 11:18 |
|
Thanks, for suggesting I post the code, I thought perhaps I was missing something very fundamental, maybe I still am(?). Anyways, I've tried to take out all of the fluff, log4j, comments and variable declarations that didn't make sense to post (for example, retMsg is declared and instantiated). The servlet: code:
code:
|
# ? Nov 11, 2008 15:17 |
|
Where are you declaring a new ContentGetter?
|
# ? Nov 11, 2008 15:35 |
|
TRex EaterofCars posted:Where are you declaring a new ContentGetter? As already stated, I tried to take out the fluff, such as variable declarations. I can tell that it is at the line marked HERE that it fails, based on my log4j output which I've also removed.
|
# ? Nov 11, 2008 15:38 |
|
mister_gosh posted:As already stated, I tried to take out the fluff, such as variable declarations. I can tell that it is at the line marked HERE that it fails, based on my log4j output which I've also removed. But that particular variable declaration might not be fluff. The only thing I can see that this could even possibly be is a scoping issue.
|
# ? Nov 11, 2008 15:50 |
|
TRex EaterofCars posted:But that particular variable declaration might not be fluff. The only thing I can see that this could even possibly be is a scoping issue. Well, it actually calls another class which does the getContent call. In my servlet, it looks like this: code:
From my standpoint, I'm wondering if I am cleaning up the servlet code properly, because if I restart Tomcat, it'll work again (one time only). I've verified that the 3rdPartAPICall is flushed and created new each time (their class has a method which properly exits the call/connection) and that I can properly call other various methods on that 3rd party object, it is a problem specifically when I execute the particular method marked at HERE. So I guess if I am cleaning up properly, it is actually their problem (which they won't admit to).
|
# ? Nov 11, 2008 16:08 |
|
Are you running on an application server such as JBoss? Also, what's the exact error or exception you get? There should be a stacktrace somewhere which tells what went wrong, and that will go a long way towards solving your problems.
|
# ? Nov 11, 2008 16:11 |
|
code:
|
# ? Nov 11, 2008 16:32 |
|
If you're interfacing with native code, make sure that you're using the code exactly like the authors intended. For instance if the library authors just translated some code over using the idioms of the other language without modification, you may be expected to call some cleanup code after every invocation.
|
# ? Nov 11, 2008 17:29 |
|
1337JiveTurkey posted:If you're interfacing with native code, make sure that you're using the code exactly like the authors intended. For instance if the library authors just translated some code over using the idioms of the other language without modification, you may be expected to call some cleanup code after every invocation. Yeah, I'm guessing 3rdPartAPICall is an object that calls the perl script, yes? Is it a member of a class you've written or is it some pre-existing interface? If it's your own class, post its code too. If it's something someone else wrote, what is the library called and where can we download it or see its documentation? Also, you should really put the variable declarations back in so we can see where things go in and out of scope.
|
# ? Nov 11, 2008 21:54 |
|
Hey guys, I'm basically a pascal / C kinda guy, and I've just had this java applet planted on me. It has a bug, which I have narrowed down by decompiling (DJ) one of the class files in a cab file. Naturally, all the strings are named systematically, and I have no idea where the values I'm looking for are. (There are many global variables) What are my options for debugging a java applet that's already been "compiled"? Sorry for my blinding ignorance.
|
# ? Nov 11, 2008 22:56 |
|
Fruit Smoothies posted:Hey guys, I'm basically a pascal / C kinda guy, and I've just had this java applet planted on me. It has a bug, which I have narrowed down by decompiling (DJ) one of the class files in a cab file. A .cab file? That's new to me. Usually applets are deployed as .jar files. Nevertheless, you could make a project in NetBeans or Eclipse with nothing of its own but containing the .jar file as a library. You can then navigate to the class files in the source tree and they should show the information available at link time and at run time for every single class. Then set the IDE to run the applet, and you should be able to use the debugger, although it may not give much in the way of useful information. The class you want to run as an applet can be found from the tag used to embed the Applet in the web page. quote:Naturally, all the strings are named systematically, and I have no idea where the values I'm looking for are. (There are many global variables) OK, from your use of the term global variables, it sounds like you're thinking of things in a C/Pascal way. There are a million tutorials out there, but for the moment, you can think of objects like records and classes as types of records. I can go into more detail later and answer any questions you might have as well. quote:What are my options for debugging a java applet that's already been "compiled"? Outside of decompiling like you have, the NetBeans/Eclipse project I mentioned earlier has another use. You can get all that information from the .class files because Java keeps it around so that it can dynamically link everything. That means you can also make your own code that links against those class files and verifies that they do what you think they do. quote:Sorry for my blinding ignorance. You're doing pretty good for not knowing the language or having the source, actually.
|
# ? Nov 12, 2008 02:34 |
|
1337JiveTurkey posted:A .cab file? That's new to me. Usually applets are deployed as .jar files. It seems that the jar file has everything in it, including the buggy code. Lord knows why I was sent the .cab file. 1337JiveTurkey posted:...set the IDE to run the applet, and you should be able to use the debugger, although it may not give much in the way of useful information. The class you want to run as an applet can be found from the tag used to embed the Applet in the web page. Does Eclipse offer step-through debugging? My only concern is that the code is actually client / server, and the server expects a reply within a certain time, or there's a disconnection that occurs. Perhaps I'll have to modify the code to write the values to a file for later inspection? Or simply echo them out somewhere. quote:OK, from your use of the term global variables, it sounds like you're thinking of things in a C/Pascal way. What I meant was, I couldn't run the isolated code, because the variables is uses are obviously found elsewhere in the library. As I said, it's client / server so the values the functions see varies. EDIT: Do I want Eclipse for java EE, or just for Java? Fruit Smoothies fucked around with this message at 13:59 on Nov 12, 2008 |
# ? Nov 12, 2008 13:56 |
|
Fruit Smoothies posted:Does Eclipse offer step-through debugging? Fruit Smoothies posted:EDIT: Do I want Eclipse for java EE, or just for Java?
|
# ? Nov 12, 2008 15:33 |
|
Ok, so I downloaded Eclipse, and I imported the jar file into a library, however it doesn't seem to be decompiling or showing the functions within. Is this supposed to happen? Or do I need to use the decompiled versions? EDIT: When I open it, it says damaged / corrupt. Fruit Smoothies fucked around with this message at 16:15 on Nov 12, 2008 |
# ? Nov 12, 2008 16:12 |
|
Fruit Smoothies posted:Ok, so I downloaded Eclipse, and I imported the jar file into a library, however it doesn't seem to be decompiling or showing the functions within. Is this supposed to happen? Or do I need to use the decompiled versions? Make sure that instead of opening it, you're importing it into the project. Go to the File menu, then select Import... and then from the list of options, select import archive and pick the .jar file. If that doesn't work and you can extract everything by unzipping it, then you can just import the directory tree containing the .class files. You should then see the folders under your package manager and you can look at the specific classes. Since it can't match them back to a source file you'll get something saying Source not found but then it'll list some data like: code:
|
# ? Nov 12, 2008 16:31 |
|
Yea I managed to get them listed. How does this help with debugging though, if I can't see specific source lines? Incidentally, I have exported .java files with "complete" source. Will this help? EDIT: When I select "run as -> Applet" i get "No applet". How can this be fixed? I assume it has something to do with the class param in the HTML?
|
# ? Nov 12, 2008 16:35 |
|
He was saying to do that so you can figure out the global variable names better. Once you add the jar to the classpath of your project it should show up in the left pane. You should be able to explore the classes inside it. Once you import one of those classes to a new class you can use the code completion feature to get more meaningful global variable names. You obviously won't get the local names though. Just out of curiosity, how do they expect you to fix the bug without the original source code? Doesn't make sense.
|
# ? Nov 12, 2008 17:25 |
|
dvinnen posted:He was saying to do that so you can figure out the global variable names better. Once you add the jar to the classpath of your project it should show up in the left pane. You should be able to explore the classes inside it. Once you import one of those classes to a new class you can use the code completion feature to get more meaningful global variable names. You obviously won't get the local names though. Ahh I see about the variable names now. As it turns out, the variable names in the class file are already systematic-like, and offer no help what-so-ever. And I was under the impression that decompiling was 100% accurate with java? (since it's not completely compiled)
|
# ? Nov 12, 2008 18:45 |
|
|
# ? May 11, 2024 16:29 |
|
Kinda sorta. It's in between a scripting language and a full compile I guess. Java is compile down to byte code. This does make decompiling easier but not 100% accurate. Comments are striped of course and I'm sure other optimizations are performed on the code. Variable names are changed to become more machine friendly. The decompiler makes due with these by assigning the variables the same name as the class name.
|
# ? Nov 12, 2008 18:59 |