|
Sereri posted:To be fair, those are from the mid to late 90s and haven't been updated ever since. There's stuff in it like "Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools". This is completely subjective, but I've found the 80 character limit to be a decent rule of thumb for readability. Usually up to about 120 characters is good for me; anything more than that, usually have to scroll to the right and it becomes easy to overlook something when debugging.
|
# ? Jul 6, 2010 15:55 |
|
|
# ? Apr 23, 2024 09:04 |
|
I go with widescreen line spacing: Put as much stuff on one line as will fit on my widescreen laptop, then make a new line.
|
# ? Jul 6, 2010 18:06 |
|
Aleksei Vasiliev posted:I go with widescreen line spacing: Put as much stuff on one line as will fit on my widescreen laptop, then make a new line. I like this one too. Can make it hard to sometimes deal with passing args without storing to a temp variables first. Java coding conventions are mostly OTBS. I would say violate the hell out 80 character limit though. If you have discriptive names, 80 characters is easy to blow past, and you certainly don't want to go back to the old days of int a,b,c. As for code cleanup? Is it an embarrassment thing? ' Also, how did this thread get removed from my bookmarks how do I miss thee. Sereri posted:To be fair, those are from the mid to late 90s and haven't been updated ever since. There's stuff in it like "Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools". Sounds crazy, but I've had to debug and run code where the only way to run the code was through a terminal server (80 character lines by 13 lines bitches). HFX fucked around with this message at 22:19 on Jul 6, 2010 |
# ? Jul 6, 2010 22:15 |
|
HFX posted:I like this one too. Can make it hard to sometimes deal with passing args without storing to a temp variables first. I have a widescreen laptop / Apple monitor as well - it's great and that if I wanted to, I could get to 220 characters in one line at my resolution / font size. I just prefer to read straight down instead of having to read way across the screen. Like I said, just more a matter of personal preference (thought I have Checkstyle set to 150 characters - more so to accommodate co-workers' styles.
|
# ? Jul 7, 2010 00:28 |
|
UberJumper posted:Does such a thing exist? Also any suggestions to turn this from a monster into something not as ugly. An IDE should help "suggest" good coding principles. Eclipse (and I don't imagine this is restricted to just Eclipse) has a shortcut key combination of Ctrl + Shift + F to format your code nicely.
|
# ? Jul 7, 2010 02:47 |
|
Chairman Steve posted:Eclipse (and I don't imagine this is restricted to just Eclipse) has a shortcut key combination of Ctrl + Shift + F to format your code nicely. Every IDE should have this. I really, really love this feature. It's amazingly customizable too.
|
# ? Jul 7, 2010 03:34 |
|
Chairman Steve posted:An IDE should help "suggest" good coding principles. Eclipse (and I don't imagine this is restricted to just Eclipse) has a shortcut key combination of Ctrl + Shift + F to format your code nicely. Not only that, you can actually define HOW it formats your code for you. In fact, for our internal product we have Eclipse format the code every time we save (to a coding standard we defined) so no one strays from the formatting standard. It's pretty awesome not having to worry about someone nitpicking about formatting during code reviews.
|
# ? Jul 7, 2010 05:02 |
|
HFX posted:If you have discriptive names, 80 characters is easy to blow past I've seen class names that violate that limit
|
# ? Jul 7, 2010 05:13 |
|
Sorry to bring this back but I have a concurrency question about using ConcurrentHashMap. I've voiced my complaints in the past about the putIfAbsent method not taking a callback interface so that an expensive object could be put into cache only if it is absent from the cache. While waiting for such a thing to exist I defined my own cache interface with a method called getOrPut, which does the same thing through the use of a callback:code:
So I began to think of an alternative solution. What if I were to call concurrentHashMap.putIfAbsent(Key, ValueWrapper), where ValueWrapper is an object that contains the object to be cached, and an ICreateValue interface which creates the object. So for instance the flow would go like this: Client calls cache.getOrPut with a key and an ICreateValue callback to create the expensive object (most likely from db). ConcurrentMap stores the key and ValueWrapper with putIfAbsent. After ValueWrapper is retrieved from cache, call getValue() and return that to the client. ValueWrapper would look like this: code:
I'd really appreciate thoughts about this, especially if I am missing something.
|
# ? Jul 7, 2010 13:37 |
I'm trying to use the org.w3c.dom stuff for some basic DOM manipulation, but I feel like I'm doing it wrong. Is it necessary to have to cast from Node to Element so frequently? Like if I want to do something to the first <td> in every <tr>:code:
|
|
# ? Jul 7, 2010 22:31 |
|
fletcher posted:I'm trying to use the org.w3c.dom stuff Oh god save yourself http://www.jdom.org/ w3c is terrible
|
# ? Jul 7, 2010 22:41 |
epswing posted:Oh god save yourself http://www.jdom.org/ I started to use that (from one of your old posts where you answered a question for me actually) but I noticed we already used the w3c stuff elsewhere in the app, so I was going to attempt to use that instead. I'll give the jdom stuff another go.
|
|
# ? Jul 7, 2010 22:53 |
|
Since I like jdom so much...pre:String html = "<table>" + "<tr>" + "<td>one</td><td>two</td><td>three</td>" + "</tr>" + "<tr>" + "<td>four</td><td>five</td><td>six</td>" + "</tr>" + "</table>"; String xpath = "//td"; Document document = new SAXBuilder().build(new ByteArrayInputStream(html.getBytes())); List<Element> elements = XPath.newInstance(xpath).selectNodes(document); for (Element element : elements) { element.setText(element.getText().toUpperCase()); } XMLOutputter out = new XMLOutputter(Format.getPrettyFormat()); System.out.println(out.outputString(document)); pre:<?xml version="1.0" encoding="UTF-8"?> <table> <tr> <td>ONE</td> <td>TWO</td> <td>THREE</td> </tr> <tr> <td>FOUR</td> <td>FIVE</td> <td>SIX</td> </tr> </table> epswing fucked around with this message at 23:08 on Jul 7, 2010 |
# ? Jul 7, 2010 22:57 |
|
FateFree posted:Sorry to bring this back but I have a concurrency question about using ConcurrentHashMap. I've voiced my complaints in the past about the putIfAbsent method not taking a callback interface so that an expensive object could be put into cache only if it is absent from the cache. While waiting for such a thing to exist I defined my own cache interface with a method called getOrPut, which does the same thing through the use of a callback: You should probably do the simplest thing that works first. Then profile it. If performance REALLY is an honest issue, start by looking at your algorithm and assumptions before trying to roll your own concurrency utilities. You will almost assuredly get some subtle idiom wrong.
|
# ? Jul 8, 2010 02:50 |
|
Yay, so turns out the project that i was given, of me cleaning up, has now turned into me rewriting the system, so it can actually work properly on something other than java 1.2. Compiling it in anything above gives alot of deprecated warnings, and actually does not work quite right. The system runs constantly and (i didn't know about this) that from time to time the entire process becomes deadlocked somewhere. So someone overheard these issues, and decided "well lets have UberJumper rewrite it, fix the issues, and make the code maintainable. Even better we can use this for his appraisal." Technically i am a student, but i am a part time casual (i've been fulltime every time i am not in school for the last while). I want this job, i am graduating soon. So i kinda want to do this perfect (even though my java experience is slim to none, nor did i ever put java experience on my resume.) So i've spent the majority of the day tearing the system apart, figuring out how everything works (the system wasn't done by a single student, oh no it was the byproduct of several students on different terms, one leaves a new one takes over where the last one left off(this system also done by a different group thank god).) So i have some java questions that i can't really seem to find the answer to (some of these will make you realize how futile the situation is): 1. Is it bad practice to fully write out the namespace (or package) of uncommon types? Instead of doing: code:
code:
code:
2. Is there anyway i can get a POD datastructure? I am kind of looking for the equivalent of a struct. Right now alot of time is spent calling hundreds of get methods of objects, and slowly building a byte array. Which is then sent out as packets. There are dozens of objects that basically read in certain data and populate member variables with the data. code:
http://geekswithblogs.net/taylorrich/archive/2006/08/21/88665.aspx 3. The system does some work with threads, i know nothing about java threads, anyways i looked at the credited example that was used as the basis for distribution of data between threads: code:
Does anyone have any good recommendations for links about threading for java? I found some but alot of them are about java.util. concurrent, which seems alot more intelligent for doing this stuff. Since it gives better control. Anyways any ideas lemme know :$ If anyone can give me a good idea
|
# ? Jul 9, 2010 01:14 |
|
UberJumper posted:1. Is it bad practice to fully write out the namespace (or package) of uncommon types? Not necessarily. However, IDEs like Eclipse have visual cues (and provide Javadoc when you hover over the reference) to let you know which one it is. The problem with verbosity in your code is that it can become cluttered pretty easily (especially with longer package names, such as org.springframework.instrument.classloading.weblogic. Unless I have references to two different classes by the same name, I don't use their canonical names. quote:2. Is there anyway i can get a POD datastructure? I'm not sure exactly how you're transforming an object to packets, but if you're dealing with streams, I might recommend a combination of ByteArrayInputStream and IOUtils, combined with your own implementation of OutputStream to convert the byte array into an object. If you're disgruntled with getters and setters, be aware that accessing objects' fields directly is generally a bad idea. You can't enforce any kind of business rules on your objects, and, if there's any kind of logic you want to perform whenever someone accesses or sets your fields, you're SOL. Additionally, if you're not aware of the exact length of the byte array that you're going to build, I'd recommend creating a Collection<Byte>, adding each of the sets of bytes as you go, and use the [url=http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/java/util/Collection.html#toArray(T[])]toArray(T[])[/url] method to convert it to a byte array. quote:Does anyone have any good recommendations for links about threading for java? I don't (I know that's not helpful, but I didn't want you to think I had missed this question). If you're seriously interested in learning Java, then pick up the Java Bible: http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=sr_1_1?ie=UTF8&s=books&qid=1278636056&sr=8-1
|
# ? Jul 9, 2010 01:41 |
|
UberJumper posted:Does anyone have any good recommendations for links about threading for java? I found some but alot of them are about java.util. concurrent, which seems alot more intelligent for doing this stuff. Since it gives better control. Java Concurrency in Practice is basically the Java concurrency bible. \/\/\/\/\/\/ This one. RitualConfuser fucked around with this message at 05:34 on Jul 9, 2010 |
# ? Jul 9, 2010 05:22 |
|
Chairman Steve posted:If you're seriously interested in learning Java, then pick up the Java Bible: Are there really any other major "must have" books for bookshelves of Java programmers or is Effective Java it?
|
# ? Jul 9, 2010 05:31 |
|
UberJumper posted:3. The system does some work with threads, i know nothing about java threads, anyways i looked at the credited example that was used as the basis for distribution of data between threads: It's kind of bad, but I don't think (though I'm definitely no expert here) that this code will cause any problems. All the threads will wake up, but the synchronized nature of the method will prevent multiple threads from actually obtaining the lock. You might want to look into the SynchronousQueue class though (or any of the other java.util.concurrent structures), since it seems to do about the same thing the code you pasted is doing. quote:Does anyone have any good recommendations for links about threading for java? I found some but alot of them are about java.util. concurrent, which seems alot more intelligent for doing this stuff. Since it gives better control. You may have already read this, but it's decent as an introduction: http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/essential/concurrency/index.html Searching for 'java concurrency' provides several other tutorials.(http://tutorials.jenkov.com/java-concurrency/index.html has some pretty good stuff near the end, at least)
|
# ? Jul 9, 2010 07:51 |
|
Shavnir posted:Are there really any other major "must have" books for bookshelves of Java programmers or is Effective Java it? I've never read Ritual's book, so I can't endorse it (nor will I discourage reading it, of course ), but, beyond these books, I've heard good things about POJOs in Action. Really, there's only so much you can read about Java syntax - beyond that, reading is more applicable to specific frameworks or platforms, such as J2EE, Hibernate, Spring, JUnit, Eclipse RCP, OSGi bundling... Of course, all reading really does is prepare you for your work - it's the actual experience that will make you a better programmer. Reading just lays down the foundations. [ Edit: I should note that Effective Java doesn't introduce revolutionary concepts that will rock the foundation of your perception of object-oriented programming. What it contains are a bunch of concepts where you'll read it and go, "Huh. That makes sense." It's all stuff that you would have figured out after years of trial-and-error and general work experience. It just saves you the time of having to learn those lessons yourself and supporting the code you wrote when you hadn't yet learned those lessons. ] Chairman Steve fucked around with this message at 02:32 on Jul 10, 2010 |
# ? Jul 10, 2010 02:28 |
|
So I have quite an interesting problem which is quickly driving me to suicide by it's simplicity. I have a simple program which has one function: query an SQL database and return simple results. Due to a bit of lag in-between the time when you press the "Query" button and when the results are actually returned, I wanted to implement an indication that program is actually doing something. The simple solution was to simply add "Working" text to the frame, replacing it with "Query Complete" when it's finished. This is the method that should be doing everything:code:
Now the killer here is that the "Query Complete" line (Second from the bottom) actually works; I have no problems with it. What the hell is going on and how can I fix it? Canine Blues Arooo fucked around with this message at 19:52 on Jul 12, 2010 |
# ? Jul 12, 2010 18:58 |
|
I don't have the exact answer to your problem, but it sounds like the UI component is being drawn/refreshed after the sql query, so it "looks" like both status.setText calls happen in quick succession, so fast that you don't see the first one. If you issue some refresh() or redraw() call after the first one (I haven't used swing in years) that might do it. Really though, if it's something that takes more than 1.0 seconds to complete, you should start thinking about offloading the work onto one of those thingers...I forget the name, something like 'SwingWorkers'. This keeps the UI responsive, while running the lengthy task in the background. Edit: found it http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/concurrency/worker.html epswing fucked around with this message at 19:29 on Jul 12, 2010 |
# ? Jul 12, 2010 19:26 |
|
epswing posted:I don't have the exact answer to your problem, but it sounds like the UI component is being drawn/refreshed after the sql query, so it "looks" like both status.setText calls happen in quick succession, so fast that you don't see the first one. If you issue some refresh() or redraw() call after the first one (I haven't used swing in years) that might do it. The length of time it takes to complete the query ranges heavily based on the number of dates you are searching. The Database has 100,000s of entries, so if you search a span of a week, it takes about 2-3~ seconds. If you search the span of say, 6 months, it may take upwards of 8-10 seconds. I'll check out the Workers and see what that does. What baffles me though is before any of the processing is actually done, it's supposed to change the text of a label and it fails to do that. All my tests indicate that the Netbeans doesn't even think that the line exists!
|
# ? Jul 12, 2010 19:55 |
|
Chairman Steve posted:If you're seriously interested in learning Java, then pick up the Java Bible: http://findbugs.sourceforge.net/
|
# ? Jul 12, 2010 22:42 |
|
FateFree posted:Sorry for the convoluted question but it gets down to what condition can I use so that any Field that extends AbstractServiceImpl returns true? The method call that you posted works fine assuming you meant "getClass" instead of "getType": code:
|
# ? Jul 13, 2010 02:33 |
|
I have a quick JNA question. Is it possible to register a callback with a native function that will call a java function? That is, I want to use a library wherein some functions may take a function pointer, and then call that function sometime later. I would like to find a way that I can register a java function with the native library, and have the native code invoke java method. Is this possible with just JNA? EDIT: Whoops after some quick reading, it appears it is not that hard to do. Another question. is it possible to use JNA with C++ library? Specifically I want to call member methods on a pointer to instance of a class. Crazy RRRussian fucked around with this message at 17:00 on Jul 13, 2010 |
# ? Jul 13, 2010 16:30 |
|
I am writing a tool for work that configures a .ini file for a program via a GUI, to replace the current system we have of manually editing the .ini file. I've got the program working fine except for one thing: The .ini file resides in a sub-folder in Program Files and if the program tries to open the file from there it fails. I can see "Access Denied" in the console. How do I grant the app permission to write to Program Files? I'm running it on a user account with local admin rights, I thought that would be enough but it seems not. This is on XP. edit: Never mind, I have no idea what I did but it's working now. chippy fucked around with this message at 15:19 on Jul 14, 2010 |
# ? Jul 14, 2010 15:05 |
|
chippy posted:I am writing a tool for work that configures a .ini file for a program via a GUI, to replace the current system we have of manually editing the .ini file. The only reason you would not be able to access a file is if the only owner of the file/directory is administrator provided you had admin rights and the file specifically had no permissions for anyone else. Is there a reason that ini file has to be in Program Files and couldn't be in the shared account settings or the registry under the shared user settings?
|
# ? Jul 14, 2010 15:50 |
|
Parantumaton posted:Actually "not implemented", Apple just doesn't want to seem lazy. Not that it matters here. Escape analysis is currently disabled in Java 6, it's not something Apple would be implementing. You can build the OpenJDK BSD port yourself if you're really curious about it.
|
# ? Jul 15, 2010 08:30 |
|
HFX posted:Is there a reason that ini file has to be in Program Files and couldn't be in the shared account settings or the registry under the shared user settings? Yeah, I didn't write the program and don't have any influence over its development, and it's always existed entirely in its own folder in Program Files. I'm just writing a sort of control panel for it that configures some stuff in the .ini for it and launches it with certain parameters. I probably could raise a change request for it but if it even got approved it would be so far down the list of priorities that it would never get done.
|
# ? Jul 15, 2010 10:24 |
|
Mr VacBob posted:Escape analysis is currently disabled in Java 6, it's not something Apple would be implementing. Well, it's just a switch. Something like -XX:DoEscapeAnalysis. Also, Apple does modify the Sun JVM before they release it.
|
# ? Jul 15, 2010 12:10 |
|
Quick question, So i bascially have a windows formatted text file, now i want it to be in unix formatted (\n instead of cr). I know in Python and a few other languages when you open a file in ASCII mode, then it will do this auto conversion for you, however i cannot find anything like this in java, when i read the file and output it, it dioes not appear to come out in the right format.
|
# ? Jul 16, 2010 10:58 |
|
UberJumper posted:Quick question, Not sure what if this is exactly what you're after, but FileReader and FileWriter use the system default character encoding, where as if you use FileInputStream and InputStreamReader, and their output equivalents, you can specify the encoding.
|
# ? Jul 16, 2010 11:06 |
|
Could anyone tell me if there's a way to get variables from maven's pom.xml parsed in code? I have a server url that should be different for development, testing and production code. System.getProperty(propertyname) seems to be what those mailing lists from 1998 suggest but it keeps returning null for me, I guess it's not meant for custom attributes.
|
# ? Jul 19, 2010 19:33 |
|
newreply.php posted:Could anyone tell me if there's a way to get variables from maven's pom.xml parsed in code? I have a server url that should be different for development, testing and production code. System.getProperty(propertyname) seems to be what those mailing lists from 1998 suggest but it keeps returning null for me, I guess it's not meant for custom attributes.
|
# ? Jul 19, 2010 19:38 |
|
Someone on my team was fooling around with maven for that, but it turns out that that's something best suited for ant.
|
# ? Jul 19, 2010 20:06 |
|
zootm posted:I don't think that Maven's pom.xml actually gets turned into a build artifact, you might be better using whatever configuration mechanism you have at hand to do this form of switching, rather than trying to pass it through Maven, which isn't really a deployment tool (unless it's gained that role, which is possible). I've been working in an OSGi container (Apache Felix) that uses maven as a deploy source. But the artifacts are all listed in the pom, the pom itself doesn't participate in the output. You wanna put that stuff in a properties file or something.
|
# ? Jul 19, 2010 20:31 |
|
TRex EaterofCars posted:You wanna put that stuff in a properties file or something.
|
# ? Jul 19, 2010 22:34 |
|
newreply.php posted:Yeah that's how I would do it, were it not that the selection depends on the environment and afaik Maven is the only part that know where the app is deployed.
|
# ? Jul 20, 2010 09:34 |
|
|
# ? Apr 23, 2024 09:04 |
|
I have a question. My current employer wants me to get my Sun Certified Java Programmer certificate. This exam costs a poo poo load of , so I really want to pass it the first time. People in my office say it is very hard, some have failed 3-5 times now. This makes me terrified just at the thought of spending $1000 dollars on a loving certificate. Can someone point me to a good source to prepare? Thanks.
|
# ? Jul 20, 2010 22:04 |