 |
 |
Index ‹ java-programmer
|
- Previous
- 1
- How do I make a simple password field....more.I want to password protect the continued running of a section of javascript.
What I need is for the user to see a login field, they type a code in, if it
is good, the script continues, if bad, it stops dead.
I would like to base the password on julian date.
Also, how do I time out a group of statements after a preset amount of time
like 1 minute or so.
I am not a Java programmer, but if examples are shown, I can usually figure
out the specific details.
THANKS in advance.
- 1
- Ideas, Making a graphical grid look like ISO viewHi, hope my question is not too abstract.
I'm drawing a square grid and I have mouse events that return
coordinates of that grid. Now I'd like to make that grid look like an
iso view. Illusion of 3D, seen from an oblique angle, as is typical in
conquest and exploration games.
Affine transform shear takes me close, but I think it's not going to get
me all the way. I think the problem is, I don't really want the
vertical lines to stay parallel, because that makes it look like the
"far end" is fatter, instead of converging to some vanishing point (The
squares in the grid should end up being trapezoidal, I think).
So two problems, 1., how to draw my grid in rectangular coords but have
it look like an iso view, and 2., how to translate the Point from the
mouse event, into the coordinates of my grid.
If Affine transform is still the way to go, I can keep studying it.
Right now I'm thinking I may actually need to work out the geometry of
the iso view, draw it explicitly, and then find the mouse coordinates by
iterating through the boundaries of my graph. This is nasty, since
AffineTransforms would make it so easy.
Maybe there's a better way I'm not thinking of, such as, instead of
bounding my grid by "lines", construct it from "shapes", and then I
could add a listener to each shape, or something like that. That sounds
treacherous too.
- 3
- jboss and Workflow??I'm work with Jboss, and I'd use Workflow on Jboss server. Is Anyone working about this problem? Can anyone give me a tutorial or an example???
- 3
- can't create BufferedImageI am trying to create a BifferedImage and Graphics2D associated with a
JPanel. I understand that the JPanel must be displayable else the
createImage method may return null. However in my stub program below I
always get null returned from createGraphics. I obviously am missing
something but I can't figure out what. If the program below is run
without a runline parameter it does not attempt to create a
BufferedImage and it runs OK. If it is run with a runline parameter it
throws an exception because bh is null. Why?
Jay
public class Test extends javax.swing.JFrame {
private static String[] opt = null;
public Test() {
init();
}
void init() {
javax.swing.JPanel jContentPane = new javax.swing.JPanel();
setContentPane(jContentPane);
setSize(450, 350);
javax.swing.JPanel graphPanel = new javax.swing.JPanel();
java.awt.Dimension s = new java.awt.Dimension(400, 300);
graphPanel.setPreferredSize(s);
getContentPane().add(graphPanel, null);
graphPanel.addNotify();
s = graphPanel.getPreferredSize();
System.err.println("Is JPanel=" +
(graphPanel instanceof javax.swing.JPanel) +
" " + s.width + "x" + s.height + " Displayable=" +
graphPanel.isDisplayable() + " Headless= " +
java.awt.GraphicsEnvironment.isHeadless());
if(opt!=null && opt.length>0) {
java.awt.image.BufferedImage bh =
(java.awt.image.BufferedImage)graphPanel.createImage(
s.width, s.height);
java.awt.Graphics2D bufh = bh.createGraphics();
}
}
public static final void main(String[] argv) {
opt = argv;
Test test = new Test();
test.setVisible(true);
}
}
- 4
- Comparing two long numbersOn Mon, 2 Jun 2008, Daniele Futtorovic wrote:
> On 2008-06-02 13:22 +0100, Lew allegedly wrote:
>> Lew wrote:
>>>> Why do you use either "d" or "D"? Is it something you always put on
>>>> double constants, or just for potentially ambiguous situations? If the
>>>> latter, how do you assess ambiguity?
>>
>> John B. Matthews wrote:
>>> I don't use either "d" or "D"; I use "d", but I have to read other
>>> people's "D"s. Presbyopia comes to us all. :-)
>>
>> Most people don't bother with either "d" or "D" in Java double constants.
>> I never have to read other people's "D" in Java code; I don't think I've
>> ever encountered a double suffix on a constant in any professional Java
>> code.
>
> double athird = 1d / 3; ?
Urgh. Now this:
double farthing = 1d / 4 ;
is at least numismatically accurate, but won't compile after 1960!
tom
--
Eat whip you steroid wall-bashing lug-head! -- The Laird
- 5
- GridBagLayout and JMenuBar problemsHere's another interesting one. I looked on the Bug Parade to see if
this was present, but rapidly drowned in the sea of totally unrelated
results I got back from the brain dead search capabilities.
I built up a JPanel using GridBagLayout and various components. Works
fine; I'm quite used to GridBagLayout and its quirks. I'm using the
Java look and feel with native decorations turned off, so GridBagLayout
respects my panel's minimum size constraints.
I had been testing this layout in a JFrame without a JMenuBar, just to
validate the layout. Now when I added a JMenuBar to the JFrame, the
layout screws up when I resize the panel down to its smallest size.
It's as though the GridBagLayout does not take the JMenuBar's dimensions
into account when resizing happens. In my case, a couple of buttons
shrink in height, a text field bizarrely grows to 1.5X height, and
another text field overlaps it. None of these problems show up unless
the menu bar is in place.
Again: a known bug? Or should I submit it?
If there's any interest I'll whittle my code down to a SSCCE. Then I'll
try it with native window decorations turned on to see if that's where
the problem lies.
Laird
- 6
- servlet calling servlet stopped by securityI have two servlets in the same tomcat webapp (A and B) both normally
accessed from the web. Sometimes A needs to access B and I use http to
do that. Actually 'B' is about a dozen other servlets, still all in
the same webapp.
This works just fine until I turn on security constraints. When I do
that and request A the login form works as normal and invokes A
correctly. But when A needs to invoke B I get another logon form
instead of B. This would be okay, I can hack through that, but I only
know the user name, not the password for A's session.
Is there a simpler way to have one servlet in the same webapp invoke
another without having to go through security? I cannot just do java
to java, there are too many entry points (ie cases of 'B') They are
all volatile and need to be exposed to the web.
Thanks for your help
Roger
- 7
- panel question.."Frances" <email***@***.com> wrote in message
news:4317337c$0$18646$email***@***.com...
<snipped />
> Sunde, we finally managed to connect to server.. thank you very much for
> all your help, very much appreciated.. Frances
You never said...
Did your original code call one of the applets methods from JavaScript?
...or was it something else?
I'm just curious to what was wrong...
--
Dag.
- 11
- question about keeping the GUI and logic separateHello,
I have a question about keeping logic/processing code off of the GUI.
In a couple of other languages I'm familiar with, there is usually a
method called FindComponent which will iterate through a form and get
the component matching the name in the argument.
For example, in VS.NET lets say I have a grid (table) on a form, the
form represents one class. I then put the code for getting and
processing data in another class. After any processing occurs (and
the results are placed in a dataset), I need to bind the dataset to
the grid. But the grid doesn't have knowledge of where the dataset
came from... so how does the data get shoveled in there?
In the data processing class, there's a local variable of grid type
and it's gets bound to the grid in the form, like so (sorry about the
VB):
Class SomeClass
Sub doSomething(ByVal c As Component)
Dim localGridView as GridView
Dim localDataSet as DataSet
' MyGrid lives on Form1
localGridView = c.FindComponent("MyGrid")
localGridView.DataSource = localDataSet
' So even though the GUI hasn't a clue as to what is going on, the
current data is now displayed to the user.
localGridView.DataBind()
End Sub
End Class
Does Java have an equivalent of FindComponent, or a something similar
to the code snip above?
I'm using Java 6 here. I did try looking at c.getComponent() but
there's only one valid index... 0 and it represents the
javax.swing.JRootPane. Anything after 0 throws an index out of bounds
error. There are 3 JButtons and 1 JList on the panel. I want to add
some strings to the JList...
public class MyGUI() extends JFrame
{
GUIUtils u = new GUIUtils();
public MyGUI()
{
//
// snip
//
myButton.addActionListener (new ActionListener()
{
public void actionPerformed (ActionEvent e)
{
try
{
u.doSomething(MyGUI.this);
}
catch (IOException ioe)
{
ioe.printStackTrace();
}
}
});
}
and...
public class GUIUtils
{
public void doSometing(Container c) throws IOException
{
listModel = new DefaultListModel();
listModel.addElement(value);
// I want to put the listmodel in the JList now but how do I get
this code to know about the JList in MyGUI?
}
}
Suggestions are greatly appreciated.
Thanks!
- 12
- web search with summarized results, good for wireless, too.We just released a wireless search service. The wireless search
service takes the results returned by Google and gives key points of
the resulting web sites. The short key points are suitable for viewing
on wireless devices.
Check it out at:
http://www.netosprey.com
The following is an example of www.sun.com:
-----
You entered: http://www.sun.com/
Link to Text ratio: 453/914=0.49562363238512036
AME finds this page has a lot of links.
It could be an index page and talks about: Java, Sun, System,
Computing, and Products
Here is a list of main ideas presented in the page:
*** Sun's Big Web Event - Don't miss Network Computing 03-Q4 on
December 3 at 8 am PST. Sign up for an e-mail reminder today.
*** Choice on a grand scale. - Sun extends product line through
strategic alliance with AMD; plans to offer high-performance x86
systems at affordable prices.
*** The identity management leader. - Sun's planned acquisition of
Waveset aims to inject the Java EnterpriseSystem with superior network
identitycapabilities.
*** Sun Signs Agreement with CSSC - Java Desktop System to be
established as the foundation for China's fast-growing IT industry.
*** Contact |Company Info |Employment |Privacy |Terms of Use
|Trademarks
-----
Check it out at:
http://www.netosprey.com
Steve
- 12
- reason for sporadic long full GC pause times?!?....Hello folks,
in our java business application our customer realize sporadic very
long pauses caused by full gc's.
Normaly the app runs smoothly with acceptable gc- and
full-gc-pausetimes. (gc=0.0xx sec / fullgc <=2 sec)
But sometimes during 8 hour work the occurs full gc's with 90-150
seconds (!)
which our customer complains about - of course.
In the first step I thought that our JVM-settings were wrong:
-Xms450m -Xmx450m -XX:NewSize=32m -XX:MaxNewSize=32m
-XX:SurvivorRatio=8 -classpath....
--> long full gc pauses occured sporadicaly.
I thought that the Newsize is too small -> wich implies the too big
tenured space -> which could be the reason for too longs full gc's. I
decided to use -NewRatio=4 Parameter.
And I also lowered the max. Heap size to Xmx350m, because the gcviewer
told me that the memory usage was only about 290 MB.
With the new settings
-Xms350m -Xmx350m -XX:NewRatio=4 -XX:SurvivorRatio=8 -classpath....
our customer had the same experience that sometimes the full gc's
pausetime took more than 100 sec's.
Additionally we/they relaized that the full gc freed not enough memory
so that the full gc frequency raised up to a point where no minor gc
were done - only full gc's !
Due to that I raised Xms and Xmx
-Xms512m -Xmx512m -XX:NewRatio=4 -XX:SurvivorRatio=8 -classpath....
which enables the JVM to free more memory at full gc (already tested),
but I fear this will not help to solve the sporadic problem with the
long full gc pause times at customer side.
Does anybody have an idea what could be the reason for the
extraordinary long full gc pause times?
Info btw:
customer PC's all have 1 GB RAM and the throughput of the application
was in any case >= 99,8% !
The problem with the long full gc pause times was never reproduced in
our lab / dev.-deptmnt.
Thanks in advance
Martin
- 14
- J2ME: j9 & JSR75?Hi all...
Has anyone tried to install IBM's optional package for JSR75
support on it's PDA?
I am having troubles by lauching the Midlet HQ that would
support FileConnection.
Regards,
Branko
- 14
- turn off multiref in Axis(SOAP)Is there any possibilities to turn off references in soap envelope.
I would like to have response axis format equivalent old soap format.
thanks for help
bastek
- 16
- For loop not working from static methodI have a JSP that outputs 10 links and it works great but want to cut
down on the scriptlet lines in my JSP.
Now I want to put the for loop that outputs the 10 links into a source
file and call the class in my JSP using just one line scriptlet.
Here is what my current JSP looks like where it outputs the 10 links:
<jsp:useBean id="pageinfo" class="storm.Pageinfo" scope="session" />
.....
<%
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
out.println("<a href=moveto.jsp?inpage=" + i + ">" + i + "</
a>");
}
}
%>
Now my attempt to put it in a class outputs only 1 link instead of 10.
Source code for the Java class:
package storm;
import storm.*;
public class PageUtil
{
public static String theMethod(Pageinfo pageinfo)
{
if (pageinfo!=null)
{
for(int i=0;i < 10;i++)
{
return "<a href=moveto.jsp?inpage=" + i + ">" + i +
"</a>";
}
}
return "";
}
}
JSP scriptlet calling the static method:
<%= PageUtil.theMethod(pageinfo) %>
Please advise how I can get this to work. I am using Tomcat 4.1.27
and dont have JSTL.
- 16
- J2ME, How to minimize a program ?Thank you so much for the information I didn't know.
But, for Sony Ericsson cells, we can press back button ( like the
symbol of inverse Enter ) to exit ( not destroy ) program.
For SmartPhone - P910i, we can run other funtion very easily ( we don't
have to implement it )
I found a cheat method that could do this.
public Form f;
....
....
// Do not new a Form for f
display.setCurrent(f); // minimum program :p
// I don't know why, the compiler pass it, and we can find it is work
on cell.
|
| Author |
Message |
The Wogster

|
Posted: 2005-6-13 20:43:00 |
Top |
java-programmer, 2 extends
Dale King wrote:
> The Wogster wrote:
>
>> Thomas G. Marshall wrote:
>>
>>> The Wogster coughed up:
>>>
>>>> Irlan agous wrote:
>>>>
>>>> It's like the goto, it's legal in C, but the only times I have seen it
>>>> used, were because someone had programmed themselves into a corner.
>
>
> In C there were some cases where it was necessary/mad the code clearer.
> Most of those cases in Java have other constructs that eliminate the
> need for an arbitrary goto. Exceptions, labelled break and continue
> eliminate most of the cases for goto from C. But since C doesn't have
> those you are forced to use goto or over complicate the code.
>
>> With languages that have richly designed looping and redirection
>> constructs, you shouldn't need the goto. I didn't say it was always
>> to be avoided, just that when you feel the need to use goto (except
>> maybe in Gee Whiz Basic), it's usually a pretty good indicator that
>> the code design is lacking.
>
>
> That design as you said could be the design of the language and not
> necessarily the design of the program. Or are you one of those anti-goto
> that also disagrees with goto-like constructs like break, continue, and
> exceptions?
Uh no, because those leave control with the language. Most people who
defend the goto so vehemently,are, with modern languages like Java,
simply are using it to emulate something else available within the language.
Let's see, in the last 10 years, I have written about 1,000,000 lines of
C code, the number of actual goto's in there, none. During that time, I
viewed probably 40,000,000 more lines, which contained maybe 20 gotos.
Shows how little goto is actually needed. Of those 5, were code that
was complex trying to do something simple, usually the reason I was
looking at it, was because it wasn't working (poor design). Five more
were instances where you had the jack-of-all-procedures, where the
programmer had written a bunch of procedures in one block of code (again
poor design). They used goto to make the thing work. The remaining
ones, were places where the programmer had written themselves into a
corner, and under pressure of getting the thing to work, used goto to
bail out (again poor design).
W
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-13 20:43:00 |
Top |
java-programmer >> 2 extends
Dale King wrote:
> The Wogster wrote:
>
>> Thomas G. Marshall wrote:
>>
>>> The Wogster coughed up:
>>>
>>>> Irlan agous wrote:
>>>>
>>>> It's like the goto, it's legal in C, but the only times I have seen it
>>>> used, were because someone had programmed themselves into a corner.
>
>
> In C there were some cases where it was necessary/mad the code clearer.
> Most of those cases in Java have other constructs that eliminate the
> need for an arbitrary goto. Exceptions, labelled break and continue
> eliminate most of the cases for goto from C. But since C doesn't have
> those you are forced to use goto or over complicate the code.
>
>> With languages that have richly designed looping and redirection
>> constructs, you shouldn't need the goto. I didn't say it was always
>> to be avoided, just that when you feel the need to use goto (except
>> maybe in Gee Whiz Basic), it's usually a pretty good indicator that
>> the code design is lacking.
>
>
> That design as you said could be the design of the language and not
> necessarily the design of the program. Or are you one of those anti-goto
> that also disagrees with goto-like constructs like break, continue, and
> exceptions?
Uh no, because those leave control with the language. Most people who
defend the goto so vehemently,are, with modern languages like Java,
simply are using it to emulate something else available within the language.
Let's see, in the last 10 years, I have written about 1,000,000 lines of
C code, the number of actual goto's in there, none. During that time, I
viewed probably 40,000,000 more lines, which contained maybe 20 gotos.
Shows how little goto is actually needed. Of those 5, were code that
was complex trying to do something simple, usually the reason I was
looking at it, was because it wasn't working (poor design). Five more
were instances where you had the jack-of-all-procedures, where the
programmer had written a bunch of procedures in one block of code (again
poor design). They used goto to make the thing work. The remaining
ones, were places where the programmer had written themselves into a
corner, and under pressure of getting the thing to work, used goto to
bail out (again poor design).
W
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-13 21:00:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
> The Wogster coughed up:
>
>>Thomas G. Marshall wrote:
>>
>>>The Wogster coughed up:
>>>
>>>
>>>>Thomas G. Marshall wrote:
>>>>
>>>>
>>>>>The Wogster coughed up:
>>>
>>>
>>>...[rip]...
>>>
>>>[regarding goto]...
>>>
>>>
>>>>>>Procedural program design theories don't require it, and OOP
>>>>>>should have made it illegal (IMNSHO).
>>>>>
>>>>>It has nothing whatsoever to do with either discipline
>>>>>specifically, so such a statement doesn't accomplish much. {shrug}
>>>>
>>>>I maintain that when you "need" goto, it's usually in a function or
>>>>method that is trying to do too many things, and that breaking it
>>>>down into smaller pieces will actually lead to a cleaner, more
>>>>maintainable construct that doesn't need the goto.
>>>
>>>
>>>
>>>A very common use for goto is an exit out of a nested loop in a
>>>language without multilevel or labeled breaks. Would you accept or
>>>not accept that as a perfectly reasonable usage of goto?
>>
>>That would be acceptable, however this is a Java group, and Java does
>>have those capabilities, does it not? Besides that the building of a
>>nested loop that needs you to bail from the very inside, all the way
>>to the outside, is often a design that is far too complicated in the
>>first place.
>>
>>
>>>It is still not at all clear where you wish to draw the line,
>>>particularly with the statement you made:
>>>
>>> "The Wogster":
>>> Procedural program design theories don't
>>> require it, and OOP should have made it
>>> illegal (IMNSHO).
>>>
>>>Here's what's wrong with it:
>>>
>>>1. That procedural or any other program design theories don't require
>>>something is certainly of no issue. Once you have a while()
>>>construct, you do not need the for(;;) loop, and once you have
>>>if/else, you do not need the switch. Would you hence argue against
>>>the for() and switch? It's a pointless statement.
>>>
>>>2. The concepts of OO and procedural programming are entirely
>>>orthogonal to whether or not a language contains a goto. It is
>>>applicable throughout both paradigms, and has no specific impact to
>>>either. Again, the /out-of-hand/ demonizing of goto is thus far without
>>>merit. Demonizing the misuse of goto is certainly with merit, as is
>>>demonizing the misuse of anything, but that is an entirely different
>>>exercise than what you seem to be attempting.
>>>
>>>Now don't get me wrong here: I /prefer/ the restricted goto within
>>>java (downward only "labeled" or "named" break) to the unrestricted
>>>versions found in C/C++, because I like the way the code looks as a
>>>result. But when you have a language without such a downward goto,
>>>then using an unrestricted goto in a careful downward fashion is
>>>perfectly fine, and railing against its usage is outright silly.
>>
>>Whatever go ahead, I don't really care if you want to write lots of
>>gotos, just hope I never have to maintain that code.....
>
>
> I never said I wanted to write "lots of goto's". And if I put them in
> there, then it would be to improve maintainability.
>
As I put in another message, I have written a lot of code, and worked
with considerably more, still haven't found an instance where goto made
things more maintainable. Every goto I have seen, since my days in
assembler, was as a result of someone trying to make sense of code that
was poorly (if at all) designed.
We may need to agree to disagree on this one, though, were arguing in
circles now....
W
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-14 3:39:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Thomas G. Marshall wrote:
>> The Wogster coughed up:
...[rip]...
>>> Whatever go ahead, I don't really care if you want to write lots of
>>> gotos, just hope I never have to maintain that code.....
>>
>>
>> I never said I wanted to write "lots of goto's". And if I put them
>> in there, then it would be to improve maintainability.
>>
>
> As I put in another message, I have written a lot of code, and worked
> with considerably more, still haven't found an instance where goto
> made things more maintainable. Every goto I have seen, since my days
> in assembler, was as a result of someone trying to make sense of code
> that was poorly (if at all) designed.
>
> We may need to agree to disagree on this one, though, were arguing in
> circles now....
Probably a good idea, and you should understand that I do not wish to be
contentious nor offend. But I still am struggling to understand your
position. IYO, let's forget the "what I've seen is", and let's concentrate
on "what bothers me", if it's ok with you, to establish your stake in the
sand.
Take a look at the following in a goto-enabled language:
for (int z = 0; z < 10; z++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
if (array[z][y][x] == somethingNeeded)
goto hop_out;
hop_out:
(continue on)
Is /this/ something that bothers your sensibilities?
Now let's look at this. Note, this is purposefully not ideal---I'm
searching for lesser-quality scenarios. And note that the "status" is
computed and maintained for proper return---I'm limiting the detail here on
purpose as well:
Send UDP/IP initial contact datagram...
If (abortNak)
goto finish_up;
(UDP transactions here)
if (errorCondition) // or whatever
goto finish_up;
(UDP transactions here)
if (errorCondition or abortNak) // or whatever
goto finish_up;
(UDP transactions)
(etc)
finish_up:
Notify database;
Send UDP trailing datagram...
return status;
Are you at odds here as well?
--
I've seen this a few times--Don't make this mistake:
Dwight: "This thing is wildly available."
Smedly: "Did you mean wildly, or /widely/ ?"
Dwight: "Both!", said while nodding emphatically.
Dwight was exposed to have made a grammatical
error and tries to cover it up by thinking
fast. This is so painfully obvious that he
only succeeds in looking worse.
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-14 3:42:00 |
Top |
java-programmer >> 2 extends
email***@***.com coughed up:
> "Thomas G. Marshall"
> <email***@***.com> wrote in
> message news:<yeMqe.269$qr1.189@trndny07>...
>> The Wogster coughed up:
>
> <Snwwip.>
>
>>
>> The cases I'm thinking of almost always involved a function where
>> the exit of the function required several things to happen. The
>> goto was in these cases a much clearer alternative to otherwise
>> *horrible* contrivances. In these cases, to say that this was done
>> only because the author missed a better non-goto way to design it is
>> to imply that using goto is /always/ to be avoided, and is simply
>> incorrect.
>
> Hi, Thomas!
>
> Could you provide this sample of code, or an equivalent?
>
> Just curious,
>
> .ed
>
> www.EdmundKirwan.com - Home of The Fractal Class Composition.
Sure---I think that the examples I pondered in my latest post to The Wogster
should be ok.
--
I've seen this a few times--Don't make this mistake:
Dwight: "This thing is wildly available."
Smedly: "Did you mean wildly, or /widely/ ?"
Dwight: "Both!", said while nodding emphatically.
Dwight was exposed to have made a grammatical
error and tries to cover it up by thinking
fast. This is so painfully obvious that he
only succeeds in looking worse.
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-14 22:04:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
> The Wogster coughed up:
>
>>Thomas G. Marshall wrote:
>>
>>>The Wogster coughed up:
>
>
> ...[rip]...
>
>
>>>>Whatever go ahead, I don't really care if you want to write lots of
>>>>gotos, just hope I never have to maintain that code.....
>>>
>>>
>>>I never said I wanted to write "lots of goto's". And if I put them
>>>in there, then it would be to improve maintainability.
>>>
>>
>>As I put in another message, I have written a lot of code, and worked
>>with considerably more, still haven't found an instance where goto
>>made things more maintainable. Every goto I have seen, since my days
>>in assembler, was as a result of someone trying to make sense of code
>>that was poorly (if at all) designed.
>>
>>We may need to agree to disagree on this one, though, were arguing in
>>circles now....
>
>
>
> Probably a good idea, and you should understand that I do not wish to be
> contentious nor offend. But I still am struggling to understand your
> position. IYO, let's forget the "what I've seen is", and let's concentrate
> on "what bothers me", if it's ok with you, to establish your stake in the
> sand.
>
> Take a look at the following in a goto-enabled language:
>
> for (int z = 0; z < 10; z++)
> for (int y = 0; y < 10; y++)
> for (int x = 0; x < 10; x++)
> if (array[z][y][x] == somethingNeeded)
> goto hop_out;
> hop_out:
> (continue on)
>
> Is /this/ something that bothers your sensibilities?
>
Yes, but more that it's a horrible construct, then that it contains a
goto.
Here is another option, that does the same thing, but is, IMNSHO clearer;
bool onlyFirst = true; // only find first somethingNeeded
for (int z = 0; z < 10 && onlyFirst == true; z++)
for (int y = 0; y < 10 && onlyFirst == true; y++)
for (int x = 0; x < 10 && onlyFirst == true; x++)
if (array[z][y][x] == somethingNeeded)
{
onlyFirst == false;
// do other stuff
}
Where the goto becomes a problem, is when do other stuff is 30 lines, so
that the goto is a couple of screens later, and someone not realizing
that the for gets usurped later on, adds code between the "for (int z"
and the "for (int y" that counts on z getting to 10. Of course later
when the code doesn't work the programmer who did it, is unavailable,
and you spend a nice, warm sunny Sunday afternoon, trying to figure out
what happened, instead of tossing a ball around with your kids, before
putting some steaks on the barbie....
My version indicates that there are other conditions, and that z may not
get to 10, and then the programmer would go looking to find out what
happens to onlyFirst.
> Now let's look at this. Note, this is purposefully not ideal---I'm
> searching for lesser-quality scenarios. And note that the "status" is
> computed and maintained for proper return---I'm limiting the detail here on
> purpose as well:
>
> Send UDP/IP initial contact datagram...
> If (abortNak)
> goto finish_up;
>
> (UDP transactions here)
> if (errorCondition) // or whatever
> goto finish_up;
>
> (UDP transactions here)
> if (errorCondition or abortNak) // or whatever
> goto finish_up;
>
> (UDP transactions)
> (etc)
>
> finish_up:
> Notify database;
> Send UDP trailing datagram...
> return status;
>
> Are you at odds here as well?
That is possibly the worst piece of code I have ever seen, and I have
seen some awful stuff in my years. It's an off the cuff example, so
I'll grant you that, how about this version though:
// send initial datagram
while(getData()); // sets abortNak and errorCondition
{
if(!abortNak && !errorCondition)
{
// UDP transactions etc
}
// Notify database;
}
// Send Trailing datagram
// return status
Here is another version of just the if statement:
if(abortNak)
{
// we could do nothing here.
}
elseif (errorCondition)
{
// we could optionally add logging code here
}
else
{
// UDP transactions
}
// Notify database;
// Send Trailing datagram
// return status
W
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-15 2:11:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Thomas G. Marshall wrote:
...[rip]...
>> Take a look at the following in a goto-enabled language:
>>
>> for (int z = 0; z < 10; z++)
>> for (int y = 0; y < 10; y++)
>> for (int x = 0; x < 10; x++)
>> if (array[z][y][x] == somethingNeeded)
>> goto hop_out;
>> hop_out:
>> (continue on)
>>
>> Is /this/ something that bothers your sensibilities?
>>
>
> Yes, but more that it's a horrible construct, then that it contains a
> goto.
>
> Here is another option, that does the same thing, but is, IMNSHO
> clearer;
> bool onlyFirst = true; // only find first somethingNeeded
>
> for (int z = 0; z < 10 && onlyFirst == true; z++)
> for (int y = 0; y < 10 && onlyFirst == true; y++)
> for (int x = 0; x < 10 && onlyFirst == true; x++)
> if (array[z][y][x] == somethingNeeded)
> {
> onlyFirst == false;
> // do other stuff
> }
Ok, good. now there is a stake in the sand. That you have an issue with
the UDP example of mine is fine for the moment, because I was purposefully
establishing something [far] less ideal. I supplied two examples of varying
complexity and worth and you've precisely placed your position on this.
Thank you for that, now we're /somewhere/.
I think that the nested loop you provide is not only slower (which in this
example is hardly an issue), but a harder to maintain obfuscated mess. Back
in my C days, had one of my guys attempted this, he would have received a
quick conversation from me.
You've taken 3 loops, each of which contained only a single conditional for
the engineer to parse through, and added to each one an additional
conditional that must be parsed and evaluated /by the engineer/ in order to
make sure that any change made to the body of the loop doesn't explode the
loop itself around his ears.
Your following statement of:
The Wogster:
Where the goto becomes a problem, is when do
other stuff is 30 lines, so that the goto is a couple
of screens later, and someone not realizing that
the for gets usurped later on, adds code between
the "for (int z"and the "for (int y" that counts on z
getting to 10.
is incredibly broken logic. If the "do other stuff" were 30 lines, then
you'd *PARTICULARLY* not want the loop you describe. It would require the
engineer to wade through 30 lines of code to make sure that the onlyFisrt
boolean was not altered within it. Furthermore, any change to those 30
lines 4 weeks later by another engineer holds the possibility of breaking
the loop itself even if he's very senior, but hopped on caffeine at 3 am.
You would have dragged the logic of the loop itself into 30 additional
lines, when the loop should have instead merely been just that: a nested
loop containing just the logic needed to form the loop.
I believe that your not-so humble opinion (as we all have from time to time)
is /predicated/ on the notion that goto is bad. Predicated and assumed.
From there you drew further conclusions, rather than weigh the issue at hand
and discover what was truly clearest.
...[rip]...
--
"It's easier to be terrified by an enemy you admire."
-Thufir Hawat, Mentat and Master of Assassins to House Atreides
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-15 10:32:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
> The Wogster coughed up:
>
>>Thomas G. Marshall wrote:
>
>
> ...[rip]...
>
>
>>>Take a look at the following in a goto-enabled language:
>>>
>>> for (int z = 0; z < 10; z++)
>>> for (int y = 0; y < 10; y++)
>>> for (int x = 0; x < 10; x++)
>>> if (array[z][y][x] == somethingNeeded)
>>> goto hop_out;
>>> hop_out:
>>> (continue on)
>>>
>>>Is /this/ something that bothers your sensibilities?
>>>
>>
>>Yes, but more that it's a horrible construct, then that it contains a
>>goto.
>>
>>Here is another option, that does the same thing, but is, IMNSHO
>>clearer;
>>bool onlyFirst = true; // only find first somethingNeeded
>>
>>for (int z = 0; z < 10 && onlyFirst == true; z++)
>> for (int y = 0; y < 10 && onlyFirst == true; y++)
>> for (int x = 0; x < 10 && onlyFirst == true; x++)
>> if (array[z][y][x] == somethingNeeded)
>> {
>>onlyFirst == false;
>>// do other stuff
>> }
>
>
> Ok, good. now there is a stake in the sand. That you have an issue with
> the UDP example of mine is fine for the moment, because I was purposefully
> establishing something [far] less ideal. I supplied two examples of varying
> complexity and worth and you've precisely placed your position on this.
> Thank you for that, now we're /somewhere/.
>
> I think that the nested loop you provide is not only slower (which in this
> example is hardly an issue), but a harder to maintain obfuscated mess. Back
> in my C days, had one of my guys attempted this, he would have received a
> quick conversation from me.
See below
>
> You've taken 3 loops, each of which contained only a single conditional for
> the engineer to parse through, and added to each one an additional
> conditional that must be parsed and evaluated /by the engineer/ in order to
> make sure that any change made to the body of the loop doesn't explode the
> loop itself around his ears.
>
> Your following statement of:
>
> The Wogster:
> Where the goto becomes a problem, is when do
> other stuff is 30 lines, so that the goto is a couple
> of screens later, and someone not realizing that
> the for gets usurped later on, adds code between
> the "for (int z"and the "for (int y" that counts on z
> getting to 10.
>
> is incredibly broken logic. If the "do other stuff" were 30 lines, then
> you'd *PARTICULARLY* not want the loop you describe. It would require the
> engineer to wade through 30 lines of code to make sure that the onlyFisrt
> boolean was not altered within it. Furthermore, any change to those 30
> lines 4 weeks later by another engineer holds the possibility of breaking
> the loop itself even if he's very senior, but hopped on caffeine at 3 am.
> You would have dragged the logic of the loop itself into 30 additional
> lines, when the loop should have instead merely been just that: a nested
> loop containing just the logic needed to form the loop.
With the goto, the engineer needs to look for something, they may not
even realize exists. My solution, indicates that the loop has TWO
conditions, which it does, so does yours, but it may not be clear that
there are two conditions, the for only has one condition, even though
the loop has two. That can be dangerous, when the engineer is debugging
code at 3am, knowing that the application takes 6 hours, and needs to be
finish running by 7.
The flag, indicates that there IS two conditions, so a quick search will
find the second condition.
I would like to continue, but don't have more time to spend on this.....
W
>
> I believe that your not-so humble opinion (as we all have from time to time)
> is /predicated/ on the notion that goto is bad. Predicated and assumed.
> From there you drew further conclusions, rather than weigh the issue at hand
> and discover what was truly clearest.
>
>
> ...[rip]...
>
>
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-15 11:52:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Thomas G. Marshall wrote:
>> The Wogster coughed up:
>>
>>> Thomas G. Marshall wrote:
>>
>>
>> ...[rip]...
>>
>>
>>>> Take a look at the following in a goto-enabled language:
>>>>
>>>> for (int z = 0; z < 10; z++)
>>>> for (int y = 0; y < 10; y++)
>>>> for (int x = 0; x < 10; x++)
>>>> if (array[z][y][x] == somethingNeeded)
>>>> goto hop_out;
>>>> hop_out:
>>>> (continue on)
>>>>
>>>> Is /this/ something that bothers your sensibilities?
>>>>
>>>
>>> Yes, but more that it's a horrible construct, then that it contains
>>> a goto.
>>>
>>> Here is another option, that does the same thing, but is, IMNSHO
>>> clearer;
>>> bool onlyFirst = true; // only find first somethingNeeded
>>>
>>> for (int z = 0; z < 10 && onlyFirst == true; z++)
>>> for (int y = 0; y < 10 && onlyFirst == true; y++)
>>> for (int x = 0; x < 10 && onlyFirst == true; x++)
>>> if (array[z][y][x] == somethingNeeded)
>>> {
>>> onlyFirst == false;
>>> // do other stuff
>>> }
>>
>>
>> Ok, good. now there is a stake in the sand. That you have an issue
>> with the UDP example of mine is fine for the moment, because I was
>> purposefully establishing something [far] less ideal. I supplied
>> two examples of varying complexity and worth and you've precisely
>> placed your position on this. Thank you for that, now we're
>> /somewhere/. I think that the nested loop you provide is not only slower
>> (which
>> in this example is hardly an issue), but a harder to maintain
>> obfuscated mess. Back in my C days, had one of my guys attempted
>> this, he would have received a quick conversation from me.
>
> See below
>
>>
>> You've taken 3 loops, each of which contained only a single
>> conditional for the engineer to parse through, and added to each one
>> an additional conditional that must be parsed and evaluated /by the
>> engineer/ in order to make sure that any change made to the body of
>> the loop doesn't explode the loop itself around his ears.
>>
>> Your following statement of:
>>
>> The Wogster:
>> Where the goto becomes a problem, is when do
>> other stuff is 30 lines, so that the goto is a couple
>> of screens later, and someone not realizing that
>> the for gets usurped later on, adds code between
>> the "for (int z"and the "for (int y" that counts on z
>> getting to 10.
>>
>> is incredibly broken logic. If the "do other stuff" were 30 lines,
>> then you'd *PARTICULARLY* not want the loop you describe. It would
>> require the engineer to wade through 30 lines of code to make sure
>> that the onlyFisrt boolean was not altered within it. Furthermore,
>> any change to those 30 lines 4 weeks later by another engineer holds
>> the possibility of breaking the loop itself even if he's very
>> senior, but hopped on caffeine at 3 am. You would have dragged the
>> logic of the loop itself into 30 additional lines, when the loop
>> should have instead merely been just that: a nested loop containing
>> just the logic needed to form the loop.
>
> With the goto, the engineer needs to look for something, they may not
> even realize exists. My solution, indicates that the loop has TWO
> conditions, which it does, so does yours, but it may not be clear that
> there are two conditions, the for only has one condition, even though
> the loop has two. That can be dangerous, when the engineer is
> debugging code at 3am, knowing that the application takes 6 hours,
> and needs to be finish running by 7.
>
> The flag, indicates that there IS two conditions, so a quick search
> will find the second condition.
Now you're grasping at straws.
In my case, each nested for() has a single conditional making 3 visible to
the engineer. Add to this a conditional test within the 3 layer loop for
exit. There is nothing hidden here at all.
In your case, each for() has 2 conditionals making 6. Add to this the same
conditional test I have in the middle, but place the code within the body of
the loop where it is possible to truly muck up the looping logic.
> I would like to continue, but don't have more time to spend on
> this.....
I too am getting tired. It's not that we disagree that is so tiring, but I
just cannot even get /close/ to understanding your logic in this regard, try
as I might to spell the examples out.
You don't think so of course, but I still suspect that if you really thought
it through honestly that you'd realize that much of your knee-jerk dismissal
of the goto is only based upon itself and not on evidence. That you loathed
it first, and then looked for and found the reasons why.
But in any case, we're certainly going nowhere fast.
Thanks for the discussion.
...[rip]...
--
Framsticks. 3D Artificial Life evolution. You can see the creatures
that evolve and how they interact, hunt, swim, etc. (Unaffiliated with
me). http://www.frams.alife.pl/
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-15 20:23:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
> The Wogster coughed up:
>
>>Thomas G. Marshall wrote:
>>
>>>The Wogster coughed up:
>>>
>>>
>>>>Thomas G. Marshall wrote:
>>>
>>>
>>>...[rip]...
>>>
>>>
>>>
>>>>>Take a look at the following in a goto-enabled language:
>>>>>
>>>>> for (int z = 0; z < 10; z++)
>>>>> for (int y = 0; y < 10; y++)
>>>>> for (int x = 0; x < 10; x++)
>>>>> if (array[z][y][x] == somethingNeeded)
>>>>> goto hop_out;
>>>>> hop_out:
>>>>> (continue on)
>>>>>
>>>>>Is /this/ something that bothers your sensibilities?
>>>>>
>>>>
>>>>Yes, but more that it's a horrible construct, then that it contains
>>>>a goto.
>>>>
>>>>Here is another option, that does the same thing, but is, IMNSHO
>>>>clearer;
>>>>bool onlyFirst = true; // only find first somethingNeeded
>>>>
>>>>for (int z = 0; z < 10 && onlyFirst == true; z++)
>>>>for (int y = 0; y < 10 && onlyFirst == true; y++)
>>>> for (int x = 0; x < 10 && onlyFirst == true; x++)
>>>> if (array[z][y][x] == somethingNeeded)
>>>> {
>>>>onlyFirst == false;
>>>>// do other stuff
>>>> }
>>>
>>>
>>>Ok, good. now there is a stake in the sand. That you have an issue
>>>with the UDP example of mine is fine for the moment, because I was
>>>purposefully establishing something [far] less ideal. I supplied
>>>two examples of varying complexity and worth and you've precisely
>>>placed your position on this. Thank you for that, now we're
>>>/somewhere/. I think that the nested loop you provide is not only slower
>>>(which
>>>in this example is hardly an issue), but a harder to maintain
>>>obfuscated mess. Back in my C days, had one of my guys attempted
>>>this, he would have received a quick conversation from me.
>>
>>See below
>>
>>
>>>You've taken 3 loops, each of which contained only a single
>>>conditional for the engineer to parse through, and added to each one
>>>an additional conditional that must be parsed and evaluated /by the
>>>engineer/ in order to make sure that any change made to the body of
>>>the loop doesn't explode the loop itself around his ears.
>>>
>>>Your following statement of:
>>>
>>> The Wogster:
>>> Where the goto becomes a problem, is when do
>>> other stuff is 30 lines, so that the goto is a couple
>>> of screens later, and someone not realizing that
>>> the for gets usurped later on, adds code between
>>> the "for (int z"and the "for (int y" that counts on z
>>> getting to 10.
>>>
>>>is incredibly broken logic. If the "do other stuff" were 30 lines,
>>>then you'd *PARTICULARLY* not want the loop you describe. It would
>>>require the engineer to wade through 30 lines of code to make sure
>>>that the onlyFisrt boolean was not altered within it. Furthermore,
>>>any change to those 30 lines 4 weeks later by another engineer holds
>>>the possibility of breaking the loop itself even if he's very
>>>senior, but hopped on caffeine at 3 am. You would have dragged the
>>>logic of the loop itself into 30 additional lines, when the loop
>>>should have instead merely been just that: a nested loop containing
>>>just the logic needed to form the loop.
>>
>>With the goto, the engineer needs to look for something, they may not
>>even realize exists. My solution, indicates that the loop has TWO
>>conditions, which it does, so does yours, but it may not be clear that
>>there are two conditions, the for only has one condition, even though
>>the loop has two. That can be dangerous, when the engineer is
>>debugging code at 3am, knowing that the application takes 6 hours,
>>and needs to be finish running by 7.
>>
>>The flag, indicates that there IS two conditions, so a quick search
>>will find the second condition.
>
>
>
> Now you're grasping at straws.
>
> In my case, each nested for() has a single conditional making 3 visible to
> the engineer. Add to this a conditional test within the 3 layer loop for
> exit. There is nothing hidden here at all.
>
> In your case, each for() has 2 conditionals making 6. Add to this the same
> conditional test I have in the middle, but place the code within the body of
> the loop where it is possible to truly muck up the looping logic.
>
Actually there are just as many conditions with your loop structure,
however it's ONLY clear if you either document it (unlikely), or the
code is a small snippet like in the example. However if there is a lot
of code, there is nothing in the code to connect the goto to the loop,
so here is where it starts looking more difficult:
for (int z = 0; z < 10; z++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
if (array[z][y][x] == somethingNeeded)
{
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
// more lines of code
goto hop_out;
}
hop_out:
Yes, this code is legal (C and C++ at least), even though it's confusing
, because you may not remember (a year later) that the goto is connected
to any of the loops. The flag version, may contain more conditionals,
however you know that the loop is connected to it, even though the
number of comments is the same. In other words the flag documents
itself. You know that another condition is connected to the loop.
You know as well as I do, that most C programmers would rather have
themselves boiled in oil, have all of their fingernails pulled out, and
be keel-hauled in acid then to voluntarily write the combination /* or
// any more often then required by employer standards.
Another possible way to write this is this way:
bool onlyFirst = true;
for (int z = 0; z < 10; z++)
{
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
if (array[z][y][x] == somethingNeeded && onlyFirst )
{
onlyFirst = false;
// do stuff
}
} // for (int x
} // for (int y
} // for (int z
In this case, you simply let the loops "deadhead" to completion, knowing
that the innermost condition will not trigger a second time, because the
condition can not be met the subsequent times. Of course you probably
don't like this either, it wastes some time running the loops, but in a
day when most processors are 1GHz and higher, that doesn't really matter
much.
However it still documents itself, and you can't get tripped up, by a
loop that does not complete. Even though the braces are not needed, I
usually put them in, along with the decorations, only because it makes
the code far easier to read, especially a year later when you can't
remember what you did, and the } is over a screen length away from the
related for.
W
>
>
>>I would like to continue, but don't have more time to spend on
>>this.....
>
>
>
> I too am getting tired. It's not that we disagree that is so tiring, but I
> just cannot even get /close/ to understanding your logic in this regard, try
> as I might to spell the examples out.
>
> You don't think so of course, but I still suspect that if you really thought
> it through honestly that you'd realize that much of your knee-jerk dismissal
> of the goto is only based upon itself and not on evidence. That you loathed
> it first, and then looked for and found the reasons why.
>
> But in any case, we're certainly going nowhere fast.
>
> Thanks for the discussion.
>
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-16 0:55:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Thomas G. Marshall wrote:
...[rip]...
>> In my case, each nested for() has a single conditional making 3
>> visible to the engineer. Add to this a conditional test within the
>> 3 layer loop for exit. There is nothing hidden here at all.
>>
>> In your case, each for() has 2 conditionals making 6. Add to this
>> the same conditional test I have in the middle, but place the code
>> within the body of the loop where it is possible to truly muck up
>> the looping logic.
>
> Actually there are just as many conditions
Nope. Only if you count the compound conditional as a single entity.
I'm regarding
for (int x = 0; x < 10; x++)
as easier to read than checking your *two* items, as you put it here:
for (int x = 0; x < 10 && onlyFirst==true; x++)
> with your loop structure,
> however it's ONLY clear if you either document it (unlikely), or the
> code is a small snippet like in the example. However if there is a
> lot of code, there is nothing in the code to connect the goto to the
> loop, so here is where it starts looking more difficult:
>
> for (int z = 0; z < 10; z++)
> for (int y = 0; y < 10; y++)
> for (int x = 0; x < 10; x++)
> if (array[z][y][x] == somethingNeeded)
> {
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
You forgot 3 :)
// more lines of code
// more lines of code
// more lines of code
> goto hop_out;
> }
> hop_out:
This is hardly what I was advocating! *If* we're going to spell out the 30
lines of code, then this is what it *should* look like.
for (int z = 0; z < 10; z++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
if (array[z][y][x] == somethingNeeded)
goto found;
//Not found handling here.
found:
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
> // more lines of code
In this way, the *entirety* of the loop is visible, and it is accomplishing
precisely one thing: the search. What happens as a *result* of *finding*
the first item is handled afterward, as it should be.
Keep those 30 lines the heck out of the loop, so that the tired engineer at
3am can see it easily and not @#$% up the boolean you added to each of the 3
nested checks.
And Keep those 30 lines the heck out of the loop because they are not being
done more than once anyway, as the bodies of loops are most often seen to
do.
...[rip]...
--
"His name was Robert Paulson. His name was Robert Paulson. His name was
Robert Paulson..."
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-16 2:28:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
> The Wogster coughed up:
>
>>Thomas G. Marshall wrote:
>
>
> ...[rip]...
>
>
>>>In my case, each nested for() has a single conditional making 3
>>>visible to the engineer. Add to this a conditional test within the
>>>3 layer loop for exit. There is nothing hidden here at all.
>>>
>>>In your case, each for() has 2 conditionals making 6. Add to this
>>>the same conditional test I have in the middle, but place the code
>>>within the body of the loop where it is possible to truly muck up
>>>the looping logic.
>>
>>Actually there are just as many conditions
>
>
> Nope. Only if you count the compound conditional as a single entity.
>
> I'm regarding
>
> for (int x = 0; x < 10; x++)
>
> as easier to read than checking your *two* items, as you put it here:
>
> for (int x = 0; x < 10 && onlyFirst==true; x++)
>
>
>>with your loop structure,
>>however it's ONLY clear if you either document it (unlikely), or the
>>code is a small snippet like in the example. However if there is a
>>lot of code, there is nothing in the code to connect the goto to the
>>loop, so here is where it starts looking more difficult:
>>
>>for (int z = 0; z < 10; z++)
>> for (int y = 0; y < 10; y++)
>> for (int x = 0; x < 10; x++)
>> if (array[z][y][x] == somethingNeeded)
>> {
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>>// more lines of code
>
>
> You forgot 3 :)
> // more lines of code
> // more lines of code
> // more lines of code
>
>
>> goto hop_out;
>> }
>>hop_out:
>
>
>
> This is hardly what I was advocating! *If* we're going to spell out the 30
> lines of code, then this is what it *should* look like.
>
> for (int z = 0; z < 10; z++)
> for (int y = 0; y < 10; y++)
> for (int x = 0; x < 10; x++)
> if (array[z][y][x] == somethingNeeded)
> goto found;
>
> //Not found handling here.
>
> found:
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
> > // more lines of code
>
> In this way, the *entirety* of the loop is visible, and it is accomplishing
> precisely one thing: the search. What happens as a *result* of *finding*
> the first item is handled afterward, as it should be.
>
> Keep those 30 lines the heck out of the loop, so that the tired engineer at
> 3am can see it easily and not @#$% up the boolean you added to each of the 3
> nested checks.
>
> And Keep those 30 lines the heck out of the loop because they are not being
> done more than once anyway, as the bodies of loops are most often seen to
> do.
>
>
So what we really end up with is something like this:
for (int z = 0; z < 10; z++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
if (array[z][y][x] == somethingNeeded)
goto found;
//Not found handling here.
goto skipfound:
found:
// more lines of code
.
. <skip>
.
// more lines of code
skipfound:
// more code that gets executed regardless.
So with 6 lines of logic (not including the labels, and other code) we
have 2 goto statements, your coming up a batch of spaghetti here.... I
prefer noodles, with a nice alfredo sauce, and some chicken mixed in, on
a plate, not on my screen.
Worse still, 3 years from now, when they need the if to iterate over
each occurance of something needed, and not just the first one, you need
to do a rewrite, or add even more gotos..... Where as the switching of
the flag can simply be commented out, which is why I came up with my
second version, something you never did comment on.....
Oh well, I need to go....
W
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-16 9:19:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Thomas G. Marshall wrote:
>> The Wogster coughed up:
>>
>>> Thomas G. Marshall wrote:
>>
>>
>> ...[rip]...
>>
>>
>>>> In my case, each nested for() has a single conditional making 3
>>>> visible to the engineer. Add to this a conditional test within the
>>>> 3 layer loop for exit. There is nothing hidden here at all.
>>>>
>>>> In your case, each for() has 2 conditionals making 6. Add to this
>>>> the same conditional test I have in the middle, but place the code
>>>> within the body of the loop where it is possible to truly muck up
>>>> the looping logic.
>>>
>>> Actually there are just as many conditions
>>
>>
>> Nope. Only if you count the compound conditional as a single entity.
>>
>> I'm regarding
>>
>> for (int x = 0; x < 10; x++)
>>
>> as easier to read than checking your *two* items, as you put it here:
>>
>> for (int x = 0; x < 10 && onlyFirst==true; x++)
>>
>>
>>> with your loop structure,
>>> however it's ONLY clear if you either document it (unlikely), or the
>>> code is a small snippet like in the example. However if there is a
>>> lot of code, there is nothing in the code to connect the goto to the
>>> loop, so here is where it starts looking more difficult:
>>>
>>> for (int z = 0; z < 10; z++)
>>> for (int y = 0; y < 10; y++)
>>> for (int x = 0; x < 10; x++)
>>> if (array[z][y][x] == somethingNeeded)
>>> {
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>> // more lines of code
>>
>>
>> You forgot 3 :)
>> // more lines of code
>> // more lines of code
>> // more lines of code
>>
>>
>>> goto hop_out;
>>> }
>>> hop_out:
>>
>>
>>
>> This is hardly what I was advocating! *If* we're going to spell out
>> the 30 lines of code, then this is what it *should* look like.
>>
>> for (int z = 0; z < 10; z++)
>> for (int y = 0; y < 10; y++)
>> for (int x = 0; x < 10; x++)
>> if (array[z][y][x] == somethingNeeded)
>> goto found;
>>
>> //Not found handling here.
>>
>> found:
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>> > // more lines of code
>>
>> In this way, the *entirety* of the loop is visible, and it is
>> accomplishing precisely one thing: the search. What happens as a
>> *result* of *finding* the first item is handled afterward, as it
>> should be. Keep those 30 lines the heck out of the loop, so that the
>> tired
>> engineer at 3am can see it easily and not @#$% up the boolean you
>> added to each of the 3 nested checks.
>>
>> And Keep those 30 lines the heck out of the loop because they are
>> not being done more than once anyway, as the bodies of loops are
>> most often seen to do.
>>
>>
>
>
> So what we really end up with is something like this:
>
>
> for (int z = 0; z < 10; z++)
> for (int y = 0; y < 10; y++)
> for (int x = 0; x < 10; x++)
> if (array[z][y][x] == somethingNeeded)
> goto found;
>
> //Not found handling here.
> goto skipfound:
> found:
> // more lines of code
> .
> . <skip>
> .
> // more lines of code
> skipfound:
> // more code that gets executed regardless.
Interesting technique: you've taken my example and added a goto to it in
order to make it look like it's overusing goto. This is a different example
where you have three pertinent sections:
found after searching and executed
non found after searching and executed
executed either way after searching
which has little to do with my example of two sections, something you still
didn't like and even opted for that extra flag check in each for() level and
placing the code executed once the thing was found /into/ the middle of the
loop, which as I pointed out opens you up for maintainability problems.
If you absolutely *must* honor all three possibilities in the same function,
then I would probably /then/ use a boolean for use /after/ the goto, but not
within the loop conditionals for obfuscation, and I certainly wouldn't have
the main logic appear within the loop like you favor. (again, this is an
arbitrary goto-enabled language):
boolean found = false;
for (int z = 0; z < 10; z++)
for (int y = 0; y < 10; y++)
for (int x = 0; x < 10; x++)
if (array[z][y][x] == somethingNeeded)
{
found = true;
goto hopped_out;
}
hopped_out:
if (found)
{
foundcode;
foundcode;
foundcode;
}
else // (!found)
{
notfoundcode;
notfoundcode;
notfoundcode;
}
bothcode;
bothcode;
bothcode;
...[rip]...
> Worse still, 3 years from now, when they need the if to iterate over
> each occurance of something needed, and not just the first one, you
> need to do a rewrite, or add even more gotos..... Where as the
> switching of the flag can simply be commented out, which is why I
> came up with my second version, something you never did comment
> on.....
I'm specifically commenting on things as close to one at a time as I can for
focus. This thread is out of hand as it is. In fact, too far so. If you
insist, then here is your example:
bool onlyFirst = true;
for (int z = 0; z < 10; z++)
{
for (int y = 0; y < 10; y++)
{
for (int x = 0; x < 10; x++)
{
if (array[z][y][x] == somethingNeeded && onlyFirst )
{
onlyFirst = false;
// do stuff
}
} // for (int x
} // for (int y
} // for (int z
You certainly can't be serious! Making loops run to completion
unnecessarily? What if the array is enlarged significantly? What if this
were done in multiple threads on top of all that?
There is such a thing as over-optimization, but terminating a loop when the
looping is no longer needed is certainly not one of them!
We really are going nowhere.
...[rip]...
--
Sometimes life just sucks and then you live.
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-16 10:04:00 |
Top |
java-programmer >> 2 extends
Thomas G. Marshall wrote:
>
> We really are going nowhere.
>
Agreed, thread ended.
W
|
| |
|
| |
 |
Virgil Green

|
Posted: 2005-6-17 2:07:00 |
Top |
java-programmer >> 2 extends
The Wogster wrote:
> Thomas G. Marshall wrote:
>>
>> We really are going nowhere.
>>
>
> Agreed, thread ended.
>
> W
34 messages in the thread (now 35...). Who wins the pool?
--
Virgil
|
| |
|
| |
 |
The Wogster

|
Posted: 2005-6-17 2:30:00 |
Top |
java-programmer >> 2 extends
Virgil Green wrote:
> The Wogster wrote:
>
>>Thomas G. Marshall wrote:
>>
>>>We really are going nowhere.
>>>
>>
>>Agreed, thread ended.
>>
>>W
>
>
> 34 messages in the thread (now 35...). Who wins the pool?
>
Having done additional thinking on this, the thread may have, to a large
degree, proved my point, when you absolutely need a goto, then your
design needs to be revisited.
Everyone who studies C, C++, Java, Basic or any other language that
contains a for statement, knows it's intended for fixed-length loops, so
perhaps the ideal is to use a different looping construct, such as a
while or do-while, loop-until or whatever else the language offers.
Then again looking for a specific value in a 3 dimensional array, should
probably be taking into account the other dimensions. Most searches on
multi-dimensional arrays, are only searching within one of the
dimensions, not all of the dimensions. Efficiency is not the name of
the game when the value your looking for in a 1000 x 1000 x 1000
dimensioned array is array[999][999][999]....
W
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-18 5:20:00 |
Top |
java-programmer >> 2 extends
The Wogster coughed up:
> Virgil Green wrote:
>> The Wogster wrote:
>>
>>> Thomas G. Marshall wrote:
>>>
>>>> We really are going nowhere.
>>>>
>>>
>>> Agreed, thread ended.
>>>
>>> W
>>
>>
>> 34 messages in the thread (now 35...). Who wins the pool?
>>
>
> Having done additional thinking on this, the thread may have, to a
> large degree, proved my point
No it didn't, and not to any degree. And attempting to revive this thread
as an attempt to claim false victory and throw in additional points is
hardly an intelligent idea.
--
Having a dog that is a purebred does not qualify it for breeding. Dogs
need to have several generations of clearances for various illnesses
before being bred. If you are breeding dogs without taking care as to
the genetic quality of the dog (again, being purebred is *not* enough),
you are what is known as a "backyard breeder" and are part of the
problem. Most of the congenital problems of present day dogs are
traceable directly to backyard breeding. Spay or neuter your pet
responsibly, and don't just think that you're somehow the exception and
can breed a dog without taking the care described.
|
| |
|
| |
 |
Thomas G. Marshall

|
Posted: 2005-6-21 3:50:00 |
Top |
java-programmer >> 2 extends
Bryce coughed up:
> On Fri, 10 Jun 2005 22:43:04 GMT, "Thomas G. Marshall"
> <email***@***.com> wrote:
>
>> Bryce coughed up:
>>> On Thu, 9 Jun 2005 13:38:40 +0200, "Irlan agous" <email***@***.com>
>>> wrote:
>>>
>>>> Hello i want to extend from 2 classes lik
>>>>
>>>> public class PatientImpl extends DataModel ,UnicastRemoteObject
>>>> implements PatientInterface throws RemoteExeption;
>>>>
>>>> But this gives an error message, dfoes anyone knows how to solve
>>>> this?
>>>
>>> No multiple inheritence in Java.
>>
>> {cough, cough}....except for interfaces.
>
> Well, That's not technically inheritence...
>
> Java classes inherit other classes
> Java classes implement interfaces.
>
> But I get the point, and duly noted
Are you sure? Take a look at the following:
interface A { void a(); }
interface B { void b(); }
interface C extends A,B { void c(); }
C is a valid interface declaration. It requires a(), b(), and c().
--
"His name was Robert Paulson. His name was Robert Paulson. His name was
Robert Paulson..."
|
| |
|
| |
 |
| |
 |
Index ‹ java-programmer |
- Next
- 1
- JSP questionshave some questions about JavaServer Pages to ask
1. I made several input fields for user to input the height, width and
other stuff to create a table. how can I make the font in color red in
first row and first column automaticly and font in other rows and
columns remain the same color?
2. I want to add a title inside the table that need to colspan the
rest of the table. Becasue I don't know what # the user will input for
columns, so I can't set it before user input. so plz help me on this.
3. Randomly place an input field in one of the cells ?a different
cell on each refresh. If the user enters the correct product there and
changes the focus (by clicking outside the field), a Javascript
provided by the jsp page checks the answer and makes appropriate alert
My jsp file looks like this:
<HTML>
<head></head>
<BODY>
<%
String s2 = request.getParameter("Bsize") ;
s2 = s2.trim();
out.print("<table bgcolor=silver border= ");
out.print(s2);
out.print(" ");
String s3 = request.getParameter("Bcolor") ;
s3 = s3.trim();
out.print("bordercolor= ");
out.print(s3);
out.print(">");
String m1 = request.getParameter("mName") ;
m1 = m1.trim();
int M = Integer.parseInt(m1);
String n1 = request.getParameter("nName") ;
n1 = n1.trim();
int N = Integer.parseInt(n1);
String s = request.getParameter("FullName") ;
s = s.trim();
out.println("<font color=red size=6>");
out.println(s);
out.println("'s table is: </font>");
out.println("<tr colspan= ");
out.print(m1);
out.println(">");
out.print("<th> Numbers </th> </tr>");
for (int i =1; i<= M; i++ )
{
out.println("<tr width= 10 >");
for (int j =1; j<= N; j++ )
{
out.println("<th >");
out.println(j * i);
out.println("</th>");
}
out.println("</tr>");
}
%>
</table>
- 2
- imageicon problemHello,
I have problem with loading an image from a directory.
I got a folder called images wich is located in my project directory :
c:\MijnJava\Swing_01.
But when i start this application i get a window with a title and in this
window a square that indicates that the picture is not found. Earlier i set
my classpath : set classpath= .;c:\MijnJava; this is in windows xp.
I am using Jcreator. The code works fine on my computer in school but not at
home.
I tryed moving the folder images to other directorys but with no luck.
What is the problem with this?
Can anyone help?
thanks
Tom
import javax.swing.*;
import java.awt.*;
import javax.swing.border.*;
import tomwouters.myswingutils.*; This is a folder where my packages
are.
public class Afbeelding_01 extends ExitableJFrame{
public Afbeelding_01(String titel){
super(titel);
TitledBorder paneelBorder =
BorderFactory.createTitledBorder("JPanel");
Container container = getContentPane();
JPanel paneel = new JPanel();
paneel.setBorder(paneelBorder);
JLabel label = new JLabel();
JLabel label2 = new JLabel();
ImageIcon afbeelding = new ImageIcon("images/jugg23.gif");
label.setIcon(afbeelding);
TitledBorder labelBorder =
BorderFactory.createTitledBorder("JLabel met jugg23.gif");
label.setBorder(labelBorder);
paneel.add(label);
container.add(paneel);
pack();
}
public static void main(String[] args) {
Afbeelding_01 frameMetAfbeelding = new Afbeelding_01("Afbeelding_01");
frameMetAfbeelding.setVisible(true);
}
}
- 3
- Grab common name from https://[ip]Hello,
I checked around on here a bit, and was unable to find an answer to
this one by searching for the error message. I'm hoping someone here
can help me with this issue.
I am attempting to gather the common name from an SSL certificate for a
given IP address. Following is the code I am using thus far (two
classes being used):
IP_Justification.java:
import java.net.*; //for https connection
import java.io.*; //for input parsing
import javax.net.ssl.HttpsURLConnection;
public class IP_Justification
{
private String IP; //IP address to search
private String domain; //common name returned by viewing IP via
https://ip
//default constructor
public IP_Justification()
{
throw new IllegalArgumentException("Please provide IP and domain");
}
//create with IP provided
public IP_Justification(String ip)
{
IP = ip;
domain = "";
}
public void getDomain() throws IOException
{
String urlToCheck = "https://" + IP;
URL techURL = new URL(urlToCheck);
System.out.println("URL created: " + techURL);
HttpURLConnection techUrlConn =
(HttpURLConnection)techURL.openConnection();
System.out.println("HttpURLConnection created" + techUrlConn + "\n");
techUrlConn.connect();
}
}
IPJustMain.java
import java.io.*;
public class IPJustMain
{
public static void main(String[] args) throws IOException
{
IP_Justification testing;
testing = new IP_Justification("64.233.167.99");
testing.getDomain();
try
{
}
catch(Exception e)
{
System.out.println("Start of output - Exception block");
System.out.println(e.getMessage());
System.out.println("End of output - Exception block");
}
}
}
Following is the output received when running IPJustMain:
URL created: https://64.233.167.99
HttpURLConnection
createdsun.net.www.protocol.https.DelegateHttpsURLConnection:h
ttps://64.233.167.99
Exception in thread "main" java.io.IOException: HTTPS hostname wrong:
should be
<64.233.167.99>
at
sun.net.www.protocol.https.HttpsClient.checkURLSpoofing(HttpsClient.j
ava:490)
at
sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:
415)
at
sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(AbstractDelegateHttpsURLConnection.java:170)
at
sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLCon
nectionImpl.java:133)
at IP_Justification.getDomain(IP_Justification.java:54)
at IPJustMain.main(IPJustMain.java:15)
Press any key to continue . . .
I fully expect to have an exception thrown, and am hoping to be able to
parse that for the information I require. The problem I am running
into is the exception itself:
Exception in thread "main" java.io.IOException: HTTPS hostname wrong:
should be
<64.233.167.99>
It seems to be responding with the URL I pass to it, and not the common
name for the SSL at the specified IP address.
Anyone happen to know if there is a way around this or if my code is
flawed in someway?
Thanks for any help that can be provided!
- 4
- How to speed up the Portal development in eclipseHi all,
I am new in portal development. I am used to Eclipse to write Java
standalone application, but no server contained application such as
servlet.
Is there any way to setup a integrated development environment with
JetSpeed in Eclipse to do portal environment?
Please enlighten me.
Thanks in advance for your inputs and ideas.
Eclifeww
- 5
- Midlet TextBox-------------------
TextBox tb = new TextBox("title", null, 5, TextField.DECIMAL);
tb.addCommand(new Command("Ok", Command.BACK, 0));
tb.setCommandListener(this);
Display dis = Display.getDisplay(this);
dis.setCurrent(tb);
-------------------
The code above shows (in my mobile Sony Ericsson K300i) a TextBox with 2
Commands "Ok" and "Ok".
If TextBox is empty of chars, first "Ok" is grayed but second not.
I suspect that the first Command "Ok" is part of TextBox (Screen) and
when I press it, it does nothing and commandAction method does not run.
Only when I press the second Command "Ok" commandAction method runs.
So, first "Ok" is "feature" of my mobile or it is in MIDP Specification?
If the second, how can I get access to this Command?
- 6
- <defunct> processesI've got a problem with <defunct> (zombie) processes on Linux...
I'm running child processes using Runtime.exec() and it usually goes well.
But just sometimes (undefined sometimes), process finishes as defunct. Is
there anything I can do about it? I suck out both inputStream and
errorStream, check Process.exitValue(), but it stucks on Process.waitFor().
I even try to suck these streams in separate threads, but it doesn't help.
I had the idea to detect if the process has stucked, and then try from
another thread to Process.destroy(), but it didn't help! Destroy does
nothing, process is still defunct, and waitFor() blocks it again... There
are no more methods in class Process to try, and I've already tried all the
combinations of existing ones...
Newsgroups and web are full of similar questions, but no answer. They all
say that a process is zombie if it is finished, but parent process hasn't
yet read the exit code. But I do read exitValue, and I also do
Process.waitFor(). Can I consider this a bug in Java VM?
Where could find the solution? Which direction should I go? I've been trying
for months, but no results...
Now, this is the latest version of code, as seen on java.sun.com...
{
...
Process process = Runtime.getRuntime().exec(commandLine);
inputVacuum = new TextVacuum(process.getInputStream());
errorVacuum = new TextVacuum(process.getErrorStream());
process.waitFor();
int exitValue = process.exitValue();
...
}
public class TextVacuum extends Thread {
private BufferedReader reader;
private StringBuffer buffer = new StringBuffer();
...
public TextVacuum(InputStream inStream) {
reader = new BufferedReader(new InputStreamReader(inStream));
start();
}
public void run() {
try {
char[] cbuf = new char[4096];
int numRead = reader.read(cbuf);
while (numRead != -1) {
buffer.append(new String(cbuf, 0, numRead));
numRead = reader.read(cbuf);
}
}
catch (IOException e) { }
finally {
try { reader.close(); }
catch (IOException e) { }
reader = null;
}
}
...
}
Thanks!
- 7
- Baffling class not found problemHello, I'm using Java 1.3 with WebLogic 5.1 on Solaris. I have these
files:
cms/system/CMSException.class
cms/system/Constants.class
cms/system/InitServlet.class
cms/system/Log.class
When I include this line on my JSP page
<%@ page import="cms.system.*" %>
everything compiles fine. As does this line
<%@ page import="cms.*" %>
but when I try
<%@ page import="cms.system.Constants" %>
(r using any of the 4 class names above) I get the error:
Compilation of '/tmp/support/jsp_servlet/_www/__temp.java' failed:
/tmp/support/jsp_servlet/_www/__temp.java:16: Class
cms.system.Constants not found in import.
probably occurred due to an error in /www/temp.jsp line 1:
<%@ page import="cms.system.Constants" %>
How can this be? The perms on the files above are all 775. Can anyone
think of an explanation for why these files can't be found?
Thanks, - Dave
- 8
- Can we change enctype dynamically??Hello all,
Can we change enctype in the form tag using javascript
document.formname.enctype = 'variable' variable being
multipart/form-data or application/x-www-form-urlencoded. I can do
this in Netscape7 not in IE6 ??
My problem is when I am in the rendered page of type
mulipart/form-data, I have to call another servlet (which process
regular form fields only). When I do that it breaks.
If I use all my servlets to process enctype=mulipart/form-data jsp's
is there any performance or any kind of issues???
Any help will be appreciated.
Thanks - gsr
- 9
- AccessControlException
The following is a snippet from a method in an applet RSSTree:
private Document getOPMLFile(String OPMLFileName) {
Document OPMLFile = null;
try {
URL u = new URL(getCodeBase(), OPMLFileName);
try {
BufferedReader br = new BufferedReader(new
InputStreamReader(u.openStream()));
if (br != null) {
try {
Builder parser = new Builder();
OPMLFile = parser.build(br);
}
.
.
.
This method is called out of RSSTree.start(). Document & Builder are
classes in the open source XML processor com.nu.xom. I get the following
error when parser.build(br) is executed:
java.lang.ExceptionInInitializerError
at RSSTree.getOPMLFile(RSSTree.java:63)
at RSSTree.start(RSSTree.java:31)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.security.AccessControlException: access denied
(java.util.PropertyPermission
org.apache.xerces.xni.parser.XMLParserConfiguration write)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.System.setProperty(Unknown Source)
at nu.xom.Builder.<clinit>(Unknown Source)
If I replace the bad line with a loop to read the the stream myself and
write out the lines, I get the XML I expect.
Without seeing the source for XOM can someone give me an idea as to why I
have an access problem when going through XOM but don't when the applet
reads directly?
Thanks.
Ken
- 10
- Whatever happened to PvdL?My curiosity about Hotjava now sated, what of Peter van der Liden? I recall
that he used to be pretty active on Usenet and quite a prolific author and
Java advocate.
As I recall he used to author the Java FAQ (which now 404's). I liked his
writing style (dating to the ugly fish book) and the Just Java series. The
6th edition came out in 2004 and no errata has published since January
2005.
Is Mr. van der Liden still active in the Java community? I realize he's no
longer with Sun and without treading into personal matters, did he have a
falling out with the people there? In spite of being published by Sun, his
Java books did contain quite a few barbs about misfeatures in the language.
- 11
- Applet file readinghello every one;
i m making an applicaion by using java Applet, on which i wish to open
a file from users system, but i dont know how to do this;
is any one have any idea about reading files on users system by using
Applet.
- 12
- [OT] gov't sponsored drug development"Peter Koehlmann" <email***@***.com> wrote:
> Tim Tyler wrote:
>> Development of life-saving drugs would be sponsored by the government.
> What universe was it you said you live in?
Oh, probably the one where in the US at least, the National Institutes
of Health do exactly that, every business day.
Tim lives in one of the civilized countries where they have Public
Health for all, and of course there, the government is money ahead
if new drugs cut down the total balanced cost of treating the ill and
compensating for the other disbenefits to society that illness causes,
even at the tax base level, and if they had any brains would realize
that and fund research accordingly.
xanthian.
--
Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
- 13
- database connection pooling in tomcat 3.3.1Hi,
I have a webapp which uses database connection pooling setup just like
the tomcat how-to suggests. But, I can't seem to get it to work on
tomcat 3.3.1. I couldn't even find any how-tos or guidances on it
anywhere. Is it supported ?
I get a javax.naming.NoInitialContextException: error when I set it up
in the conf/app-myapps.xml like the 3.3.1 doco suggests.
Appreciate any help on this.
Regards,
Lenine
- 14
- jsp servlet code seperation confusionI posted this on the .help NG but I believe you folks could probably
provide more of an accurate answer considering the help group is
targeted towards true beginners.
Okay, where I am employeed I have the options of programming with
Microsoft Technologies and Java specifically J2EE. I have been
investigating the task of learning Java for about the last 3 to 4
months. I am a ASP.Net developer fulltime at work with C#. I was new to
OOP when I started into .Net about a year ago and am getting better.
However, our corporation uses Java as a National standard and I am
looking to advance some day and need to learn Java. Furthermore, where I
live, KY there are very few jobs for technologies other than .Net and
Java. No PHP or ColdFusion.
In the last couple of years this code seperation theory has overloaded
the programming world. .Net does it with what's called code behind. In
my research of Java the only things I see that reference code seperation
is servlets (I am sure J2EE and EJB contribute also). However,
everything I have read on servlets reference outputing HTML back to the
browser via the HttpServletResponse and Request objects.
My question, why in the world do they consider outputting HTML back to a
browser via a servlet considered code seperation. Furthermore, it
seems very time consuming and difficult to hand code complex layouts in
HTML and incorporate/format it for a servlet.
Can someone please explain or direct me to a resource where I can
understand why using servlets at any point in an application would be
better than jsp or even applets? Sometimes it's hard enough to design
complex layouts with the assistance Dreamweaver for example.
Thanks for any insight you can provide, I have read hundreds of pages of
information concerning this and trying to compare it with the my current
knowledge in the .Net world.
Marty U.
- 15
- Learning Apache Ant, problems with Swing(?)I'm attempting to learn Apache Ant (apache-ant-1.6.1); OS Linux Fedora
Core 2; j2sdk1.4.2_04. I appear to have problems with Ant + Swing, but
each work separately.
The following is my first build file (copied from the web).
<?xml version="1.0"?>
<!-- build file for lesson 1 -->
<project name="tutorial" default="build" basedir=".">
<target name="build">
<javac srcdir="." />
</target>
</project>
Works fine on a simple Java program, e.g.
import java.io.*;
public class Hello {
public static void main(String args[]) {
System.out.println("Hello");
}
}
However, when I progress to anything involving Java Swing, I get
compilation errors like:
[javac] /home/jc/java/classes/anttest/GuiScreens.java: In method
`GuiScreens.main(java.lang.String[])':
[javac] /home/jc/java/classes/anttest/GuiScreens.java:24: error:
Can't find constructor
`javax.swing.JFrame(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)'
in type `javax.swing.JFrame'.
[javac] frame[j][i] = new JFrame("Config: " + i,
gc[i]);
/This program compiles okay using javac./
(BTW jc@localhost~/java/classes/anttest>$ echo $ANT_HOME
/usr/apache-ant-1.6.1
jc@localhost~/java/classes/anttest>$ echo $JAVA_HOME
/usr/java/j2sdk1.4.2_04)
Any ideas?
TIA,
Jon C.
|
|
|