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
trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
In Java everything character and time related should accept a localization parameter, if one is not provided it defaults to the local computer's settings, which means that if you haven't added those parameters, the defaults might lead to different behavior.

Adbot
ADBOT LOVES YOU

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

Hidden Under a Hat posted:

Could you give me an example of a "localization parameter"?

Locale.US
TimeZone.getTimeZone("GMT-8")

Now if you're doing things with relative times that have NOTHING AT ALL to do with wall time or durations of Days/Weeks/Months/Years, then by all means, System.currentTimeMillis() (or nanoTime()) is probably ok for your usage.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
So what do you do with the time? If you do not care about wall time or durations of time longer than hours, you shouldn't even bother with Calendar and Date.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Yeah not all days are 24 hours, leap seconds and DST changes will affect time.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
You make a good point. Time is such a complex and nuanced topic that, like I am in, I know enough to say I don't know poo poo, and I use weasel words a lot.

That said, specifically about S.cTM: if you check the JavaDoc:
http://docs.oracle.com/javase/6/docs/api/java/lang/System.html#currentTimeMillis()

JDK SE 6 posted:

Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.

See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).

Now currentTimeMillis() is perfectly ok for many (most?) tasks, but you really need to understand your problem domain to know how timekeeping should be accomplished, and be well educated about the options and how your app needs to respond.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
At the risk of sounding like a broken record, have you looked at grails?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
For something like that I'd probably use Quartz:
http://quartz-scheduler.org/

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

baquerd posted:

I've used Quartz but I don't see how it would make things more elegant? It seems like I would just be using a SimpleTrigger to execute a Job instead of a Timer to execute a TimerTask.

Mostly to externalize the configuration and have an de facto industry standard component for task scheduling. More software engineering than development elegance, I suppose.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Go here:
http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/index.html

and look up Lists:

http://docs.guava-libraries.googlecode.com/git-history/release/javadoc/com/google/common/collect/Lists.html

there's a partition method. Use that.

If you can't add another library to your code, then get it from git and put the guts of that method into yours.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Have you profiled the app to find out if that's really what's going on?

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

Hidden Under a Hat posted:

Ok it's definitely the chart object, class instances of the Chart object keep going up even though there should only ever be one Chart object that keeps getting reinitialized. So what are some ways to ensure an object is dereferenced and destroyed?

Sometimes (but not usually) a static analysis tool like FindBugs can uncover a situation where you're holding a reference that will prevent GC.

Other than that, you have to look at the entire object lifecycle and audit the references to it. Something must be putting it in a collection or some other container that never goes out of scope.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
super.fn() simply calls the method "fn" on its superclass with the current object's data, if the superclass calls an overridden method, it will find the most specific override that matches

E: I should probably be more clear.

The type of the object does not change even when superclass methods are called, so the override will still be "in play" even in super methods.


\/ yeah you did a way better job of explaining than I did

trex eaterofcadrs fucked around with this message at 19:58 on Jul 12, 2012

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
You could always try Google Protocol Buffers. It's a wire format but it should work fine.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
What's happening is that the TypeAdapter that GSON ends up using for your example is ReflectiveTypeAdapter, which is seeing the long value; field in the Example class, then tries to use a parser for Long which then craps out on that number.

I'm not sure how you register new TypeAdapters but there is a List <TypeAdapterFactory> factories object inside GSON (Gson.class:120) that it looks for TypeAdapterFactory classes that support your class. It iterates through that List though (Gson.class:352) and once it finds a potential match it plows on ahead, which indicates to me that it'll be hard for you to fix this without using maybe BigDecimal instead of long.

I did this based on the current SVN head so if you're using a different version obviously ymmv.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Another way to do it is to literally count up all your class file sizes, including jars. It's a lot of stupid work and you need to be thorough, and that also doesn't include rt.jar or any runtime generated classes (say from Spring proxies or Hibernate proxies).

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

MEAT TREAT posted:

Just wanted to add that WebServices also love to chew through the permgen space when you redeploy them a lot.

If this happens to you then you must have a ClassLoader leak, or a configuration where the jvm is not allowed to reclaim objects in permgen.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Adding on to Internet Janitor and MEAT TREAT's ideas:
* What autoboxing is
* A pretty comprehensive understanding of the Collections framework (difference between Set, List, Map and their implementations), Iterator, etc.
* Difference between long, int, double, float
* What the heap and stack are
* Difference between an Error and an Exception
* If you really wanna bake them, ask about bytecode (what's the difference between invokestatic and invokevirtual, for instance) or JVM internals

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

Doctor w-rw-rw- posted:

I think he wasn't talking about the value of the skill itself, but rather how much someone with his level of experience might be able to market his skills for.


Probably a question for another thread, but location makes a difference, and I have no clue how experienced a developer you are. Upwards of $60k for sure, possibly $70k or $80k+. And I'm lowballing for the Bay Area (but then, higher Bay Area rent will easily make the difference).

In Chicago there's a ton of high profile Java firms and talent is thin, you could get near 100k here if you didn't suck and hung around for 4-5 years.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Have you profiled the GC with jstat?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Honestly that sounds like a bug. When the CPU spikes, can you tell if it's due to GC overhead?

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
A little tangent; if permgen is filling up during hot deploys then the app has a ClassLoader leak. I wonder if that might have something to do with it. I'm totally taking a shot in the dark here but if you can track down the leak, your app will be better for it anyhow.

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

StabbinHobo posted:

thats the hopefully-productive yak shaving path we've started down

are there any good commandline/programatic ways to do it though? taking a several-gigs heap dump and downloading it to your laptop to futz around in the gui tools is gruelingly slow.

Nothing automatic as far as I know but

http://www.samaxes.com/2007/10/classloader-leaks-and-permgen-space/

is probably the most concise step by step I've found

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

Safe and Secure! posted:

While we're on the topic, any favorite Java mock libraries?

Mocking really pisses me off but when I have to, I use Mockito.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
Well Java 7 will fix that stupid issue:

code:
catch (IOException|SQLException ex) {
    logger.log(ex);
    throw ex;
}

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

rhag posted:

I personally believe that the contract should be something like this:
1. If the method returns a collection, then it should never return null. Return an empty collection if there are no things there.
2. If the method returns a single object, it returns null if there are no objects that satisfy the condition (find(id) for example).

The best solution is the one provided by Scala with the Optional support, but in Java an implementation of that would only lead to more verbose code for what otherwise should be a simple check.
The worst solution is throwing a runtime exception (like JPA for createQuery(...).getSingleResult()).

Of course, to any solution there are exception cases, and there could indeed be times where returning new Thing("i don't have any") may be valid and preferred, but i personally think this should not be the normal way of doing things.

This is what I do unless I have Option types.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
You could use reflection, or write a compiler.

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

I was going to say just hoist the Clojure collections, but this is probably the best answer.

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

baquerd posted:

Can someone point me in the direction of difficult problem sets dealing with low-level concurrency? I feel the need to brush up, having been spoiled with Spring and dealing with problems that don't care about approaching concurrency with a naive solution. As a related aside, I've had a copy of Java Concurrency in Practice for many years.

One of the best ones I've seen is the one Rich Hickey demonstrated about an ant colony.

Best links I can find are these:
http://juliangamble.com/blog/2011/12/28/clojure-gui-demo-of-ants/
https://gist.github.com/jjcomer/1494094

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
The first thing that came to mind for me was structure sharing. Maybe you can look at this library? It has a PersistentHashMap you can probably steal and repurpose.
https://github.com/krukow/clj-ds

My thoughts are, if the underlying CHM changes after the snapshot iterator is generated, the iterator's internal instance simply will not be aware of the modified entries, but all subsequent operations on the original CHM instance will be available for any other operations.


You will likely have to do some wizardry to regain the full semantics of CHM but it shouldn't be too hard.

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

Fly posted:

Why does anyone use maven by choice? (serious question) There must be something it's good at doing.

I use it because I also use OSGi and Maven makes deployment into the OSGi container vastly easier than just dumping dependencies in a hotfolder.

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

Fly posted:

edit: The dependency downloading is the one thing that gives me the most grief. What else does it do that might be useful?

It gives you a very widely adopted standard to version your own artifacts. You can run your own nexus and personally vet any artifacts it provides if you want. I used to use it for large-scale internal development projects (SOA systems mostly) and it was a godsend. Just always use Maven 3. Maven 2 was a piece of poo poo from hell. Also deploying FROM a nexus is usually pretty drat simple, which is again what I use it for. I can say "install artifact com.example/poo poo-maker/2.0.1" and it'll go do it.

It also has tons of plugins for doing lots of tedious poo poo. The only issue I have with them is that they are usually poorly documented (read the source) and the xml config for them can get wonky fast.

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

Jabor posted:

So how does it interact with your actual version control solution? Is it some separate entity that you have to keep in sync?

Well, for the most part they're orthogonal. One is the versioning and control of source (which includes the pom.xml maven config file) and the other is versioning and control of build artifacts. Once you tag a version in source control, you can use your continuous integration tool to automatically deploy the build artifacts to maven.

so my toolchain is like this

hg tag $version -> hudson sees new tag and generates build $build_no -> build $build_no passes tests, artifact $version.jar generated -> artifact $version.jar deployed to internal maven nexus

That said, Maven can also host source artifacts so you can have source up in the nexus with your jars and wars and whatever else.

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

Hard NOP Life posted:

In that case you can inspect your direct dependencies POMs to make sure they declared a single version of their dependencies. Again Artifactory and Nexus can help because you can overwrite their POM if it's wrong and they don't want to fix it.

Another thing I've seen is simply to declare the libraries transitive dependencies as direct dependencies which ensures a stable build no matter what. The downside is that now if you upgrade your dependency Maven won't tell you if any of it's transitive dependencies where updated.

A short workaround could be the follwing: an IDE like Netbeans would make it a snap since you could remove the transitive dependencies from your POM and Maven would get all the new ones if they changed and you can add them back using this handy context menu without having to edit your POM by hand each time.


This is all true and also there's nothing stopping you from rebundling jars. I do this all the time because people don't make OSGi compatible bundles a lot of the time.

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

supermikhail posted:

If you can keep a secret, I had this as part of an idea of artificial evolution while commuting. /secret.

I think it's deterministic, just not guaranteed in any given circumstance.

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

rhag posted:

When i had to inspect a lot of classes to make sure they behave (for other reasons than you), what I did was to write unit tests that would do the inspection for me. The tests would be run with each build, giving me very fast feedback on the status of the build.
The library i used was the ow2's asm library. They have apparently reached the 4.0 release but in maven they only have the 3.3.1 .
The maven dependency looks like this:
<dependency>
<groupId>asm</groupId>
<artifactId>asm-all</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>

Yeah I actually was playing around with exactly how to do this last night. I didn't see a mechanism to get just the byte code bytearray for a specific method.

I think the "easiest" way without trying to write some kind of huge java thing is to use javap to decompile each one of the stupid classes and see if there is a method with a byte position greater than (say) 62,000. Shouldn't be too hard to do with grep/awk.

Adbot
ADBOT LOVES YOU

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

HFX posted:

I have to process a large number of text files that were originally written by some kind of Cobol program.

Many languages support the concept of writing into a record structure for output. The text files look like they were written by just such a program. Now, here comes the hard part. I would like to reverse this so my program can consume the document without me having to write a parser with lots of special rules. Are their any java libraries that given a record structure and format of items in it, they could automagically suck out the items into some Java objects?

Is this a COBOL master file or just a text output from some kind of log or extract? It may be possible to read in as byte delimited record fields. Do you have a few samples?

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