|
OK. The easiest way to do this is to break it up into two problems. First you need to distinguish where the start and end of a parseable command is. If the user is pressing enter after each command, then you really want to just get the next line rather than searching for tokens. There are several ways to do this, but one of the simpler ways is to just take System.in and then wrap it in a InputStreamReader and then a BufferedReader like so:code:
|
# ? Feb 20, 2009 06:04 |
|
|
# ? May 9, 2024 05:27 |
|
rileylolz posted:For class, we've been assigned to make an 8x8 board for various pieces to move around on. I've run into a problem with user input, specifically dealing with how to handle tokens. I'm using Scanner to break up the input, but the problem is the largest command will have 5 tokens and the shortest will only have one. The way it's set up now is that it needs a command that will use all 5 tokens or else it crashes. Lazy way would be to catch the exception and ignore it. The more proper way would be to have a count=0 outside of the switch statement. Then have a switch statement based off what count it is. After the switch increment the count. You could probably get rid of the loop also with a series of ifs as well. You would check hasNext() and if true whatever equals next()
|
# ? Feb 20, 2009 06:05 |
|
Slimy posted:In C++, I'd just have the implementation of getArrayListByType() return a pointer to foo and bar, which I could dereference. Why bother to use a switch at all? Why don't you use a List<List<Message>>?
|
# ? Feb 20, 2009 06:06 |
|
Slimy posted:The problem is in clearMessageArray() (check the comment). What I'm really looking for is an implementation of getArrayListByType() that will actually return me something that can be used to modify foo and bar. You're just encountering problems because you're attempting to solve the problem using methods idiomatic to C++, it's easily done! Here's another implementation: code:
|
# ? Feb 20, 2009 13:01 |
|
Since it's static anyway... :code:
|
# ? Feb 20, 2009 14:43 |
|
Hi guys, I'm using Eclipse at work to do Java web dev. The previous programmer left a lot of useless (and now abandoned) poo poo going to System.out. There are thousands of lines of System.out to search through, many of them are valid. But there are also some annoying ones that happen without fail every 10-15 seconds and result in 09:37:45,585 INFO [STDOUT] null. Very useful. Is there any way I can set a breakpoint on System.out.println? I figure if I had the JDK source code loaded, I could set a breakpoint on entry to that method, but I don't.
|
# ? Feb 20, 2009 15:41 |
|
Pivo posted:Hi guys, I'm using Eclipse at work to do Java web dev. You can't Ctrl+Click into the method and see its source? I just have the standard 1.6 JDK and plain-jane Eclipse 3.4 and I can enter all of Java's standard classes.
|
# ? Feb 20, 2009 16:08 |
|
TRex EaterofCars posted:You can't Ctrl+Click into the method and see its source? I just have the standard 1.6 JDK and plain-jane Eclipse 3.4 and I can enter all of Java's standard classes. Nope... Maybe the source search path isn't correct. Let me see if the files are actually on my system.
|
# ? Feb 20, 2009 16:29 |
|
Slimy posted:The problem is in clearMessageArray() (check the comment). What I'm really looking for is an implementation of getArrayListByType() that will actually return me something that can be used to modify foo and bar. What's wrong with doing code:
EDIT: Pivo posted:Nope... Maybe the source search path isn't correct. Let me see if the files are actually on my system.
|
# ? Feb 20, 2009 16:43 |
|
Lysidas posted:EDIT: Heh, was just coming back to say I did exactly this and it fixed it. Thanks
|
# ? Feb 20, 2009 16:45 |
|
i haven't written code for a couple months, so forgive me if im doing something incredibly stupid. what im trying to do is populate an array with all different random numbers. here is my code:code:
|
# ? Feb 21, 2009 00:06 |
|
code:
|
# ? Feb 21, 2009 00:09 |
|
god. loving. damnit. thanks man.
|
# ? Feb 21, 2009 00:14 |
|
That can be painfully slow if the number of items increases much beyond where it is. If you're looking for a shuffled list of numbers, then this should be what you need:code:
|
# ? Feb 21, 2009 00:46 |
|
Lysidas posted:EDIT: As a follow-up, it looks like a class called Logger intercepts stdout so the JDK println is never even called. And, of course, I don't have the source code for the logger. Honestly I've never done webdev in Java before this, anyone have any good links for a quick rundown of logging systems in JBoss? Nearly half of our server logs are [STDOUT] null and the logger logging messages about the logger.
|
# ? Feb 21, 2009 01:25 |
|
Pivo posted:As a follow-up, it looks like a class called Logger intercepts stdout so the JDK println is never even called. And, of course, I don't have the source code for the logger. Honestly I've never done webdev in Java before this, anyone have any good links for a quick rundown of logging systems in JBoss? Nearly half of our server logs are [STDOUT] null and the logger logging messages about the logger. Do you know the package Logger is in? I'll bet it's log4j or Apache Commons' Logger.
|
# ? Feb 21, 2009 01:30 |
|
TRex EaterofCars posted:Do you know the package Logger is in? I'll bet it's log4j or Apache Commons' Logger. You're quick on the draw mang. I'll have to get back to you on that, but I know it's not log4j from my experience with red5. The "logger logging about the logger" is like this: code:
I'm not at work right now so I don't have any additional info, but I sure would like to clean up our logs since I'm the one who sifts through 'em.
|
# ? Feb 21, 2009 01:41 |
|
JBoss uses the Log4J logging framework. You can find the configuration file for it in the config directory of your server. If you're just looking for calls to System.out, just make a subclass of PrintStream that wraps the real/current System.out and sends everything to it instead. Remember: System.out isn't final so you can replace it with whatever you want. You can set a breakpoint there or you can just create a Throwable, getStackTrace() it and get the second element. That's got the class, method, file name and line number (if you compiled those in) for whatever printed to System.out. edit: If you find the Log4J config file, you can filter specific packages IIRC so you can at least shut those ones that constantly spam poo poo in debug mode up.
|
# ? Feb 21, 2009 01:43 |
|
Hah. Remote Desktop to the rescue... It IS log4j! Thanks a lot. Coming from primarily PHP and Python, stuff's so different over here!
|
# ? Feb 21, 2009 01:49 |
|
Hey Pivo, a really good Java tip I have for you is to ALWAYS google for the names of classes or messages displayed when programs throw stack frames. I just googled for "com.arjuna.ats.arjuna.logging.arjLogger" and found a whole bunch of people who asked the same question you did about excessive logging, right on the first page.
|
# ? Feb 21, 2009 02:40 |
|
Hey TRex, guess what page of Google I pulled that log-quote from? Oh and by the way, my question was only tangentially related to the topic of those particular log entries! I work for a company that provides online tutoring to children in need. We tutor adults, as well. Would you be interested in learning about our services? Our English tutors are phenomenal! Pivo fucked around with this message at 04:27 on Feb 21, 2009 |
# ? Feb 21, 2009 04:23 |
|
Thanks for the responses. As to why the code was written the way it was, I have no idea. I just went in to fix a bug, and was hoping to modify as little code as possible (which would have been the method I tried to use, had there been a Java equivalent). However, I ended up biting the bullet, and re-implementing it as a List of ArrayList<Message>'s. And, Jesus Christ, did that simplify the class. Nearly every method in that class has a switch statement based on 'type' (of which there were 5, not the 2 I had in my example), all with nearly identical code.
|
# ? Feb 21, 2009 05:25 |
|
Pivo posted:Hey TRex, guess what page of Google I pulled that log-quote from? Oh and by the way, my question was only tangentially related to the topic of those particular log entries! Kid, I can't read your mind. I thought those were the actual log messages your program generated. Maybe if you were concise about the problem, we wouldn't be having this little exchange. In any event, gently caress you. If you're gonna act like a noob and then get all bent out of shape when someone gives you a tip, perhaps you should learn how to solve simple problems like this on your own.
|
# ? Feb 21, 2009 15:17 |
|
Pivo posted:Hey TRex, guess what page of Google I pulled that log-quote from? Oh and by the way, my question was only tangentially related to the topic of those particular log entries!
|
# ? Feb 21, 2009 18:05 |
|
Hello all, I'm having some difficulties with some extremely basic Java programming. This is regarding creating your own class and using a driver with it. Here's a zip containing all the files regarding this program... http://bioshacker.googlepages.com/project2.zip I don't even know if I have my class (GiftOrder.java) completed correctly. It compiled correctly, but I'm just not sure if I did calcSubTotal, calcTax, or calcOrderTotal correctly. I definitely have no clue what question 5 and 6 (within Project2.java) want from me. What's the command to get the invoice to display? I can't figure it out. Ugh. I'll post the code here as well. The first code is the class, GiftOrder.java, and the second code is the driver, Project2.java. Thanks to anyone who is willing to help. code:
code:
|
# ? Mar 2, 2009 18:33 |
|
Question 6 is just asking you to use the set methods for bows, ribbons and whatever to the iNumBows as captured from the user. Once these are run then the invoice can be calculated based on the class variables. The calculateInvoice() method returns a string. You know how to output a string to screen, so just output the return value of calculateInvoice().
|
# ? Mar 2, 2009 19:37 |
|
We have several different web applications at work in which we use custom tags. In each application, we have a tld file, and the associated java code. The problem is that in a lot of cases, the tags are exactly the same across all the applications, so the code has been copied from application to application. I would like to have a single custom tag library that can be accessed from all the different applications. However, all the custom-tag documentation and examples that I find just show how to do it by sticking a tld into the web-inf folder of the application you're going to use it from. I'm assuming that I can create an external tag library, since Struts and JSTL are external. Can anyone point me in the right direction to figure out how to do this?
|
# ? Mar 2, 2009 22:14 |
|
We're going to move to Java for our web development here at the office and I've just finished taking a boatload of Java courses over the past two months. My head is spinning. We're on Oracle for the backend and using JDeveloper as our IDE. What I can't decide on is the multitude of frameworks both for the model and view parts of our work. For the front end I like JSF but right now it seems to involve a lot of "magic" and I'm not sure how flexible it'll be. We do some odd things in our web app right now because the data we need to show is complex. Struts looks neat but everyone seems to think its going by the wayside. Oracle ADF on JSF looks like ASP. On the back end I'm still trying to figure out exactly what the difference is between TopLink and EJB 3.0, aside from a better GUI in JDeveloper for the former. Oracle BC looks neat but again gives me that unsettling feeling that we'd be locking into the Oracle game for another decade. I'm really stuck here picking out the best. For some history, our web applications were all developed by myself using Oracle PL/SQL. Its a procedural language using packages compiled into the DB and its required me to hand build pretty much everything from scratch, including a sort of homebrew MVC framework. I feel like some sort of old timey watch maker compared to the massive amount of tools that JavaEE is offering. Any ideas?
|
# ? Mar 3, 2009 06:31 |
|
I recently spent some time trying to figure this out for myself. In the end I decided to go with Spring and Hibernate as the frameworks I was going to learn. As far as I can tell it looks like Spring solves a lot of the problems inherent in ejb3. Just about everywhere I looked hibernate had much more adoption than toplink. The main reason for my decision is the speed at which development could occur with spring and the fact that both products seem to have a large following out there on the net. Basically I know I can get help with hibernate. Toplink? Not so much. Edit: I've only scratched the surface of the available java frameworks. I come from a ruby on rails background where development speed, ease of use, and the community are a big deal. I looked for these qualities when delving in to the java world. Ghotli fucked around with this message at 02:22 on Mar 4, 2009 |
# ? Mar 4, 2009 02:18 |
|
Ghotli posted:Edit: I've only scratched the surface of the available java frameworks. I come from a ruby on rails background where development speed, ease of use, and the community are a big deal. I looked for these qualities when delving in to the java world. I'm gonna sound like a broken record but Grails is Java's answer to ROR... unless you just want to run ROR on JRuby.
|
# ? Mar 4, 2009 03:22 |
|
I've actually read quite a bit about grails and jruby and in my opinion both technologies just aren't mature enough yet. I've tried my hand at both and it seemed like I couldn't find help when I ran into road blocks. Either the documentation was shotty (or missing) or the blog and irc communities of people actively hacking away and solving problems in each framework were too small to yield good google results. Frankly I think both technologies will be great when they get more large scale support. To a certain extent this has already happened with jruby. The documentation has been much better since Sun decided to invest money in it's development. With the upcoming releases of jruby 1.2, rails 2.3, and ruby 1.9 it's looking like each project has done alot to support the others. I think this will in turn foster a larger community of people using the technology. I've been considering trying my hand at deploying some of my apps to glassfish or jboss. I tried this about 8 months ago and ran into a ton of problems. I hear it's much easier these days. In the end I went with spring because of these kinds of shortcomings. It seemed like it had the most active community around one of the more well thought out modern java frameworks. That and I found lots of job postings looking for spring/hibernate experience. It seemed like a worthy framework to invest in these days. Not something that's going to go away anytime soon.
|
# ? Mar 4, 2009 04:22 |
|
Thank you for the feedback. Assuming that I'd have to stick with JDeveloper and lie close to the warm bosom of Oracle approved technologies, which would you choose for the view: JSF or Struts+JSP?
|
# ? Mar 4, 2009 05:45 |
|
I'm writing a program which is supposed to read a "maze" of characters in from a file and try to navigate it. The maze has two different character types, one of which is considered a valid path, the other a "wall". I've written the entire program, but when I go to test it, the method I wrote to navigate the maze doesn't do what I need it to; I know this because when a cell in my maze array has been visited, the value stored there is replaced by a 3, and at the end, if the cell is part of the valid path from the top left corner to the bottom right corner, the value stored in that cell is supposed to be replaced by a 7 (all the cells in the valid path become 7 via backtracking). The code for the navigating method and my main method are below.code:
code:
|
# ? Mar 4, 2009 18:05 |
|
First, you're checking if the value in the current cell is equal to the value in the final cell, not whether the coordinates are equal. Second, your algorithm is wrong for several reasons. Third, this function will overflow the stack on long solution paths, even if you patch the algorithm to work.
|
# ? Mar 4, 2009 19:07 |
|
I'm working on an Android app for reading books that are encrypted text files. The files are encoded using 256bit AES, however in the examples I can find, when opening the file they read the file bit by bit - and the app just sits there while loading the file (the file is around 600Kb) I'm wondering, is there a more efficient way to do this? code:
|
# ? Mar 5, 2009 00:20 |
|
I have a question about Java nanoTime. I'm trying to use it to measure the running time of some code and most of the time it returns a value around 130,000, but sometimes it returns values around 3,750,000 or -3,750,000. I'm running a dual core processor on windows and my only theory is that the dual core is messing up the nanoTime call somehow. Any ideas on what is happening/how to fix it?
|
# ? Mar 5, 2009 05:59 |
|
Moon Whaler posted:I have a question about Java nanoTime. I'm trying to use it to measure the running time of some code and most of the time it returns a value around 130,000, but sometimes it returns values around 3,750,000 or -3,750,000. I'm running a dual core processor on windows and my only theory is that the dual core is messing up the nanoTime call somehow. Any ideas on what is happening/how to fix it? nanoTime makes no guarantees about the *accuracy* of the time, only the *precision*. Meaning, you can't use System.nanoTime() to actually get an accurate measure of the current time, but the difference between two calls to nanoTime is the most precise elapsed time measurement possible in Java.
|
# ? Mar 5, 2009 06:09 |
|
dancavallaro posted:nanoTime makes no guarantees about the *accuracy* of the time, only the *precision*. Meaning, you can't use System.nanoTime() to actually get an accurate measure of the current time, but the difference between two calls to nanoTime is the most precise elapsed time measurement possible in Java. Yeah but telling me my program finishes 3ms before it starts seems a little off Edit: Yeah, i'm subtracting the time before from the time after, it just sometimes gives negative results Moon Whaler fucked around with this message at 06:17 on Mar 5, 2009 |
# ? Mar 5, 2009 06:15 |
|
I'm trying to write a program which can deal out five card poker hands to two players, evaluate them according to the rules of poker and determine the winner. I don't really care about optimization or anything, I just want it to work and not contain any programming atrocities. I realize there are some extremely efficient/complex ways to do this better, but I'm doing it as a learning project. I'm having a real hard time getting it to determine the winner when two hands are the same rank and it comes down to kickers to determine the winner. I'm having trouble coming up with even a gross brute force type algorithm to do all this. Here are two of the classes I'm having trouble with: http://pastebin.com/m2d9aca3d I'm really new at programming and especially new at java. I'm not really sure what the best ways set things up are when it comes to using class methods or object methods and all that. Any help would be greatly appreciated!
|
# ? Mar 5, 2009 09:06 |
|
|
# ? May 9, 2024 05:27 |
|
Moon Whaler posted:Yeah but telling me my program finishes 3ms before it starts seems a little off Is it possible that the data type you're using to store the nanoTime result (or the subtraction result) is overflowing and wrapping?
|
# ? Mar 5, 2009 17:08 |