|
ComptimusPrime posted:Thank you. That did the trick. And I'm sure that tidbit will help me a whole hell of a lot in the future. Just so that you know, if you really do need that kind of precision in your calculations checkout the BigDecimal class.
|
# ¿ Oct 6, 2009 00:56 |
|
|
# ¿ Apr 26, 2024 08:52 |
|
The reason you won't see too many operations with floats is because of the constant casting you have to do since Java treats all literal floating point numbers as doubles. If you mix a float with a double it will return a double because if will convert the float to a double to do the operation. But it won't convert the result back down to a float because of the possible loss of precision, so you have to do it manually with a cast. Here's a quick example. If you just write 2.5 Java treats it as a double, you have to either cast it to a float or append an f to the end 2.5f. If you aren't careful you can do things like like this. code:
Here is some more reading if you are interested. http://mindprod.com/jgloss/floatingpoint.html
|
# ¿ Oct 6, 2009 08:23 |
|
karuna posted:Ok I think I'm understanding you, is there an issue with casting the Math.random()?
|
# ¿ Oct 15, 2009 23:50 |
|
In one of my classes they had us make a multi threaded expression solver. It was really neat because it entailed finding all the parts of the expression that could be solved independently, then solving them, and then putting it all back together again.
|
# ¿ Oct 17, 2009 02:46 |
|
I was going to say that I've never found a use for a LinkedList over an ArrayList, but then I remembered that it implements the queue and deque interfaces.
|
# ¿ Nov 10, 2009 22:37 |
|
Compiling from the command line is loving annoying. I suggest you use an IDE or learn to use Ant/Maven to do your compiling for you.
|
# ¿ Nov 17, 2009 21:41 |
|
LOL no, but it only gets worse as your project grows in size and I feel it's valuable to learn it sooner rather than when you really need it and are pressed for time.
|
# ¿ Nov 18, 2009 01:14 |
|
code:
|
# ¿ Jan 26, 2010 19:03 |
|
I have no loving clue how that helps you.... that just simulates rolling a dice. Use this InternetJanitor posted:Random randy = new Random(); Or this which is probably what he would expect. InternetJanitor posted:double value = ((Math.random() * 2) -1); e: I just remembered I had this exact same assignment but it was on problem on our test and no one had a clue how to solve it.
|
# ¿ Jan 30, 2010 19:28 |
|
Parantumaton posted:One gotcha I'd like to mention, Entry contains apparently only weak references to the key and value it holds so the following code may throw NPE if you get a bit unlucky with GC: This is the first I've ever heard of these, how interesting. http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html
|
# ¿ Feb 4, 2010 19:57 |
|
Hey guys I have a question about GlassFish that I can't really find the answer to. I just want to clarify if it's necessary to use a load balancer with a cluster. What happens when I try to just access the cluster without a load balancer? Or is that not even possible, I would have to specify a specific server? In the case that it is required, what software load balancer would you recommend?
|
# ¿ Feb 15, 2010 17:35 |
|
HondaCivet posted:Quick noob sorta question: Is there a way to compare strings that is case AND space insensitive? Like something that would say "ooga booga" == "OOGA BOOGA" == "oogaBooga" is true? I don't know what you are doing but maybe strip all the whitespace characters from the string and convert to lower case.
|
# ¿ Feb 20, 2010 00:10 |
|
Try just Transport t ¿ in.readObject();
|
# ¿ Mar 1, 2010 21:14 |
|
Mustach posted:
That's not a deep copy.
|
# ¿ Mar 30, 2010 21:01 |
|
How are you actually sending the object to the servlet? If you are doing it from an HTML formm you pass each one of the fields in the object as an http parameter and then get them back out using the getParameter method of the request object. This is obviously tedious and is one of the main reasons you use a framework to do this mapping automatically.
|
# ¿ May 14, 2010 03:44 |
|
mister_gosh posted:Ok, after trying for 8+ hours, I thought I better try here. I have two .war files which reference a couple of external jars in a Tomcat application. Try putting the jars in the tomcat/lib folder.
|
# ¿ May 28, 2010 15:47 |
|
epswing posted:mister_gosh said he's got two war files, so two web apps. Isn't MEAT TREAT's suggestion exactly what tomcat/lib is for (ie multiple webapps having access to the same set of jars)? Exactly, if it's a common library that you are going to share with multiple applications you should place it there. This only becomes a problem when you need two different versions of the same library. But really I've never had a problem with deploying my wars with a lib directory, I believe the application server will use those first which will override whatever is in the tomcat/lib folder.
|
# ¿ May 28, 2010 19:16 |
|
Someone on my team was fooling around with maven for that, but it turns out that that's something best suited for ant.
|
# ¿ Jul 19, 2010 20:06 |
|
I kind of am, that sounds like something I'm about to do
|
# ¿ Aug 11, 2010 23:13 |
|
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. In Netbeans ALT-SHIFT-F will make you happy.
|
# ¿ Aug 20, 2010 19:04 |
|
Magicmat posted:I'm trying to figure out the best way to share an Eclipse project. The folder is on a shared drive (shared via Dropbox), with one computer on Mac OS X and the other using Windows 7. Use mercurial with tortoisehg if you still want a decent DVCS on windows. There isn't any excuse.
|
# ¿ Aug 22, 2010 00:50 |
|
danishcake posted:A quick question from a C++ guy who is dipping his toes into Java. If I have two preallocated objects, is there a convenient way to do a deep copy of one into the other, avoiding allocating a new one? I really want something a bit like clone() but with an existing target. If you are not opposed to using an external class the Apache Commons BeanUtils class has the copyProperties method that does what you want. But that if you have non primitive fields inside, it will probably just copy the references and not do a deep copy like you would expect.
|
# ¿ Aug 22, 2010 21:38 |
|
Which profiler do you guys recommend for remote J2EE applications? I'm really interested in viewing which queries are taking the longest to return when the system is under heavy load. I have a few stress tests setup that I'm going to run from like 10 machines and each one is going to simulate like 50 clients. I know it's not enough to kill the server, but I hope to see some interesting data. I also need to be able to save the data that it generates to later review it.
|
# ¿ Aug 31, 2010 15:33 |
|
This isn't tested, but this should get you going:code:
|
# ¿ Sep 26, 2010 18:07 |
|
Zaxxon posted:well then what's the normal way to organize your libraries?
|
# ¿ Oct 8, 2010 20:28 |
|
Jewbert Jewstein posted:Doing more Google Maps work with the site I'm making and now it appears that I need to embed a dynamic map to it instead of a static one. With the static map I was able to just embed a browser and send it a url. Javascript isn't Java You want to ask in the Web Design/Development Small Questions
|
# ¿ Oct 15, 2010 16:41 |
|
Elos: are you using OpenJDK or the Sun JDK on Linux?
|
# ¿ Oct 21, 2010 17:36 |
|
Elos posted:That method just loops trough an array asking the tiles to draw themselves. I don't have any real reason for drawing it constantly besides wanting to see how it's done and hell, I might want to make it a pseudo-realtime like Diablo or something. Use a profiler, any new JDK will have one included. You can also try JProfiler or Yourkit.
|
# ¿ Oct 23, 2010 00:22 |
|
I think the solution to that is to store it as a timestamp which MySQL stores internally as the number of miliseconds since Jan 1, 1970. Then when you ask it for the time it will return it untouched, and in your Java program you can apply the correct offset.
|
# ¿ Nov 9, 2010 23:51 |
|
Spring is a web framework, and Swing will be supported for a long time to come. The SwingLabs has some cool stuff that you can use, but I don't see too many people using it in the future for any serious desktop applications. Java FX was supposed to be this awesome thing that would save desktop Java applications but that didn't pan out. My opinion is that Java desktop applications are dead, and if not that at least a second class citizen on the platform.
|
# ¿ Nov 18, 2010 21:31 |
|
You need to use the certificate you created in your client and add it to the truststore for the SSLConnectionFactory or whatever it's called before trying to connect to the server. Or you can disable the check for the server's certificate but that's not a good idea in the real world. Oh also make sure that your certificate includes your hostname in the common name field.
|
# ¿ Dec 7, 2010 17:50 |
|
Flobbster posted:What's really fun is teaching students in a second-semester Java data structures class the proper way to implement equals and hashCode, especially when the concept of hash tables hasn't been introduced yet so a hash code seems pointless to them. (Why teach hashCode without mentioning hash tables? If we're teaching them to override equals, it's better that we mention hashCode at the same time since the two are so closely related.) I always thought the contract for hashCode was that it had to match the same things that equals did, but after reading the spec that's not the case. God drat that's a terrible way to introduce subtle bugs. That code is still inexcusable, they should at least check for nulls and that's its the same type!
|
# ¿ Dec 10, 2010 01:27 |
|
The real solution is to have your model live outside the scope of that method so that when you refresh the model the JSpinner updates automatically.
|
# ¿ Dec 13, 2010 16:07 |
|
fletcher posted:While we're on the topic of concurrency, I discovered ExecutorService the other day and it is awesome. Made it a piece of cake to make my little utility app multi-threaded, and now it runs 8x faster. Yes it is awesome, I used it to test and reproduce a race condition in another part of my code.
|
# ¿ Jan 13, 2011 21:48 |
|
I might be completely wrong on this but don't the newer JDBC drivers deffer the execution until you actually start scrolling the resultset?
|
# ¿ Jan 28, 2011 02:46 |
|
Aleksei Vasiliev posted:Quick question about HashSets (which are backed by HashMaps): I'm pretty sure the only way it could change while you're iterating is if you add or remove elements in another thread. Even then it would throw a ConcurrentModificationException. With a single thread it will iterate as you expect. The warning means that after a bunch of inserts into the HashMap the next time you iterate it it might have changed the order of the elements.
|
# ¿ Jan 29, 2011 17:47 |
|
Parantumaton posted:"We're an Apache project, therefore we must use Apache Commons Logging!" would be an excellent example of that. slf4j or
|
# ¿ Feb 24, 2011 17:39 |
|
Right but you're not an Apache Project. That's who my comment was directed at.
|
# ¿ Feb 24, 2011 21:27 |
|
Because a lot of Apache projects already switched.quote:Apache Archiva
|
# ¿ Feb 24, 2011 22:16 |
|
|
# ¿ Apr 26, 2024 08:52 |
|
covener posted:Seems fallacious, different people on different projects use different logging. Who could possibly give a gently caress? I gave a gently caress when I had to include 5 projects and each one used a different logging API. Thankfully now I've consolidated all of that poo poo using slf4j adapters and redirect it to whatever my container uses. My point was that now that slf4j exists there isn't any reason to use the commons logging API in new projects. Parametrized logging is loving awesome and you don't have to deal with the classpath issues of the JCL.
|
# ¿ Feb 25, 2011 17:12 |