|
Aleksei Vasiliev posted:Can't you just check for null || arr.length == 0 or is 0-len a valid condition? Yes, but for a large GUI codebase previously run under Java 6, it seems odd to have to go into all classes which checked that it was null and add the extra code. I could also Override the TreeMap method... there's ways around this, but it just seems like you shouldn't need to patch code just for the remainder of a major release. mister_gosh fucked around with this message at 21:02 on Aug 13, 2012 |
# ? Aug 13, 2012 21:00 |
|
|
# ? Jun 3, 2024 05:03 |
|
mister_gosh posted:I could also Override the TreeMap method... there's ways around this, but it just seems like you shouldn't need to patch code just for the remainder of a major release. Which is reasonable I agree, but time has proven once again that you can't count on any new update not breaking your poo poo. There is wisdom in not updating your platform every time a major update comes along. You're lucky that you still have access to the source code of your program and can fix it.
|
# ? Aug 13, 2012 23:01 |
|
Is there a tool out there that will attach to a running Servlet container and log all of the method calls that are made? I'm trying to generate some system documentation for a framework whose developer is no longer with the team and stepping through the code manually is going to be pretty painful.
|
# ? Aug 15, 2012 20:34 |
|
wins32767 posted:Is there a tool out there that will attach to a running Servlet container and log all of the method calls that are made? I'm trying to generate some system documentation for a framework whose developer is no longer with the team and stepping through the code manually is going to be pretty painful. You could use AspectJ and set the aspect to match all method calls, a quick google suggests this might work. Be careful - I did this once by setting the wrong aspect, and logged every method call in all the libraries I was using too
|
# ? Aug 15, 2012 20:54 |
|
wins32767 posted:Is there a tool out there that will attach to a running Servlet container and log all of the method calls that are made? I'm trying to generate some system documentation for a framework whose developer is no longer with the team and stepping through the code manually is going to be pretty painful. Try attaching with VisualVM and doing some "CPU Profiling"
|
# ? Aug 15, 2012 20:55 |
|
Is there a good book or online resource for some one with zero java experience? I swear half the job descriptions I read are looking for java experience, and I have none.
|
# ? Aug 16, 2012 15:08 |
Kaluza-Klein posted:Is there a good book or online resource for some one with zero java experience? I swear half the job descriptions I read are looking for java experience, and I have none. http://docs.oracle.com/javase/tutorial/tutorialLearningPaths.html
|
|
# ? Aug 16, 2012 21:56 |
|
I must say, I completely agree. Unlike many languages, the best learning tools for Java are made by the people who actually make the language. Also, just generally check the documentation if you have a question. It's extremely well written and besides the syntax, it pretty much can teach you everything you need to know. Good luck with learning Java!
|
# ? Aug 19, 2012 22:38 |
|
I am attempting to teach myself proper Unit Testing using JUnit but into something the first time and would like some help. I'm just getting into backend programming after coming from mobile so hopefully this question doesn't cause you guys to want to kill me. I've been going through some example classes to create proper unit tests and came across this. I'll simplify it a bit for sake of SA. code:
Also, can someone explain downcasting. I am having a really hard time wrapping my head around it. code:
|
# ? Aug 22, 2012 00:31 |
|
notMordecai posted:I am attempting to teach myself proper Unit Testing using JUnit but into something the first time and would like some help. I'm just getting into backend programming after coming from mobile so hopefully this question doesn't cause you guys to want to kill me. Well, you need to document what executeSomeThing is supposed to do. Create Cat and Dog objects and pass them through, checking to make sure that executeSomeThing produces the correct result with a number of different arguments, including illegal ones if applicable to test failure conditions. Since it appears this function will likely mutate the parameters, you need to check to make sure this state manipulation was done correctly and without side effects. quote:Also, can someone explain downcasting. I am having a really hard time wrapping my head around it. Downcasting's most immediate effect is to allow compile time access to the fields and methods of the child object's class. So if Parent has method X() and Child adds method Y(), you would need to downcast to call Y().
|
# ? Aug 22, 2012 00:38 |
|
baquerd posted:Well, you need to document what executeSomeThing is supposed to do. Create Cat and Dog objects and pass them through... Yeah that's what I was trying to get at. So I WOULD create and define the fields of a class in a unit test, then pass that entire class to unit test it? It's more of a general question and less of a "this scenario" question. I've never attempted to test a method that had entire objects pass into it.
|
# ? Aug 22, 2012 05:16 |
|
notMordecai posted:Yeah that's what I was trying to get at. So I WOULD create and define the fields of a class in a unit test, then pass that entire class to unit test it? For example if the method was supposed to call the Dog class's giveTreat method, you'd create a mock Dog object, tell it to expect a giveTreat call, then call the method you're testing, then verify the mock's method got called. (These don't replace JUnit, you'd use them together.)
|
# ? Aug 22, 2012 05:32 |
|
Base Emitter posted:You might want to take a look at mock objects, too. For example the EasyMock or PowerMock libraries. Mock objects are basically fake replacements that allow you to verify that the class under test tickled it's dependencies in all the right places. yeah I got very familiar with Mockito trying to figure this out after realizing I would need to use it for this case. Still came up empty on a solution. Hopefully I can take a crack at it tomorrow.
|
# ? Aug 22, 2012 05:56 |
|
While we're on the topic, any favorite Java mock libraries?
|
# ? Aug 22, 2012 11:18 |
|
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.
|
# ? Aug 22, 2012 14:14 |
As a general policy, if I have a constructor in Java which takes two points (for example) and produces a line, is it a good idea to use the points as a reference or should I make copies? That is...Java code:
Java code:
|
|
# ? Aug 22, 2012 16:13 |
|
Always make a copy of mutable data you're given and going to store unless a) it's internal to the implementation (not public), or b) you document it properly and can just yell at the users if they gently caress it up. (this is in Effective Java) e: or c) you're doing weird poo poo where best practices are wrong Jo posted:On the one hand, people might be expecting to fiddle around with the values after the creation of the object.
|
# ? Aug 22, 2012 16:20 |
|
Jo: Well, Points are mutable. It depends on what you're trying to do. In some situations it can be very useful to have composed objects update under your feet, but if you mutate the Points that are passed in it may seem like "spooky action at a distance" from the caller's perspective. At any rate, it is indeed an important issue to consider, and worth documenting.
|
# ? Aug 22, 2012 16:21 |
Internet Janitor posted:Jo: Well, Points are mutable. It depends on what you're trying to do. In some situations it can be very useful to have composed objects update under your feet, but if you mutate the Points that are passed in it may seem like "spooky action at a distance" from the caller's perspective. At any rate, it is indeed an important issue to consider, and worth documenting. I was fiddling with a reimplementation of Ken Silverman's BUILD engine. Part of my reasoning was, if someone dicks with a vertex, I'd like to see the lines and sectors update automatically without having to iterate through each line and sector. At the same time, perhaps that's the correct way to do it on update. What if someone hoses a vertex? We'd need to update all the lines and sectors anyways to account for the loss.
|
|
# ? Aug 22, 2012 16:54 |
|
Also check out Flyweight pattern if it's applicable in your context.
|
# ? Aug 22, 2012 18:13 |
pigdog posted:Also check out Flyweight pattern if it's applicable in your context. Thank you. I think this will be beneficial.
|
|
# ? Aug 22, 2012 22:29 |
|
Safe and Secure! posted:While we're on the topic, any favorite Java mock libraries? I like JMockit. It takes a while to learn but it's absurdly powerful and quick once you get the hang of it.
|
# ? Aug 23, 2012 03:47 |
|
I personally prefer Mockito. I found it to allow me to write cleaner and easier to maintain code, and it's extremely powerful.
|
# ? Aug 23, 2012 13:47 |
|
Easiest way to parse xml? I'm this close to just using regexes.
|
# ? Aug 24, 2012 21:04 |
|
Tres Burritos posted:Easiest way to parse xml? I'm this close to just using regexes. Any library that gives you XPath?
|
# ? Aug 24, 2012 21:32 |
|
Yeah there's no good reason to code that from scratch.
|
# ? Aug 24, 2012 23:14 |
|
Tres Burritos posted:Easiest way to parse xml? I'm this close to just using regexes. Funny, was just passing this StackOverflow link around the office today.
|
# ? Aug 24, 2012 23:38 |
|
bartkusa posted:Funny, was just passing this StackOverflow link around the office today. Yeah I did some googling and found that too. Is dom4j an acceptable answer or are the cool kids not using that?
|
# ? Aug 24, 2012 23:41 |
|
Tres Burritos posted:Yeah I did some googling and found that too. Is dom4j an acceptable answer or are the cool kids not using that? Whatever works for you is acceptable. If you have big XMLs to parse and/or memory is tight, use SAX. It's a bit more work, but it's relatively fast. A DOM parser is nice and easy, but it takes up a tad bit more memory to do it's job. If you only need parts of the XML (the value of all the test elements for example, how many times does the person tag appears, etc.), don't parse that thing, use XPath. One decent and relatively fast library for java is XOM (http://www.xom.nu/), but there are many others (including the ones that come with the jdk). Which one you use is just a matter of taste and your requirements. Personally I prefer the jdk bundled libraries.
|
# ? Aug 25, 2012 13:16 |
|
What is the recommended book or video series of java with no previous experience?
|
# ? Aug 26, 2012 09:34 |
|
ZombieIsland posted:What is the recommended book or video series of java with no previous experience? Start with the tutorial and go from there: http://docs.oracle.com/javase/tutorial/ . After that get a java book that has decent reviews, that is focused on whatever you're interested in.
|
# ? Aug 26, 2012 13:26 |
|
trex eaterofcadrs posted:Mocking really pisses me off but when I have to, I use Mockito. Have you never had to test code that depends on an external service? Mocks are extremely useful for when you are trying to actually create unit tests instead of integration tests. I suppose they could be overdone, but at my shop they're underutilized. quote:Yeah I did some googling and found that too. Is dom4j an acceptable answer or are the cool kids not using that? Either DOM or SAX will be fine. Whatever you do, for the love of god please don't try to write a regex for parsing. I can empathize with the sentiment that many Java libraries are poorly documented and hard to understand, but you'll still save yourself a ton of time by not rolling your own solutions for common tasks like consuming XML. quote:What is the recommended book or video series of java with no previous experience? Head First Java is frequently recommended. Sierra's SCJP 6 is good for learning the syntax and basic libraries, but won't teach you good practice. Once you have some experience under your belt, I strongly recommend Effective Java and Head First Design Patterns. They tackle pattern reuse, which is just as important as code reuse. Lord Of Texas fucked around with this message at 21:35 on Aug 26, 2012 |
# ? Aug 26, 2012 21:15 |
|
Lord Of Texas posted:Have you never had to test code that depends on an external service? Mocks are extremely useful for when you are trying to actually create unit tests, and integration tests. I suppose they could be overdone, but at my shop they're underutilized. I think this is a big point, and if I recall, has been debated in this thread before. But the lack of understanding about the different types of testing that code can and should undergo can lead to excessive or improper use of helpful technology. Even in testing, it's still about using the right tool for the job - but you need to know what the job is first.
|
# ? Aug 26, 2012 21:32 |
|
Anyone interested in the review of the manuscript of the fourth edition of Spring in Action? If you are interested in reviewing, check out the main thread.
|
# ? Aug 28, 2012 19:14 |
|
This might be a dumb question, but my CS190 class has us using jGRASP. I like the Netbeans interface better, how do I go about writing in Netbeans and then moving it over to jGRASP for the Professor?
|
# ? Aug 28, 2012 20:16 |
|
I can't imagine you need to do anything IDE-specific, especially for a simple Java course. I did all of my Java course work in Sublime Text 2, and the only thing I can recall my instructor's Netbeans-generated code having was a package line that I didn't need.
|
# ? Aug 28, 2012 20:58 |
|
Star War Sex Parrot posted:I can't imagine you need to do anything IDE-specific, especially for a simple Java course. I did all of my Java course work in Sublime Text 2, and the only thing I can recall my instructor's Netbeans-generated code having was a package line that I didn't need. I don't really. I'm writing my first project right now in jGrasp, it was more of an aesthetic thing.
|
# ? Aug 28, 2012 22:43 |
|
There shouldn't be anything special, even the package declaration is a part of the Java language. I'm sure if you had some issues showing up in NetBeans that didn't happen in JGrasp we could help figure it out.
|
# ? Aug 28, 2012 23:29 |
|
Here's a design question. It has members of my development team on opposite sides, so I thought I'd get the opinions of the thread. ----- Say you're calling a method that returns some business resource from an external service. code:
Your options when the resource is not found are: 1) return null 2) throw a checked exception for the client code to handle 3) return an empty ThingBean with no fields populated
|
# ? Aug 30, 2012 16:34 |
|
|
# ? Jun 3, 2024 05:03 |
|
Option 3 is the solution I'd go with if I was asked to come up with the worst solution. If throwing an unchecked exception is out, then so is returning null, as they can fail to handle that (and cause a NPE).
|
# ? Aug 30, 2012 17:34 |