comp.lang.java.programmer http://groups-beta.google.com/group/comp.lang.java.programmer [EMAIL PROTECTED]
Today's topics: * I/O Deadlock. - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b85e662ab698cca4 * Java History - 4 messages, 4 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5712674adb50bd0e * OpenLDAP + java + changing user's passwords - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aabcc64718ab59bc * Using reflection - 3 messages, 3 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e55612b759c1004 * LDAP character encoding - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2cd78003c51f2560 * What's New on the Web : 2004-12-10 - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/36fd1acfbf151b3e * plugin & packages - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f8770143f9f32c9 * swing JInternalFrame focus management - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4a071968367d7dcc * Can Java Programmer Learn C++ Quickly? - 4 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c7a28aa864e41ec * execution speed java vs. C - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e8713e999b13b7d1 * Java double precision - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ffd916b2ccb1a75b * Problem in Paint method - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/57896100121a1d97 * Unique key and value - 2 messages, 2 authors http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3f78fd73e6d5dce7 * Interesting design question involving ZIPs and servers - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d93856e0b568e2e4 * Servlets sessions - 1 messages, 1 author http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/30ab0398a5b15244 ============================================================================== TOPIC: I/O Deadlock. http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/b85e662ab698cca4 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 1:31 am From: David Zimmerman Ken Adams wrote: > Basically I have a client/server system and I implement the following ocde > to set up the streams on both the client and the server. > I seem to have deadlock when program execution enters this area. How to I > stop the deadlock between the client and server? > Thanks > > > Socket socket = new Socket(hostName, port); > ObjectInputStrem inStream = new ObjectInputStream(new > BufferedInputStream(socket.getInputStream())); > > ObjectOutputStream outStream = new ObjectOutputStream(new > BufferedOutputStream(socket.getOutputStream())); > > The ObjectOutputStream constructor writes a header onto the given stream. The ObjectInputStream constructor reads the header. If there is nothing to read, the constructor will wait fot it. So, be careful what order you create the various Object stream objects on each side. ============================================================================== TOPIC: Java History http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5712674adb50bd0e ============================================================================== == 1 of 4 == Date: Thurs, Dec 9 2004 6:22 pm From: Steve Sobol Chris Smith wrote: > At the time of Java 1.2, a lot of changes got made. Though there were > actually no changes at all to the language specification, the main > changes were: a vastly expanded standard API, at least several times as > expansive as the 1.1 versions and including Swing and Java2D for the > first time and a completely revamped security model; a completely re- > implemented virtual machine, incorporating the then-new Hotspot > technology to do adaptive JIT compiling of code; and some great leaps > forward in the ease of use of the development tools (including the new > classloading scheme that distinguishes between the boot classloader and > the system classloader). There were other changes as well. Right. And has anyone figured out why "Java2" 1.2 wasn't properly named Java 2.0 by the braintrust at Sun? There *were* a huge number of changes. -- JustThe.net Internet & New Media Services, http://JustThe.net/ Steven J. Sobol, Geek In Charge / 888.480.4NET (4638) / [EMAIL PROTECTED] PGP Key available from your friendly local key server (0xE3AE35ED) Apple Valley, California Nothing scares me anymore. I have three kids. == 2 of 4 == Date: Thurs, Dec 9 2004 11:40 pm From: "Tom Dyess" Sun does something similar with SunOs and Solaris: SunOs 5.7 is also Solaris 7; SunOs 5.8 is also Solaris 8, etc. Must be a cultural thing from way back when that just stuck. "Chris Smith" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: >> Being new to Java, I am trying to get a little history. >> >> Currently everything is referenced as some type of J2 (J2SE, J2EE, >> J2ME). >> >> I am wondering when/if there was ever a J1SE, J1EE, etc ... > > Not exactly. > > First there was Java 1.0.2 (the first public release). Then there were > several 1.1 releases. Then there was 1.2. > > At the time of Java 1.2, a lot of changes got made. Though there were > actually no changes at all to the language specification, the main > changes were: a vastly expanded standard API, at least several times as > expansive as the 1.1 versions and including Swing and Java2D for the > first time and a completely revamped security model; a completely re- > implemented virtual machine, incorporating the then-new Hotspot > technology to do adaptive JIT compiling of code; and some great leaps > forward in the ease of use of the development tools (including the new > classloading scheme that distinguishes between the boot classloader and > the system classloader). There were other changes as well. > > Primarily because of Hotspot, and partially because of Swing, Sun felt > that they had turned a corner, if you will, and that all the prior > critiques of Java, which were mostly aimed at performance, no longer > applied. Hence, they felt the need for a new name, and they called the > release version 1.2 of the "Java 2" platform. History has proven them > right in that time efficiency is nowhere near the concern for Java that > it was; but I'm not sure how much good that marketing decision of "Java > 2" actually did. > > -- > www.designacourse.com > The Easiest Way To Train Anyone... Anywhere. > > Chris Smith - Lead Software Developer/Technical Trainer > MindIQ Corporation == 3 of 4 == Date: Thurs, Dec 9 2004 11:46 pm From: "Hal Rosser" "Kieron Briggs" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [EMAIL PROTECTED] wrote: > > Being new to Java, I am trying to get a little history. > > > > Currently everything is referenced as some type of J2 (J2SE, J2EE, > > J2ME). > > > > I am wondering when/if there was ever a J1SE, J1EE, etc ... > > > > What does the 2 stand for? Was there some type of major revision? > > The numbering system of Java has been.... erratic. > > From memory (and I'm sure others will correct me here...) > > In the beginning there was Java, which was also called Java 1.0. > > Then there were some improvements to the standard API, and Java 1.1 was > born. > > Then there were some more improvements to the standard API and Java 1.2 > was born. But for some reason (I think it had to do with the bad press > Java 1.0 had received for being slow), they decided to also call this > Java 2. And to complicate matters more, there was the Standard Edition > (which had all the standard APIs) and the Enterprise Edition (which had > some extra APIs like mail and so on). > > Then there were some more changes to both the standard APIs and the > enterprise APIs, and Java 1.3 was born. However, this was still called > Java 2, not 3. Go figure. Ditto for Java 1.4. > > Now we are just arriving at Java 1.5. This is the first version to > introduce really major language changes (generics etc) as well as API > improvements. I think they're trying to get people to call this Java > 5.0... ;-) > In the beginning - the language was called 'Oak', and was too far ahead of its time, because it was made for refrigerators, washing machines, etc (a language for appliances). Now who wudda thunk there would be programs for telephones you could just walk around with. --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.807 / Virus Database: 549 - Release Date: 12/7/2004 == 4 of 4 == Date: Thurs, Dec 9 2004 9:55 pm From: Chris Smith Tom Dyess <[EMAIL PROTECTED]> wrote: > Sun does something similar with SunOs and Solaris: SunOs 5.7 is also Solaris > 7; SunOs 5.8 is also Solaris 8, etc. Must be a cultural thing from way back > when that just stuck. Well, that's a tad different from what happened with Java 2. "Java 2" is a product, and it has several versions, of which 1.2 is only the first one. Though it's confusing to have a numeral in the product name, it does actually make sense from an objective standpoint. However, Solaris is *exactly* reminiscent of the current "Java 5.0" fiasco. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: OpenLDAP + java + changing user's passwords http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/aabcc64718ab59bc ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 7:44 pm From: Anzime JScoobyCed wrote: > Eric Gutierrez wrote: > >> >> 1. Will the user be able login with the new password from the program >> below if LDAP server is expecting the password to be encrypted in >> SSHA1 (or some other method)? >> >> 2. Will LDAP automatically encrypt the new plain text password for me >> when I run the program below? --how I wish... >> >> 3. Will I need to write code to encrypt the plain text password to >> SSHA1 before giving it to the LDAP server? If yes, where do I start - >> any API's out there to do this fast? > > > Hi, > > I am currently working with LDAP servers (Active Directory and Sun > iPlanet), but only in one way reading (that is, I read values from the > LDAP server, but I don't write any). > Password are encrypted on both server, but when I send a query to create > a context, I use the clear text password. I have no problem with that. > Now if I read that password, of course I got binary values for the > encrypted password. > I would say you don't need to encrypt the password to send it to your > LDAP server. But in fact that depends on the API you are using. I see > you use some netscape package. You should look at the documentation that > goes with that API. > Now if you need to encrypt data, you should have a look at the JCE API > (Java Cryptography Extension) > http://java.sun.com/products/jce/index-14.html > JCE is part of the J2SDK since it's 1.4.x version. Quoted: > "Support for the following algorithms by the SunJCE provider: > > * DES > * DESede > * AES (with Java 2 SDK, v 1.4.2) > * Blowfish > * PBEWithMD5AndDES > * PBEWithMD5AndTripleDES > * Diffie-Hellman key agreement among multiple parties > * HmacMD5 > * HmacSHA1 > " > > --- > JScoobyCed hash your password with using SHA1, create a LDAPAttribute with the hash, and call modify on the connection. -- Regards, Anzime ============================================================================== TOPIC: Using reflection http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/1e55612b759c1004 ============================================================================== == 1 of 3 == Date: Fri, Dec 10 2004 3:17 am From: "Ken Adams" How do you obtain on object refrence using reflection. I need the reference to the actual object not the class. Basically I want to have a server send a message to a client, the client will run the message, which will,using reflection set an Arraylist in the client to the same value as the arrayList that was sent with the message from the client. How do I do that? Thanks == 2 of 3 == Date: Thurs, Dec 9 2004 7:39 pm From: [EMAIL PROTECTED] Check out the Class object. http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html Create an instance using the newIntance() method - http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#newInstance() One thing to note: the class you are using reflection on must have a no argument constructor. hth, Brock == 3 of 3 == Date: Thurs, Dec 9 2004 11:37 pm From: "Stefan Schulz" On 9 Dec 2004 19:39:54 -0800, <[EMAIL PROTECTED]> wrote: > Check out the Class object. > > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html > > Create an instance using the newIntance() method - > http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Class.html#newInstance() > > One thing to note: the class you are using reflection on must have a no > argument constructor. This is only true if Class#newInstance is used. You can create Objects without a no argument constructor useing java.lang.reflect.Constructor objects. -- Whom the gods wish to destroy they first call promising. ============================================================================== TOPIC: LDAP character encoding http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/2cd78003c51f2560 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 11:08 am From: JScoobyCed smirks wrote: > Hi, > > I am retrieving some information from a Microsoft Active Directory > Server via Java's JNDI API. > > In particular, I'm trying to get an attribute called 'objectSID', which > is of type Octet-String on the active directory. > I believe the problem has to do with character encoding, but I don't > know how to proceed from here. I have tried various character sets when > converting 'value' to a byte array above, but to no avail. > Any help will be greatly appreciated. > > Regards, > Clyde > Hi, Man you are a lucky one :) I have been doing the same type of query (ObjectSID) a few weeks ago and met the same problem. And guess what, I found the solution. Step 1: The environment In the Hashtable that you use for the (Ldap)Context, you only need to add a parameter: Hashtable env = new Hashtable(); // ... put your env in the Hashtable env.put("java.naming.ldap.attributes.binary","objectsid"); Note: if you had to query also, say, jpegphoto attribute, you would do: env.put("java.naming.ldap.attributes.binary","objectsid jpegphoto"); All attributes in a space separated list. Step 2: The query: <pseudo-code> SearchControls ctl = new SearchControls(SearchControls.SUBTREE_SCOPE, 0, 0, new String[] {"cn","objectSid"}, true, false); NamingEnumeration ne = ctx.search("dc=mydomain", "cn=*", ctl); SearchResult sr = ne.nextElement(); Attributes atts = sr.getAttributes(); byte[] objectSid = (byte[])atts.get("objectSid"); </pseudo-code> Now, let's say you saved this objectSid in a database, and later you want to query a LDAP server for this objectSid ? Ok, here we go: <pseudo-code> SearchControls ctl = new SearchControls(SearchControls.SUBTREE_SCOPE, 0, 0, new String[] {"cn","objectSid"}, true, false); byte[] data = objectSid; // from previous code NamingEnumeration ne = ctx.search("dc=mydomain", "objectSid={0}", new Object[] {data},ctl); SearchResult sr = ne.nextElement(); Attributes atts = sr.getAttributes(); String cn = atts.get("cn").get(); </pseudo-code> This follows the Java pattern mechanism (not sure the real name of this concept). The query means: find in "dc=mydomain", the attributes that match objectSid={the 0th object in the argument parameter} which is Object[] {data} Hope this will help. --- JScoobyCed ============================================================================== TOPIC: What's New on the Web : 2004-12-10 http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/36fd1acfbf151b3e ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 1:10 pm From: etamp What's New on the Web : Today http://www.etamp.net/ =========================================================== Etamp(etamp.net) provides latest news of web sites around the globe. You can inform free of charge what is happening in your web site. To submit your releases, you must first become a member. It's free, fast and easy. ============================================================ ====== [ Win a great prize every day from now until Christmas Eve ] Win a great prize every day from now until Christmas Eve Every day from December 9 to Christmas Eve (except weekends), we will have a brand new pri¡¦ http://www.etamp.net/beta/?etamp=check_dir/news.html?&part=ws&number=1068 [ 'Tis the Season to Find Exoplanets ] This holiday season, advanced amateur astronomers can present the astronomical community with an extraordinary gift: the detection of a new transiting¡¦ http://www.etamp.net/beta/?etamp=check_dir/news.html?&part=ws&number=1067 [ New Zealand Immigration Programme ? Skilled Migrant Fortnightly Selection ] A selection of Expressions of Interest under the Skilled Migrant Category took place on 8 December 2004. The selection point was 100 meaning Express¡¦ http://www.etamp.net/beta/?etamp=check_dir/news.html?&part=ws&number=1066 [ Number One in China: Red Flag Offers Opera to Chinese Users ] Beijing, China and Oslo, Norway - Nov. 24, 2004 Red Flag Software, the leading supplier of Linux operating systems and applications in China, and O¡¦ http://www.etamp.net/beta/?etamp=check_dir/news.html?&part=ws&number=1065 ============================================================================== TOPIC: plugin & packages http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/5f8770143f9f32c9 ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 9:27 pm From: Chris Smith VisionSet <[EMAIL PROTECTED]> wrote: > > Sounds like you're making things harder than you need to (for example, > > you're loading the classes with Class.forName? Does that mean that > > you're placing these plugin classes in the classpath?) while > > simultaneously preventing people from using good programming techniques. > how do you mean? I mean that plugins should be loaded from a separate ClassLoader than the application. The application's ClassLoader should be its parent. To do otherwise is to make everything dependent on the CLASSPATH environment variable or equivalent command line options. Since the CLASSPATH is also used to locate application code, and frequently modified (against good judgement) by installation of third-party libraries, that's extremely fragile. This is a lesson that was learned long ago in Java. Take a look at java.net.URLClassLoader. It is the answer. You simply create one, give it the path where it should look to find the plugin classes, and call loadClass instead of Class.forName. > The purpose is really to avoid having to teach the plugin writer any more > than is strictly necessary to produce the plugin, since this is only a > simple demo app. Java knwoledge isn't an aim rather the algorithm they > write. I'd just like the writer of the plugin to just produce a classfile > and pop it in the right place for it to be detected. > > Do you have an improvement without the need to jar the plugin? URLClassLoader doesn't require you to use JAR files; you can give it either a directory or a JAR file, and it'll work fine. However, I'd strongly encourage you to provide at least the option to use JAR files. Again, by using loose class files you are begging for problems and frustration. You could easily define a plugin directory, and then allow plugin code authors to either drop a JAR file in there *or* create a subdirectory for their plugin. To be honest, I'd be searching for an alternative very fast if I needed to distribute loose class files to use your framework. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: swing JInternalFrame focus management http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/4a071968367d7dcc ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 8:45 pm From: [EMAIL PROTECTED] Some one? Anyone? -ryan ============================================================================== TOPIC: Can Java Programmer Learn C++ Quickly? http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/7c7a28aa864e41ec ============================================================================== == 1 of 4 == Date: Fri, Dec 10 2004 3:47 pm From: Ian T James Kanze wrote: > > Not only. Garbage collection is IMHO more than just a safety net. > There are a lot of cases where having done the design, it becomes > apparent that the exact end of lifetime isn't important. You have to do > the design, to know this, but once you know it, if you have garbage > collection, your work is done. Whereas in C++... EXACTLY! > > Curiously, I've had more problems with memory leaks in Java than in C++. > There's a psychological aspect at work -- in Java, you don't give it a > thought, so you slip up and forget for that JButton to deregister > somewhere. (Especially easy since the designers of Swing slipped up, > and forgot to inform the JButton that the window was being disposed.) Interesting. I'm not far enough into Java to be using the swing libraries as yet, but I'll keep that in mind for a future 'gotcha'. > > Just a fancy way of saying that in practice, I've seen more problems > with dangling pointers in C++ than with memory leaks. Which often cause segfaults at some later stage. >(And one of my C++ > applications runs 24 hours a day, 7 days a week, with contractual > penalties over something like 5000 Euro per minute for downtime.) Mmmmm, contractual penalties. > > It's true that C++ often interfaces directly to C level API's. And of > course, you have to use null terminated strings there. But that use is > generally limited to the interface level itself. Often you still need to know the problems with ntca's when using some of those interfaces. Some of the more, shall we say 'baroque', win32 APIs can get you into a lot of trouble without an understanding of char buffers. > All of Linux is in C, for example. How do you define 'All of Linux'. Is it every application written for Linux, or just the kernel and gnu tools? > > The sources of java.lang.String are available somewhere. My > pre-standard String class (dating from 1991) looked almost exactly like > it -- the main difference was that I used reference counting for garbage > collection, and I supported value semantics (but the only way to modify > a String originally was assignment -- I had a StringBuilder class which > worked a lot like StringBuffer). Did you implement the "+" operator with 'malloc' or 'new'? And the Length() function, did you use strlen, or did you have some other mechanism that kept track of the character length? Ian == 2 of 4 == Date: Thurs, Dec 9 2004 10:05 pm From: Chris Smith Ian T <[EMAIL PROTECTED]> wrote: > Interesting. I'm not far enough into Java to be using the swing > libraries as yet, but I'll keep that in mind for a future 'gotcha'. It definitely is a potential problem, but it's often overstated. This comes up when you have a listener which is supposed to be shorter-lived that the object it's listening to. If the listener is supposed to last the entire lifetime of the object it listens to, then you don't need to worry about it. For that reason, it's rarely a problem with listeners on GUI components, and I question the danger of listeners on a JButton. However, when you start working with attaching component model adapters to application data, it DOES become a concern and deserves your full attention. > > All of Linux is in C, for example. > > How do you define 'All of Linux'. Is it every application written for > Linux, or just the kernel and gnu tools? Linux is a kernel, and it is written in C. The GNU tools are not a part of Linux, but they are still written *mostly* in C, with some extra languages here and there. Of course, applications are written in many languages for Linux-based operating systems (to use very precise terminology). The general point, though, that most open-source is in C is still true. There's a fairly large open-source Java community, but it doesn't come close to the amount of C code out there. C++ is almost non-existent in open-source, in my experience, probably because once you're that close to C, people start asking why you don't use C. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation == 3 of 4 == Date: Fri, Dec 10 2004 4:26 pm From: Ian T Chris Smith wrote: >>>All of Linux is in C, for example. >> >>How do you define 'All of Linux'. Is it every application written for >>Linux, or just the kernel and gnu tools? > > > Linux is a kernel, and it is written in C. And assembler. > The GNU tools are not a part > of Linux, but they are still written *mostly* in C, with some extra > languages here and there. > C++ is almost non-existent in > open-source, in my experience, probably because once you're that close > to C, people start asking why you don't use C. Some projects (such as wxWindows) started their life as C, and evolved into C++. And then there are the wrappers for C libraries like gtk--. A quick look on sourceforge shows 14269 "projects" that use C++. Filtering those further to those at Development Status: 5 - Production/Stable leaves 2440 projects. Removing those projects that also are done in C leaves 1801, production level projects in C++. Which is a reasonable distance from "almost non-existent". Anyway, not looking for an argument, just a worthwhile discussion. BTW, is your position at MindIQ mostly Java or C++ ? Ian == 4 of 4 == Date: Thurs, Dec 9 2004 10:37 pm From: Chris Smith Ian T <[EMAIL PROTECTED]> wrote: > Removing those projects that also are done in C leaves 1801, production > level projects in C++. Which is a reasonable distance from "almost > non-existent". Guess I just don't see them. > BTW, is your position at MindIQ mostly Java or C++ ? > If you're curious, we use Java almost exclusively here. If you count JavaScript as a programming language (which I do) then there's also some of that. There's a small bit of C (via gcc on linux) and even Visual Basic, but it hasn't been used for ages. No C++ at all, to my knowledge. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: execution speed java vs. C http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/e8713e999b13b7d1 ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 11:47 pm From: "Tom Dyess" Here are some timed specs with source code and results for Java vs. C/C++ http://www.scottsarra.org/timer/timerMain.html which links to this at the end (haven't read second one) http://www.javaworld.com/javaworld/jw-02-1998/jw-02-jperf.html <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I write programs at work to do numerical calculations. Those programs > are usually written in C. I recently started looking into Java and > found the language and its features very attractive. I figured that I > should give it a try and see whether it is suitable for numerical work. > So I went ahead and wrote a very simple matrix multiplication program > in C and Java and benchmarked them. To my disappointment, C turned out > to be about 1.5 to 2 times faster than Java. > > Below more detail on what I actually did. I calculated the matrix > product of two random 800x800 matrices for int and double matrices. The > tests were run on a powerBook G4 1.33GHz. The C compiler was gcc-3.3 > and the Java version I used 1.4.2_05. The C code was compiled with > optimization level 3 (-O3). I couldn't find anything equivalent for > javac, so I compiled the code presumably without optimizations or with > some default level of optimization. The runtimes I found were > > int matrices > C (-O3): 15s > C (without -O): 33s > Java: 32s > > double matrices > C (-O3): 28s > C (without -O): 47s > Java: 45s > > Since the unoptimized C code (without specifying any -O level) runs > about as fast as the Java code I assume that I am looking at badly > optimized Java code. > > Can I force the java compiler or the runtime engine to optimize my code > further? > > Thanks, nick > > > > > > > The C program was > > #include <stdio.h> > #include <stdlib.h> > > #define N 800 > #define M 800 > > int a [N][M]; > int b [N][M]; > int c [N][M]; > > int main () > { > int i, j, k; > > printf ("creating matrices a and b\n"); > > /* Initialize the two matrices. */ > for (i = 0; i < N; ++i) { > for (j = 0; j < M; ++j) { > > a[i][j] = (int) ((rand () / (double) RAND_MAX - 0.5) * 10); > b[i][j] = (int) ((rand () / (double) RAND_MAX - 0.5) * 10); > } > } > > /* Multiply the matrices. */ > > printf ("multiplying them\n"); > > for (i = 0; i < N; ++i) { > for (j = 0; j < M; ++j) { > > c[i][j] = 0; > } > } > > for (i = 0; i < N; ++i) { > for (j = 0; j < M; ++j) { > for (k = 0; k < M; ++k) { > > c[i][j] += a[i][k] * b[k][j]; > } > } > } > } > > > The Java code was: > > public class MatrixTestDirty > { > public static void main (String args []) > { > int N = 800; > int M = 800; > > int a [][] = new int [N][M]; > int b [][] = new int [N][M]; > int c [][] = new int [N][M]; > > System.out.println ("creating matrices a and b"); > > /* Initialize the two matrices. */ > for (int i = 0; i < N; ++i) { > for (int j = 0; j < M; ++j) { > > a[i][j] = (int) ((Math.random () - 0.5) * 10); > b[i][j] = (int) ((Math.random () - 0.5) * 10); > } > } > > /* Multiply the matrices. */ > > System.out.println ("multiplying them"); > > for (int i = 0; i < N; ++i) { > for (int j = 0; j < M; ++j) { > > c[i][j] = 0; > } > } > > for (int i = 0; i < N; ++i) { > for (int j = 0; j < M; ++j) { > for (int k = 0; k < M; ++k) { > > c[i][j] += a[i][k] * b[k][j]; > } > } > } > } > } > ============================================================================== TOPIC: Java double precision http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/ffd916b2ccb1a75b ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 10:31 pm From: Chris Smith <[EMAIL PROTECTED]> wrote: > I know the following behaviour is an old problem, > but still I don't understand why such a simple piece of code: It's because you're thinking in decimal, but the computer thinks in binary. 0.1 is a repeating decimal number in binary. To understand this case, we could take an analogous algorithm in decimal; say, adding 1/3 instead of 1/10. In this example, we'll give the numbers ten significant digits of precision, so: 0.3333333333 + 0.3333333333 ------------ = 0.6666666666 + 0.3333333333 ------------ = 0.9999999999 So the same thing happens with repeating decimal numbers in base 10 as well. The cumulative error from adding 0.3333333333 instead of exactly 1/3 adds up. It's only counterintuitive because you're not expecting 0.1 to be a repeating decimal, and that's because you're not thinking in base 2 like the computer is. > Why, as a developer, I have to use a trick like this to solve the > problem: > > java.text.DecimalFormat df = new > java.text.DecimalFormat("###.########"); > double val = 0; > for(int i=0;i<10;i++) { > val+=0.1; > val = df.parse(df.format(val)).doubleValue(); > System.out.println(val); > } No, you can write: DecimalFormat df = new DecimalFormat("###.########"); double val = 0; for (int i = 0; i < 10; i++) { val += 0.1; System.out.println(df.format(val)); } As Patricia said, you're assuming that the "correct" answer is achieved by truncating the result in decimal that then parsing it back again. Only in the very limited case of nice round numbers is that true. This would be a very poor idea if you were working with any kind of measured or calculated quantity. You shouldn't be assuming enough precision that rounding error will matter anyway, so there's no need to make that round trip. -- www.designacourse.com The Easiest Way To Train Anyone... Anywhere. Chris Smith - Lead Software Developer/Technical Trainer MindIQ Corporation ============================================================================== TOPIC: Problem in Paint method http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/57896100121a1d97 ============================================================================== == 1 of 2 == Date: Thurs, Dec 9 2004 9:50 pm From: [EMAIL PROTECTED] Hi Everyone, I am creating light weight button. I have given almost all support. But in application when user overriding paint method my component is not visible. When calling setVisible in application my paint method is not getting called. Please let me know how to solve this problem. Regards Udhaya == 2 of 2 == Date: Fri, Dec 10 2004 8:25 am From: "Andrei Kouznetsov" > I am creating light weight button. > > I have given almost all support. > > But in application when user overriding paint method > > my component is not visible. > > When calling setVisible in application my paint method is > > not getting called. > Please let me know how to solve this problem. please don't multipost. -- Andrei Kouznetsov http://uio.dev.java.net Unified I/O for Java http://reader.imagero.com Java image reader http://jgui.imagero.com Java GUI components and utilities ============================================================================== TOPIC: Unique key and value http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/3f78fd73e6d5dce7 ============================================================================== == 1 of 2 == Date: Fri, Dec 10 2004 5:53 am From: "Bruce Lee" Is it possible to have a hashtable that has both unique keys and unique values (ie like a 2-columned database with both rows unique)? == 2 of 2 == Date: Fri, Dec 10 2004 8:30 am From: "Andrei Kouznetsov" > Is it possible to have a hashtable that has both unique keys and unique > values (ie like a 2-columned database with both rows unique)? something like HashSet? -- Andrei Kouznetsov http://uio.dev.java.net Unified I/O for Java http://reader.imagero.com Java image reader http://jgui.imagero.com Java GUI components and utilities ============================================================================== TOPIC: Interesting design question involving ZIPs and servers http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/d93856e0b568e2e4 ============================================================================== == 1 of 1 == Date: Fri, Dec 10 2004 6:00 pm From: Ian T [EMAIL PROTECTED] wrote: > > OK... So, the problem is, I want to be able to do FREE-FORM TEXT > searches on all of my completed reports. How can I search a zipped > buffer for a specific text string without having to uncompress the > buffer (ruining my memory savings). I could store text keywords with my > meta data object, but thats not really free-form... and that's what the > users are really hopeing for. > Thanks, Build an index and compress that too. Parse each XML document for words, and build some kind of multi-entry hash table, hmmm ... does Java have a multimap? Each index entry would consist of the word, followed by the documentID. If you will have less than 4 billion documents, then the documentID can be a 32bit unsigned int (4 bytes). That means that for words of greater than 4 letters long, you achieve a first order level of compression on the index, equivilent to (average_word_length - 4) per entry. Not to mention that you can discard common words like "the, it , a , an, but, with" from the index. Once you have built your index, compress it with ZipOutputStream. When the user wants to search, load the index and build your hash map, do the search on the map, then retrieve the XML documents via their documentID. Ian ============================================================================== TOPIC: Servlets sessions http://groups-beta.google.com/group/comp.lang.java.programmer/browse_thread/thread/30ab0398a5b15244 ============================================================================== == 1 of 1 == Date: Thurs, Dec 9 2004 11:06 pm From: [EMAIL PROTECTED] (Xarky) What a stupid mistake I did... :S Thanks for your help ============================================================================== You received this message because you are subscribed to the Google Groups "comp.lang.java.programmer" group. To post to this group, send email to [EMAIL PROTECTED] or visit http://groups-beta.google.com/group/comp.lang.java.programmer To unsubscribe from this group, send email to [EMAIL PROTECTED] To change the way you get mail from this group, visit: http://groups-beta.google.com/group/comp.lang.java.programmer/subscribe To report abuse, send email explaining the problem to [EMAIL PROTECTED] ============================================================================== Google Groups: http://groups-beta.google.com
