|
TRex EaterofCars posted:No one smart uses struts any more. Ugh. Could you explain what's wrong with Struts? (Just curious)
|
# ? Jan 21, 2012 01:29 |
|
|
# ? May 10, 2024 14:17 |
|
pigdog posted:Could you explain what's wrong with Struts? (Just curious) For one, it uses Object-Graph Navigation Language (OGNL), which makes it easy to parse input to Java objects and get values from Java objects using strings like "session.user.name.firstName". OGNL can also parse and execute arbitrary Java code. Yep, nothing can go wrong with that.
|
# ? Jan 21, 2012 02:59 |
|
Doctor w-rw-rw- posted:Play framework is a really cool non-Servlet app framework. Klout and some other companies use it in production and its Scala support was good enough for Typesafe to anoint it officially as...something. I forgot. But its Java bindings are great, and I find it a lot of fun. Agreed, the Play framework is easily the best framework I have worked with. It is so good that it makes me sad when I have to go to work and use ASP.
|
# ? Jan 21, 2012 19:40 |
|
I am in posted:For one, it uses Object-Graph Navigation Language (OGNL), which makes it easy to parse input to Java objects and get values from Java objects using strings like "session.user.name.firstName". OGNL can also parse and execute arbitrary Java code. I think it is worth adding that there is no point picking up something like Struts right now if you are starting from scratch. The world of web development has largely moved on. Struts can be used to create a great website that is secure and full featured, but there is no point to using it. It isn't higher performing that other frameworks, it isn't more inherently secure, and most importantly, it is not as easy to create things with as one of the more modern frameworks.
|
# ? Jan 21, 2012 19:46 |
|
Spring MVC is good. Tapestry is very nice as well. The Play! framework...i personally wasn't too impressed with their 1.2.x versions, I'll wait to see what 2.0 will bring to the table. Grails is awesome for a lot of reasons, awful for others (slow, huge memory usage, etc.). 2.0 promised to fix a lot of things (including speed improvements), didn't have a chance yet to try it out.
|
# ? Jan 22, 2012 05:07 |
|
rhag posted:Spring MVC is good. Tapestry is nice, and so is Wicket for that matter (as far as a view technology). If you need speed, Spring MVC + JSTL is the best on the block as far as I'm concerned. Grails definitely requires you to learn how to use -XX:PermGenSize and -Xmx but I think for the increase in productivity it's worth it.
|
# ? Jan 22, 2012 07:07 |
|
Just saw this one:quote:Unsigned Integer Arithmetic API now in JDK 8 At long last indeed!
|
# ? Jan 22, 2012 11:07 |
|
quote:I've just pushed initial API support for unsigned integer arithmetic into JDK 8! The support is implemented via static methods
|
# ? Jan 22, 2012 15:42 |
|
Having one line methods that are return (int)x & 0xff; is great, especially since invoking Byte.toUnsignedInt is longer than just doing it directly.
|
# ? Jan 22, 2012 16:31 |
|
I'm using a Scanner to read in and parse a text file. I'm not sure if I'm just doing this wrong, or if I'm missing something, but here's the issue. I've created the Scanner object in my main(), with it taking input from a File object. I pass the Scanner into a method, where it reads through every line of a file. I then pass the Scanner to a second method, but by this point Scanner is at the end of the file, so there's no more lines to read. So, as I see it, either I need a new Scanner object for each method, OR I need some way to tell the Scanner to start over. Help?
|
# ? Jan 22, 2012 22:14 |
|
Creating a new Scanner will likely work. I would really recommend that you take a look at InputStreamReader or FileReader. Each of these will do what you need them to do, and you can call reset() to go back to the beginning of the file. Not as friendly as Scanner, but it is the more correct way of handling the problem.
|
# ? Jan 22, 2012 22:36 |
|
Scanner is really friendly and easy to use, but it's really slow performance-wise and not as versatile. Use FileReader or BufferedReader.
|
# ? Jan 22, 2012 23:49 |
|
Each file being parsed isn't very long (~55 lines), but it needs to process 52,000 documents, so efficiency is certainly a concern. BufferedReader looks like the best alternative so far, though I'll admit I've become fairly reliant on Scanner's .hasNext() method.
|
# ? Jan 23, 2012 00:23 |
|
How worried do I have to be about permgen space? I'm working on a large (700,000 lines of code probably?) application. I'm trying to make use of functional programming, so I'm using a number of Function classes to imitate true closures.
|
# ? Jan 23, 2012 02:30 |
|
The only time I've run into permgen space problems is when using a lot of Spring/CGLib stuff in a web container. Redeploy the application(s) several times, and the JVM starts puking, because it has some problems cleaning up after proxy classes or something.
|
# ? Jan 23, 2012 03:25 |
|
Pretty much the same as that, I've only seen it when redeploying big Spring apps.
|
# ? Jan 23, 2012 10:06 |
|
Going to chime in with I've only seen it when redeploying a project with a lot of Web Services in GlassFish. After many redeploys it will barf on that and require a restart. I think it's because the GC doesn't reclaim stuff in the permgenspace. edit: I've also seen it when compiling a project in Netbeans a bunch of times. LOL
|
# ? Jan 23, 2012 10:14 |
|
I am attempting to create a java/jsp web page which will read from an xml file and allow users to interact with the data. What I am thinking is pulling the data from the xml file and putting it into a java object, this object could then be passed through using a session. Temporary object could be pointed to origonal one if they wanted to add or remove elements. Well I am having some trouble getting started, I am a little confused as to which xml parser I should be using. I got brief overviews of SAX and DOM however I am still unsure. Or is there an easier way than this? I havnt done any work with java in awhile. I found some code online that I was able to alter to read in xml and parse into list then to an array. Is there an easy way to remove the tags from a string. So for a given string I have 'tag=value', how can I return everything after it? Can this be accomplished with regex? DholmbladRU fucked around with this message at 03:02 on Jan 25, 2012 |
# ? Jan 24, 2012 21:44 |
|
See something like this: http://totheriver.com/learn/xml/xmltutorial.html . DOM is easier to use but takes up more memory and CPU (gets important if the XMLs are in megabytes of size), SAX is a bit of a bitch to use but is faster and doesn't blow up if the XML files are huge, StAX is sort of middle ground but haven't used it much yet. Don't use a regexp to parse XML, especially other peoples' XML, it will bite you in the rear end. That's what XML parsers are there for. There's a bunch of boilerplate code, but once you have that DOM object you can do cool stuff with it like search it with XPath, modify the elements, transform it with XSLT, et cetera. edit: If the XML in question corresponds to a concrete XML schema, then see this: http://xmlbeans.apache.org/ pigdog fucked around with this message at 10:13 on Jan 25, 2012 |
# ? Jan 25, 2012 09:27 |
|
pigdog posted:See something like this: http://totheriver.com/learn/xml/xmltutorial.html . DOM is easier to use but takes up more memory and CPU (gets important if the XMLs are in megabytes of size), SAX is a bit of a bitch to use but is faster and doesn't blow up if the XML files are huge, StAX is sort of middle ground but haven't used it much yet. Don't use a regexp to parse XML, especially other peoples' XML, it will bite you in the rear end. That's what XML parsers are there for. There's a bunch of boilerplate code, but once you have that DOM object you can do cool stuff with it like search it with XPath, modify the elements, transform it with XSLT, et cetera. Thanks for the information. I was able to use dom for the moment to bring in an xml file and put it into java obj. What I was talking abuot regex for was to remove part of a string that I do not want. code:
DholmbladRU fucked around with this message at 14:05 on Jan 25, 2012 |
# ? Jan 25, 2012 13:45 |
|
DholmbladRU posted:Here I am reading in a xml tag and adding it to a java object field. However the tag name 'location=' comes along with it. How can I remove this from the incoming string without taking up alot of resources? So you have <abc location='xyz'> and want to remove the location='xyz' ? Why not simply remove the attribute from the object?
|
# ? Jan 25, 2012 14:11 |
|
DholmbladRU posted:Here I am reading in a xml tag and adding it to a java object field. However the tag name 'location=' comes along with it. How can I remove this from the incoming string without taking up alot of resources? This line is a suspect one: code:
So if the event was an isAttribute() event that was helpfully converted to a content event that could explain the "location=" part. Instead, you should put the StartElement that asStartElement() returns in a variable and read the attribute using getAttributeByName().
|
# ? Jan 25, 2012 15:32 |
|
I am in posted:This line is a suspect one: Didnt think about non character input, user input will be validated so hopfully that wont happen. And this is a small project that I am puttingn togetther This should work right? code:
|
# ? Jan 25, 2012 17:16 |
|
No, that doesn't even compile. Try this to see what's going on:code:
|
# ? Jan 25, 2012 20:30 |
|
code:
code:
I am still really confused by your example, I dont see how I would do .getCharacters. I am getting the Id in, and stored properly. But after that everything is wrong
|
# ? Jan 25, 2012 22:16 |
|
DholmbladRU posted:xml example Running that exact XML using this output loop code:
code:
7th event is the Character event you're looking for. And the invalid closing tag and its error message follows next. Tracking an XML stream is tricky enough on its own, doubly so if you're learning the language at the same time. Plus it's overkill unless your XML files are 100+MBs or you have a concrete performance target. May I suggest DOM instead? Here's a DOM version of the previous parsing debugger: code:
code:
|
# ? Jan 26, 2012 07:18 |
|
I am in: Thank you for providing me with these methods. It is really helping me understand this better. Eventually I will be pulling in an xml file with more than just the location tag. code:
like this code:
code:
code:
DholmbladRU fucked around with this message at 19:22 on Jan 26, 2012 |
# ? Jan 26, 2012 16:47 |
|
DholmbladRU posted:like this Yes, this is more like it. The Node API docs here summarizes different element types and how they are matched to Java interfaces. It doesn't show an example, but the intended way to use the Node API is like this: code:
code:
|
# ? Jan 26, 2012 20:33 |
|
Yeah seems like this should work, thanks for all the help. Is there a way to grab the 1, or the "home id='1'"? When that is added as a node it only contains 'home: null'. The ID doesnt seem to be read anywhere.
|
# ? Jan 26, 2012 21:47 |
|
DholmbladRU posted:Yeah seems like this should work, thanks for all the help. Is there a way to grab the 1, or the "home id='1'"? When that is added as a node it only contains 'home: null'. The ID doesnt seem to be read anywhere. You can read all the attributes from a NamedNodeMap object by calling node.getAttributes() when the node's type is Node.ELEMENT_NODE.
|
# ? Jan 26, 2012 22:41 |
|
I am getting a bunch of lines where getNodeName()="" and getNodeValue()=""code:
System.out.println(node.getNodeType()); System.out.println(node.getFirstChild()); System.out.println(node.getNodeName()); System.out.println(node.getNodeValue()); There are no trailing spaces in my xml document, I even ruined the tabing to make sure.. code:
DholmbladRU fucked around with this message at 23:59 on Jan 26, 2012 |
# ? Jan 26, 2012 23:54 |
|
DholmbladRU posted:There are no trailing spaces in my xml document, I even ruined the tabing to make sure.. It sure looks like there are some newlines in there...
|
# ? Jan 27, 2012 07:47 |
|
If you really want to work with xml, I recommend using a library like XOM (my favorite) or JDOM (the most well-known). It will make your life a billion times easier.
|
# ? Jan 27, 2012 16:27 |
|
Or you can just use groovy. It makes xml super simple.
|
# ? Jan 27, 2012 16:33 |
|
TRex EaterofCars posted:Or you can just use groovy. It makes xml super simple. Because adding a whole language to a project for a single feature is no problem for anyone...what advantages and features specifically addressing XML does Groovy have? Seconding XOM. It's straightforward in its usage.
|
# ? Jan 27, 2012 19:36 |
|
Doctor w-rw-rw- posted:Because adding a whole language to a project for a single feature is no problem for anyone...what advantages and features specifically addressing XML does Groovy have? No need to be a dick; XML in Java is so hairy that writing a small class in Groovy is vastly preferable. Java's going polyglot anyhow, might as well jump on board. To answer your question, XML is basically a first class citizen in Groovy. Both reading and writing are super simple. I make judicious use of MarkupBuilder and XMLParser myself. http://groovy.codehaus.org/Processing+XML
|
# ? Jan 27, 2012 20:27 |
|
TRex EaterofCars posted:No need to be a dick; XML in Java is so hairy that writing a small class in Groovy is vastly preferable. Java's going polyglot anyhow, might as well jump on board. While your statement is true, that XML is a first citizen in groovy and its parsing is trivial, I still don't get what's so difficult in Java either (with the standard DOM or SAX parsers). Sure, some libraries may come and make it even easier, but...holy moly, you can say anything about it except that it's hard. Their only requirement is to read the documentation, then is a breeze. I personally favor SAX for the simple reason that is faster and can parse relatively big XML files (where DOM would choke for example: OutOfMemoryError). Writing a SAX handler is quite straight-forward as well. for small XMLs though, DOM is good enough for every day use.
|
# ? Jan 27, 2012 20:45 |
|
rhag posted:While your statement is true, that XML is a first citizen in groovy and its parsing is trivial, I still don't get what's so difficult in Java either (with the standard DOM or SAX parsers). It's obviously subjective but I seriously hate working with XML in Java. It's long winded and error prone, and the less I type the better. Groovy's is much easier to read and understand later as well. There are streaming parsers and builders for Groovy as well.
|
# ? Jan 27, 2012 20:54 |
|
TRex EaterofCars posted:No need to be a dick; XML in Java is so hairy that writing a small class in Groovy is vastly preferable. Java's going polyglot anyhow, might as well jump on board. Sorry, wasn't trying to be a dick. I don't really favor the trend towards JVM languages that aren't statically typed. If I want to go for something interpreted or much looser in general than Java, I'm happy to make use of Objective-C and Python. And for many projects, usage of Groovy or even Scala is a pretty hard sell, so someone working on a project might not necessarily have the option to add a whole new language, particularly not if there's - for example - established practices for testing and a test scaffolding that expects things to be one way, and metrics that evaluate said testing. That is to say, for some, process might get in the way of progress. I only took a very brief look, but it seems that Groovy has a concise format for parsing, but as someone who writes in Java, verbosity can sometimes be tolerated for other features. In the case of XOM, it can clean up the DOM of HTML files, which is what I like it for.
|
# ? Jan 27, 2012 21:33 |
|
|
# ? May 10, 2024 14:17 |
|
Doctor w-rw-rw- posted:Sorry, wasn't trying to be a dick. I don't really favor the trend towards JVM languages that aren't statically typed. If I want to go for something interpreted or much looser in general than Java, I'm happy to make use of Objective-C and Python. And for many projects, usage of Groovy or even Scala is a pretty hard sell, so someone working on a project might not necessarily have the option to add a whole new language, particularly not if there's - for example - established practices for testing and a test scaffolding that expects things to be one way, and metrics that evaluate said testing. That is to say, for some, process might get in the way of progress. I hear ya. Chaining NekoHTML to Groovy's XML processor to get markup repair isn't too bad ( code:
In regards to losing the static typing, one nice thing about Groovy is that type declarations are supported. You can write near-Java (up to a few subtleties) and Groovy will gobble it down.
|
# ? Jan 27, 2012 22:15 |