This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of React Cookbook: Recipes for Mastering the React Framework and have David Griffiths & Dawn Griffiths on-line!
See this thread for details.
Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!

Stephen Bloch

Ranch Hand
+ Follow
since Aug 19, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
2
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Stephen Bloch

I've never really liked the ?: ternary operator syntax, but the last time I taught CS1, I used a predominantly functional paradigm and it was natural to introduce ?: before if/else. Later on in the semester, when we had both features, we found that whenever we converted an if/else to a ?:, the code became significantly shorter and often clearer.
7 years ago
OK, I knew about the lambdas, and have been looking forward to them with bated breath for months. They won't make Java code as short and clean as Haskell code, or even Scheme code, but much shorter and cleaner than it has been. Yay!

I hadn't heard that you could now put static methods into an interface; I've been kvetching about that for YEARS. From a programmer's perspective, an "interface" should be a collection of method specifications that all implementing classes support, and there's no obvious reason static methods (e.g. pseudo-constructors) should be excluded from that. The implementation explanation, that interfaces are about run-time polymorphism and a static method isn't subject to run-time polymorphism, always struck me as missing the point. Also yay!
7 years ago
Bingo! I told you it was really basic....
15 years ago
OK, this is much more basic than I thought. I thought the difficulty might have something to do with the constructor, the anonymous inner class, maybe the cases in the class name... so I reduced the program to



and I'm still having the problem: it compiles and runs fine under BlueJ, it compiles and runs fine on the Mac command line, it compiles but doesn't run on the Windows command line.

I hate Windows....I hate Windows....I hate Windows....I hate Windows....
15 years ago
I wrote up a sample program for my students (it's a JFrame, with SwingUtilities.invokeLater and an anonymous inner class, none of which I think is actually relevant to this question).

It compiles and runs under BlueJ, on both Mac and Windows. It compiles and runs from the command line on the Mac. It compiles from the command line on Windows, but when I try to run it, I get a NoClassDefFound exception on the main class.

Are there common reasons that this kind of thing would happen? (For example, spaces in a directory name on Windows?)
15 years ago
Any further developments in this area since the last post, over 2 years ago? Are there any good Java interfaces to OpenGL? Or do I have to teach my graphics course in C++?

Does anybody here have experience teaching a graphics course using OpenGL or Java3D?
[ June 27, 2005: Message edited by: Stephen Bloch ]
16 years ago
I've been tapped to teach the undergraduate computer-graphics course at
Adelphi this fall. Problem is, I'm not really a specialist in computer
graphics, so I haven't spent any time keeping up on the current textbooks,
and I'd love some recommendations from people who have.

The course will contain a mix of college sophomore, junior, and senior
computer-science majors. Theoretically, all will have taken at least a year of Java, a month of C/C++, a semester of linear algebra, and a semester or two of calculus. We have a separate course (which I just taught) on GUI programming, so we don't need to emphasize that aspect, but instead spend our time on 2-D and 3-D rendering, shading and surface effects, etc., including the use of some (unspecified) graphics package: in the past I've used SRGP/SPHIGS and (more recently) OpenGL, but I was thinking of using Java3D this time; any advice on this?
16 years ago
I was teaching a bunch of college students about Java threads today, and gave an example in which two threads share an int counter, without giving any consideration to synchronization, and jointly count down from 100 to 0. I showed how most of the time the count goes smoothly, but once in a while you get "78...77...77...76...74...73..." or the like. So then I introduced "synchronized" to fix the problem. Except that some of my students had never seen the problem, so they couldn't tell if it was fixed. Specifically, the students running JDK 1.5 never got duplicate or skipped numbers. Why not? What has changed in the thread libraries that makes threads behave more predictably? And how can I still illustrate the need for synchronization?



(By the way, that code structure was a poor choice pedagogically: synchronizing the run() method doesn't do anything, because the two run() methods have different "this"es. I'll redesign this before the next time I present it. But that's not the question at hand....)
There are, BTW, good reasons that Java doesn't allow multiple inheritance. For example, consider

If you call whatDoesThisDo() on a Boojum object, which version of x does it increment? Which version of y does it decrement? Which version of doSomething() does it call? It's not clear what the program is supposed to do, much less how to make the compiler and JVM do that.

In C++, there are obscure rules to control which of these things happens, and you can change which one happens by using the keyword "virtual" (yet another of the half-dozen meanings of that keyword in C++). The designers of Java decided to avoid all those problems by just not allowing multiple inheritance. It turns out that to avoid all these vexing issues, it suffices to make sure no class inherits from two different parents that have instance variables, and no class inherits from two different parents that have method implementations; these are exactly the constraints imposed on the Java "interface" construct, so we can inherit from multiple interfaces but only one class.

That said, there are situations in which multiple inheritance would be nice. For example, I like to introduce linked lists in the classroom via polymorphism, rather than with an "if (current == null)" statement. (For details, see my paper on the subject.) When I move on to doubly-linked lists, I may write

It would save some trouble, and avoid some duplicate code, if HasSuccessor and HasPredecessor could have instance variables and default implementations of certain methods. But they can't, in Java. Arguably a small sacrifice for avoiding all the headaches of multiple inheritance.
[ March 29, 2005: Message edited by: Stephen Bloch ]
16 years ago
I don't have Eclipse 3 yet, because I haven't upgraded my Mac to OS 10.3 yet, because 10.4 will be out any month now.
16 years ago
When I type "ant -version" at the command line, I get 1.6.2, dated July 16, 2004, but I think Eclipse is using a 1.5.3 plugin. Where can I get an updated plugin?
16 years ago
I'm trying to write a client/server program, and to test it I need to start the server, leave it running, and then run the client. Is there a way to do both of these from within an ant task? Everything I've tried results in ant waiting for the server to terminate before it goes on to the next subtask, which is running the client.

So what have I tried?
1)

This produces the error message "The <java> task does not support the spawn attribute," directly contradicting the ant documentation. See
this thread.
2) <exec executable="${basedir}/serverd"/>
where "serverd" is a shell script looking like


This successfully starts the server, but ant never gets past it to do anything else.
16 years ago
The assignment says "4 byte numeric, magic cookie value. Identifies this as a data file." If it didn't matter what the 4 byte numeric was, it wouldn't really serve the purpose of "identifying" data files, would it? I think the programmer would be within his/her rights to reject any file that doesn't start with the same 4-byte numeric as is in the given file. OTOH, the assignment doesn't specifically say you have to verify the cookie value, so I'll probably hard-code the magic cookie value and issue a warning if it doesn't match.
I just downloaded my SCJD assignment (Bodgitt & Scarper), and the instructions specify that there's ONE application, which runs as either server, client, or stand-alone depending on its command-line argument. I expect this is what they wanted in your assignment too.
Aha; I had gotten it to work using force=true, but I hadn't realized why that was necessary. The Thread approach makes sense, although it seems like more hassle than should be necessary. Thanks!

Umm... by "unbind()", you did mean "unexportObject()", didn't you?
[ January 04, 2005: Message edited by: Stephen Bloch ]
16 years ago