Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
geeves
Sep 16, 2004

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". :psyduck:

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.

Adbot
ADBOT LOVES YOU

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
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.

HFX
Nov 29, 2004

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". :psyduck:

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

geeves
Sep 16, 2004

HFX posted:

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.


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).

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.

Chairman Steve
Mar 9, 2007
Whiter than sour cream

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.

epswing
Nov 4, 2003

Soiled Meat

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.

crazyfish
Sep 19, 2002

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.

Contra Duck
Nov 4, 2004

#1 DAD

HFX posted:

If you have discriptive names, 80 characters is easy to blow past

I've seen class names that violate that limit :(

FateFree
Nov 14, 2003

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:
@Override
	public V getOrPut(K key, ICreateValue<V> createValue) {
		Object element = concurrentMap.get(key);		
		
		// if the element was not found in cache create it
		if(element == null)
		{
			V object = createValue.create();
			
			// store in cache
			concurrentMap.put(key, object);
			
			return object;
		}
		
		return element;	
	}
As you can see there is a race condition here, and while it previously hadn't been a problem I can see how it may cause the value in cache to be invalid over time. Synchronizing this method of course defeats the purpose of using a concurrent hash map to begin with.

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:
public ValueWrapper {
ICreateValue createValue;
Object object;

  public synchronized Object getValue() {
     if(object == null)
        object = createValue.create();

     return object;
  }

}
Wouldn't this essentially ensure that only one expensive object is created, while also leaving the synchronization around the cache untouched and speedy? Essentially the only synchronization blocking should be around threads looking for the same element in cache, and it would probably only be slow for the first time before the object is created.

I'd really appreciate thoughts about this, especially if I am missing something.

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
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:
NodeList rows = doc.getElementsByTagName("tr");
for (int i=0;i<rows.getLength();i++) {
    org.w3c.dom.Element row = (org.w3c.dom.Element)rows.item(i);
    NodeList cells = row.getElementsByTagName("td");
    //do something with cells.items(0)
}

epswing
Nov 4, 2003

Soiled Meat

fletcher posted:

I'm trying to use the org.w3c.dom stuff

Oh god save yourself http://www.jdom.org/

w3c is terrible :(

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb

epswing posted:

Oh god save yourself http://www.jdom.org/

w3c is terrible :(

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.

epswing
Nov 4, 2003

Soiled Meat
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));
...prints...
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

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

UberJumper
May 20, 2007
woop
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:
import java.net.InetAddress;
<stuff>
InetAddress foo = new InetAddress();
Doing this seems so much more verbose:
code:
java.net.InetAddress foo = new java.net.InetAddress();
The second one seems more verbose. Since i can easily pick out what the current context is talking about. This is really helpful since, it uses a few third party libraries, i have this:

code:
import foo.bar.gdb.Dataset;
import zoo.cat.Raster.Dataset;
Thankfully these aren't in the same class or anything, but its confusing as hell, because half of the time i don't know if its a geodatabase Dataset or if its a raster Dataset. Etc. Is it bad :downs:?

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:
public class DataDescriptor
{
   public byte[] getHeaderVersion();
   public byte[] getHeaderName();
   <snip tons of this poo poo>
}
What i really want is something similar to C#'s struct system for marshalling. Where you can define the order of values, size, packing etc. Then just convert it into a byte array. E.g. this:>

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:
public class TSBox
{
    private Object data_ = null;
    private boolean empty_ = true;
    
    public synchronized void put(Object obj)
    {
        while(!empty_)
        {
            wait();
        }
        data_ = obj;
        empty_ = false;
        notifyAll();
    }
    
    public synchronized Object get()
    {
        while(empty_)
        {
            wait();
        }
        Object obj = contents;
        notifyAll();
        return obj;
    }
}
Personally i think this system is dumb, lets say you have 100 threads who call get(), and only two threads are currently calling put() (theres a lack of data or something). So when something puts() it will wake all the threads, and they will all race for the lock. Also that wait() should always be called within a while loop (the chapter on threading ends here :suicide:).

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

Chairman Steve
Mar 9, 2007
Whiter than sour cream

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

RitualConfuser
Apr 22, 2008

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

Shavnir
Apr 5, 2005

A MAN'S DREAM CAN NEVER DIE

Chairman Steve posted:

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


Are there really any other major "must have" books for bookshelves of Java programmers or is Effective Java it?

Kilson
Jan 16, 2003

I EAT LITTLE CHILDREN FOR BREAKFAST !!11!!1!!!!111!

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:

:words:

Personally i think this system is dumb, lets say you have 100 threads who call get(), and only two threads are currently calling put() (theres a lack of data or something). So when something puts() it will wake all the threads, and they will all race for the lock.

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)

Chairman Steve
Mar 9, 2007
Whiter than sour cream

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

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer
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:
 private void ezmodeButtonActionPerformed(java.awt.event.ActionEvent evt) {

        status.setText("Working...); // This is the line in question

        try
        {
            String outputString = "";
            int strCount = 0;

            Statement stmt;
            ResultSet rs;
            Connection con = DriverManager.getConnection(url, username, password);
            stmt = con.createStatement();

            rs = stmt.executeQuery("SELECT * " +
                "from source_error WHERE create_dt > '" + startDate.getText() + "' AND create_dt < '" +
                 endDate.getText() + "' AND error_text LIKE '%" + ezmodeSearch.getText() + "%'");
            while(rs.next())
            {
                String errorText = rs.getString("error_text");
                String errorDate = rs.getString("create_dt");
                outputString = outputString + "error_text:  " + errorText + "  create_dt:  " + errorDate + "\n";
                strCount++;
            }
            resultCount.setText(strCount + "");
            output.setText(outputString);
        }
        catch(Exception e)
        {
             System.out.println(e);
        }
        status.setText("Query Complete");  // This actually works
        System.out.println("Query Complete \n");
}
    
The very first line of the method (status.setText("working..."); ) gets skipped. In fact, if I put a stop point there, it doesn't even stop at that point. I've tried to force it to write something into the box using some of the most rear end backwards techniques known to man but I cannot under any circumstance get the thing to actually write "Working" into the stupid jLabel.

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

epswing
Nov 4, 2003

Soiled Meat
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

Canine Blues Arooo
Jan 7, 2008

when you think about it...i'm the first girl you ever spent the night with

Grimey Drawer

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.

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

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!

Fly
Nov 3, 2002

moral compass

Chairman Steve posted:

If you're seriously interested in learning Java, then pick up the Java Bible:
I recommend also downloading a copy of FindBugs to run against your code base. It can find things that can be wrong in your code and also tell why they are wrong.

http://findbugs.sourceforge.net/

magnafides
Feb 7, 2004
I love molesting 8 year old girls, their tiny little hands make my cock look huge

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:
UserService userService = new UserServiceImpl();
System.out.println(AbstractServiceImpl.class.isAssignableFrom(userService.getClass()));
gives the desired result (true).

Crazy RRRussian
Mar 5, 2010

by Fistgrrl
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

chippy
Aug 16, 2006

OK I DON'T GET IT
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

HFX
Nov 29, 2004

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.

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.

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?

Mr VacBob
Aug 27, 2003
Was yea ra chs hymmnos mea

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.

chippy
Aug 16, 2006

OK I DON'T GET IT

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.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

Mr VacBob posted:

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.

Well, it's just a switch. Something like -XX:DoEscapeAnalysis.

Also, Apple does modify the Sun JVM before they release it.

UberJumper
May 20, 2007
woop
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.

chippy
Aug 16, 2006

OK I DON'T GET IT

UberJumper posted:

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.

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.

newreply.php
Dec 24, 2009

Pillbug
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.

zootm
Aug 8, 2006

We used to be better friends.

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.
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).

Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
Someone on my team was fooling around with maven for that, but it turns out that that's something best suited for ant.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.

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.

newreply.php
Dec 24, 2009

Pillbug

TRex EaterofCars posted:

You wanna put that stuff in a properties file or something.
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.

zootm
Aug 8, 2006

We used to be better friends.

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.
Can you just get Maven to move the "correct" properties file for the deployment it's performing as an artifact out with the deployment? It doesn't seem as though this is something that should be hard, although Maven does excel in making almost everything difficult.

Adbot
ADBOT LOVES YOU

YouAreCorrect
Oct 2, 2008
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 :10bux:, 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.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply