Why do we use Heap Memory, Can we use Stack memory for the same? EDITED One more question came in my mind after reading answers 1) is there any other kind of memory which we can think of alternative to Heap and Stack? Edited I came across the string pool, is that memory associated with the heap or Stack? Answ…
Tag: java
Integer division: How do you produce a double?
For this code block: the value of d is 0.0. It can be forced to work by casting: But is there another way to get the correct double result? I don’t like casting primitives, who knows what may happen. Answer That avoids a cast. But you’ll find that the cast conversions are well-defined. You donR…
Weird Integer boxing in Java
I just saw code similar to this: When ran, this block of code will print out: I understand why the first is false: because the two objects are separate objects, so the == compares the references. But I can’t figure out, why is the second statement returning true? Is there some strange autoboxing rule th…
Why does this Java/Groovy code cause heap memory exceptions?
This 3rd party script keeps causing heap memory exceptions: That part of the script, which receives messages through TCP/IP after receiving the message, causes the following exception: Exception in thread “Thread-2” org.codehaus.groovy.runtime.InvokerInvocationException: java.lang.OutOfMemoryError…
JEditorPane – make tabs spaces
I’m wondering if there’s a way to have tabs convert to spaces in a jeditorpane, much like you’d see when working in an IDE. I don’t want to set the tab size. I can already do that easily. I want to have tabs replaced with their equivalent in spaces. So for example if my tabs are 5 spac…
Circle approximations using Bezier curves
I have 2 questions about bezier curves, and using them to approximate portions of circles. Given the unit circle arc (1,0)->(cos(a),sin(a)) where 0 < a < pi/2, will it result in a good approximation of this arc to find the bezier curve’s control points p1, p2 by solving the equations imposed by…
How to check whether the file is binary?
I wrote the following method to see whether particular file contains ASCII text characters only or control characters in addition to that. Could you glance at this code, suggest improvements and point out oversights? The logic is as follows: “If first 500 bytes of a file contain 5 or more Control charac…
Specifying an order to junit 4 tests at the Method level (not class level)
I know this is bad practice, but it needs to be done, or I’ll need to switch to testng. Is there a way, similar to JUnit 3’s testSuite, to specify the order of the tests to be run in a class? Answer If you’re sure you really want to do this: There may be a better way, but this is
Coding Conventions – Naming Enums
Is there a convention for naming enumerations in Java? My preference is that an enum is a type. So, for instance, you have an enum I am opposed to naming it: I understand it is easy to pick off which files are enums, but then you would also have: Also, is there a good document describing the same for constant…
JSF 1.0 vs JSF 2.0
What is difference between these 2 version of JSF (JSF 1.0 and JSF 2.0)? As I am new to java, I only find that difference is at Architectural level. But, in perspective, I can’t get how much it affects the application development ? Also, the MVC imposed is different with JSF and Spring. Even if JSF has …