Greg Blajian

Greenhorn
+ Follow
since Aug 31, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Greg Blajian

Hi, I was wondering if someone might have some insight on a little problem I am having with a Filter I wrote for pretty printing jsp documents[jspx extension]. It seems to be the consensus that you can't make it pretty print by default so I used a response wrapper and replaced the ServletOutputStream with a ByteArrayOutputStream using a rather hack delegate following the compression example in the Head First Servlets and JSP book. It only sort of works though. Most of the tiles run all the way through and output to the ByteArrayOutputStream fine except the last one. The problem is that when the last one fails I end up with incomplete XHTML thus I can't treat it as XML and output it as a pretty printed document. It's not like its critical but I can find nothing unusual looking at the JSPX that would cause the output stream to be truncated in this way and I am not getting an error that would indicate what the problem is. Just wondering if anyone has any ideas on it. By the way, when I use the response object straight up(no wrapped objected or delegate) the page renders completely and correctly. If there is another forum more appropriate for this question please let me know.
18 years ago
JSP
Thank you Ernest, that answered my question very clearly and concisely. I really appreciate it.
18 years ago
While I agree with you in general, when there is an opportunity or a need to improve the code for performance gains is there some advantage to one method over another? I ask because of something I read on this site Mindprod. If I just believed it out of hand I wouldn't even have asked but, although that may have been true at some time in past incarnations of java, is it still true now? Was it ever true?
18 years ago
Given the following which way is the best in terms of "best practice" and speed? All of the calls work fine, but is one better than the other? The only things in any non-implementing class are static variables. Eclipse complains about instantiating a class to call a static variable and I can see why it would, but is there some benefit in speed using an abstract class over a class, or over an interface? To me the interface makes the most sense but I can't seem to come up with a justification that sounds good, especially if there is some penalty in speed to using an interface as opposed to a class (abstract or otherwise).

<code>
class Goofy1
{
public static final String FIRST = "Mickey";
public static final String SECOND = "Donald";
public static final String THIRD = "Goofy";

public Goofy1()
{
super();
}
}

public interface Goofy2
{
String FIRST = "Mickey";
String SECOND = "Donald";
String THIRD = "Goofy";
}

public abstract class Goofy3
{
public static final String FIRST = "Mickey";
public static final String SECOND = "Donald";
public static final String THIRD = "Goofy";

public Goofy3()
{
super();
}
}

public class GoofyImpl
{
/**
* @param args
*/
public static void main(String[] args)
{
Goofy1 myGoofy1 = new Goofy1();
System.out.println("Disney's first: " + myGoofy1.FIRST);
System.out.println("Disney's second: " + Goofy2.SECOND);
System.out.println("Disney's third: " + Goofy3.THIRD);
System.out.println("Disney's favorite: " + Goofy1.THIRD);
}
}
</code>

TIA
18 years ago
I apologize if this question is too simple for the intermediate forum. Given the following code
<code>
public class A
{
private String b = {"a", "b", "c", "d"};
private static A a = new A();
public static A getInstance()
{
return a;
}

int findGoofy(String x)
{
int j = -1;
for (int i = 0; i < b.length; ++i)
{
if (c.equals(b[i])) j = i;
}
return j;
}
}
</code>

if a method in one thread wants to look for "a" and a method in another thread looks for "d" could the caller looking for "d" end up with 1 or -1 or the one looking for "a" end up with 4 or -1? Does the static modifier on the singleton instance guarantee thread safety in the findGoofy method? Would I be better off just making findGoofy static and not having a singleton at all? Would there be different instances of x and i on the stack/heap for each thread that would ensure that this isn't really a problem regardless of whether anything is declared static or not?
19 years ago