|
Gravity Pike posted:Shaving off six clock cycles by using two variables instead of one is going to be a gnat's fart compared to opening a TCP connection. Yes, and while Smarmy Coworker could probably get HotSpot to spit out the assembly code that it would run and start counting instructions I wouldn't bother.
|
# ? Apr 3, 2014 22:31 |
|
|
# ? Jun 11, 2024 15:08 |
|
yeah I usually value being readable I just totally farted on iterating all of a sudden because I'm redoing a project from the ground up and my professor told me that he grades optimization so I was scared
|
# ? Apr 3, 2014 23:11 |
|
rhag posted:To make code execute from the context you can add an afterPropertiesSet method to the beans, in which you can do your stuff. Or, use a static method and call it as a factory method from the XML. Thanks for the idea, but this still isn't quite what I'm trying to get since Maven won't run those tests. I did find some additional annotations in the Spring documentation on a second look that I think will work out by just overriding contexts through @ContextHierarchy.
|
# ? Apr 3, 2014 23:33 |
|
Smarmy Coworker posted:yeah I usually value being readable I just totally farted on iterating all of a sudden because I'm redoing a project from the ground up and my professor told me that he grades optimization so I was scared Ah. Sadly, homework coding standards are somewhat different than professional coding standards.
|
# ? Apr 3, 2014 23:39 |
|
dereekb posted:Thanks for the idea, but this still isn't quite what I'm trying to get since Maven won't run those tests. I'm completely lost. So, you use maven, you put unit tests in test/java and maven won't run them? How is that possible?
|
# ? Apr 4, 2014 00:48 |
|
rhag posted:I'm completely lost. So, you use maven, you put unit tests in test/java and maven won't run them? How is that possible? Something got lost in translation and reading I'm sure, haha. No worries, I got it working .
|
# ? Apr 4, 2014 01:31 |
|
I am supposed to edit class RefUnsortedList to include method endInsert.Homework posted:Design another public method to be added to the RefUnsortedList class, which inserts an here is RefUnsortedList: Java code:
Java code:
Java code:
Java code:
FAT32 SHAMER fucked around with this message at 05:41 on Apr 4, 2014 |
# ? Apr 4, 2014 05:27 |
|
It looks to me like the 'find' method does something pretty similar to what you're looking for (except that it doesn't insert, obviously).
|
# ? Apr 4, 2014 07:19 |
|
Kilson posted:It looks to me like the 'find' method does something pretty similar to what you're looking for (except that it doesn't insert, obviously). I did try that, however how would I use it? I tried while( list != null ) { find( null); } and the programme compiles, but it sits there and doesn't finish like it's looping to infinity. would it be Java code:
FAT32 SHAMER fucked around with this message at 07:43 on Apr 4, 2014 |
# ? Apr 4, 2014 07:24 |
|
I figured it out, though I'm positive there's a better way to do it than using an if/else statement to do the same thing either way.Java code:
|
# ? Apr 4, 2014 10:37 |
|
Tusen Takk posted:I figured it out, though I'm positive there's a better way to do it than using an if/else statement to do the same thing either way.
|
# ? Apr 4, 2014 10:43 |
|
pigdog posted:Uh, yes? Such if statement is completely useless; remove it and leave the contents of one of the options. This is why you shouldn't stay up until 6a doing homework
|
# ? Apr 4, 2014 10:49 |
|
Tusen Takk posted:This is why you shouldn't stay up until 6a doing homework So that's why you're writing a public void endInsert( Object element ) method while your RefUnsortedList class already has one?
|
# ? Apr 4, 2014 11:07 |
|
pigdog posted:So that's why you're writing a public void endInsert( Object element ) method while your RefUnsortedList class already has one? No, I had to add that method to RefUnsortedList and that's where that snippet is from.
|
# ? Apr 4, 2014 11:15 |
|
Java code:
|
# ? Apr 4, 2014 16:15 |
|
Smarmy Coworker posted:
Yes. 1: always catch the most specific exception visible. This way, unchecked exceptions can properly propagate instead of getting squelched, among other reasons. 2: Don't use system.exit. either rethrow the exception or don't catch it in the first place, if this is something that should end your flow.
|
# ? Apr 4, 2014 18:41 |
|
project guidelines tells me "print one line to system.err and exit. and only do this." but good point on #1, I've cleaned up to catch IOExceptions and some others Smarmy Coworker fucked around with this message at 18:50 on Apr 4, 2014 |
# ? Apr 4, 2014 18:47 |
|
Smarmy Coworker posted:project guidelines tells me "print one line to system.err and exit. and only do this." Then do it for this class only, and note that you'd be crucified if you did that in a real job as "the rear end in a top hat that made the server mysteriously crash". loving Academia
|
# ? Apr 4, 2014 23:07 |
|
Smarmy Coworker posted:project guidelines tells me "print one line to system.err and exit. and only do this." You can return from main and the program will exit. You don't have to specifically call System.exit to do this.
|
# ? Apr 4, 2014 23:11 |
|
rhag posted:You can return from main and the program will exit. You don't have to specifically call System.exit to do this.
|
# ? Apr 5, 2014 00:21 |
|
rhag posted:You can return from main and the program will exit. You don't have to specifically call System.exit to do this. It's been ages since I did Java, but does System.exit put up any happy messages or is it the same program end as return? For my question, I'm getting started with Java to knock some rust off and gain some experience with a larger sized project in the language. I made a little maze game in C++ and want to build a mapmaker for the game in Java. I know the OP recommends Eclipse (with or without Netbeans, I assume), but does anyone use DrJava as an IDE? It's a light-weight .jar and supports some simple project management. I could use Eclipse, but my understanding is it takes some TLC to get setup. As far as the mapmaker is concerned relearning the primitives and how they interact has lead me to be greatly concerned. The map files are not human readable and just a simple collection of bytes: the first two define the size of the map and each subsequent byte defines a single space on a grid. I did this to avoid having to create an overly complicated parser and to keep things simple (the largest map allowed is 16x16). For what it's worth I used bit masking to encode the information for each space. First and foremost, is there a reason that I shouldn't be using Java if I working at this low of a level? When prepping for this project I cam across this Oracle tutorial advising against using the byte streams. Granted that could just be in the context of reading characters, since Java is UTF-16 from the bottom up. Also, when using the byte streams should I expect strange behavior when reading a single byte at a time? For example 0x80 is a byte that occurs in all maps (defines the border), will they read and write that correctly? I ask, because Java pitched a fit at byte = 0x80 but was fine with byte = -127.
|
# ? Apr 5, 2014 22:33 |
|
BirdOfPlay posted:It's been ages since I did Java, but does System.exit put up any happy messages or is it the same program end as return? Returning out of main will give you exit code 0. System.exit(n) can give you another code (traditionally anything nonzero is an error).
|
# ? Apr 6, 2014 00:47 |
|
If you're reading a file containing binary data, you'll want to get in the habit of using a DataInputStream rather than operating on a raw InputStream. 0x80 is not a byte literal, it's an int literal- one that would not fit in a signed byte. That Java does not have a proper byte literal is a bit of an annoyance, but you can do what you want by using "((byte)0x80)".
|
# ? Apr 6, 2014 00:57 |
|
Bytes in java are going to be confusing if you come from a C background, because they are values within the range of -128 to 127. Java wants to interpret 0x80 as an int - it's value is 0x00000080, or 128, which is too big to fit in a byte (in the same way that 1024 is too big to fit in a byte.) Beyond how you represent literals in your source code, java is fine for manipulating bytes. It's not like the language gets confused by certain patterns of bits. The tutorial is warning you that a byte stream is the wrong tool for the job of manipulating text - you should you a character stream. As far as I'm aware, IntelliJ and Eclipse are the standard IDEs. When I install a fresh Eclipse, I immediately download the m2e Maven plugin and a git plugin, and then set tabs to be replaced by 4 spaces. I consider it "usable" at this point, and feel the rest out as I go.
|
# ? Apr 6, 2014 01:11 |
|
It's me, I'm the last hold out using NetBeans I just like the UI better than eclipse and it's builtin maven support seals the deal. I use eclipse for Android stuff, but I can't get over the UI.
|
# ? Apr 6, 2014 02:20 |
|
Janitor Prime posted:It's me, I'm the last hold out using NetBeans Look man, get your eyes checked. I tried to use NetBeans for a thing, hoping it had gotten better, but I actually laughed out loud at the terrible lowest bidder swing API in 2014. Eclipse has maven support in 30 seconds. Please stop defending your abuser, it's not cool.
|
# ? Apr 6, 2014 02:35 |
|
For people who are professional Java developers, IntelliJ basically takes Eclipse and makes it look like a little crying child that you need to take care of all the time. OK, it's not that bad and IDE wars are holy wars, etc.
|
# ? Apr 6, 2014 02:38 |
|
baquerd posted:For people who are professional Java developers, IntelliJ basically takes Eclipse and makes it look like a little crying child that you need to take care of all the time. I never figured out how to get per-thread stepping to work with Android Studio (read: IntelliJ). Which is kind of a big deal when doing multithreaded debugging.
|
# ? Apr 6, 2014 05:32 |
|
Gravity Pike posted:As far as I'm aware, IntelliJ and Eclipse are the standard IDEs. When I install a fresh Eclipse, I immediately download the m2e Maven plugin and a git plugin, and then set tabs to be replaced by 4 spaces. I consider it "usable" at this point, and feel the rest out as I go.
|
# ? Apr 6, 2014 08:32 |
|
I literally installed Kepler today, and it didn't come with.
|
# ? Apr 6, 2014 09:28 |
|
Thanks for the help, but what the gently caress is this ("Modified UTF-8") poo poo? So, when it reads "0x80," it returns "0xC480." Or for "0xF8" you get "0xC7B8." EDIT: Whoops, readByte() works as expected, I thought there was just the read() method. But still, why would that be the simple solution to anything? How many ops does it take to recajigger the original byte? BirdOfPlay fucked around with this message at 09:56 on Apr 6, 2014 |
# ? Apr 6, 2014 09:45 |
|
java is targeted at applications where reading characters and human-scale numbers and Web Things are more common than dealing with raw byte layouts. that doesn't mean you can't use it for the latter but the 'easy path' through many apis is going to be higher level than you'd prefer. an alternative would be to make dealing with packed bits easy and xml-rpc hard, but there are already languages for that.
|
# ? Apr 6, 2014 11:17 |
|
BirdOfPlay posted:Thanks for the help, but what the gently caress is this ("Modified UTF-8") poo poo? Okay, you don't want streams. If you are cool with buffers and understand that you need to check return values, use FileChannel. It is the thinnest of thin wrappers. You read bytes into a buffer of bytes called a... ByteBuffer. Brain Candy fucked around with this message at 12:50 on Apr 6, 2014 |
# ? Apr 6, 2014 12:45 |
|
Gravity Pike posted:I literally installed Kepler today, and it didn't come with. It's in the Java EE version. After being forced to use IntelliJ for like 8 months I still prefer Eclipse.
|
# ? Apr 6, 2014 14:55 |
|
yesterday i discovered java.nio.file.Files and it's pretty cool. I enjoy the ability to blast a Files.readAllBytes without having to instantiate an input stream what OTher c00l stuff is there??
|
# ? Apr 6, 2014 16:59 |
|
I have been programming in Python but now am trying to modify someones code that is in Java. Is there a reason that this person would not have used this.ID instead of ID in the getID() function? I cannot tell why they would have omitted it.Java code:
|
# ? Apr 7, 2014 23:02 |
|
Jose Cuervo posted:I have been programming in Python but now am trying to modify someones code that is in Java. Is there a reason that this person would not have used this.ID instead of ID in the getID() function? I cannot tell why they would have omitted it. Pure code style - there's no difference as there's no other ID variable in scope. If you have a class like this: Java code:
Java code:
|
# ? Apr 7, 2014 23:12 |
|
Jose Cuervo posted:I have been programming in Python but now am trying to modify someones code that is in Java. Is there a reason that this person would not have used this.ID instead of ID in the getID() function? I cannot tell why they would have omitted it. unlike python classes any defined parameters are always in scope if this person had instantiated another ID variable in a method (not getID because that would be dumb, but i guess this would ALSO be dumb anywhere else, except for javadocs looking nice, but i think capitalization matters so they should just use 'id' for that?) they would then have to use this.ID to access the parameter. So basically, JingleBells posted:Pure code style - there's no difference as there's no other ID variable in scope. Smarmy Coworker fucked around with this message at 23:44 on Apr 7, 2014 |
# ? Apr 7, 2014 23:38 |
|
Yeah, in Java this. is only needed if there is another variable of the same name in local scope and you're accessing the instance variable. Notably, calling this.ID does not invoke a getter method like it does in some languages.
|
# ? Apr 7, 2014 23:45 |
|
|
# ? Jun 11, 2024 15:08 |
|
That said, getters and setters can be important. If you have a subclass that has slightly different behavior in the getter/setter, you're potentially causing subtle bugs by referencing the variable directly. Mainly, it depends on code style, both of the developer and of the codebase. If you're working on Enterprise Software, you should probably always use getters/setters.
|
# ? Apr 8, 2014 00:35 |