Skip to content

Tag: java

why use Heap Memory in Java

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…

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 don&#82…

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…

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…

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 …