|
Yes, it's a configuration issue. I had this thing running on Tomcat and managed to get DEBUG (and TRACE) level logging working there, but now on jetty I'm back to only having INFO and up. Not that it matters anymore, I just search-replaced all my debug calls with info calls and then reverted those changes before committing my work back to git.
|
# ? Apr 21, 2016 16:13 |
|
|
# ? Jun 1, 2024 09:21 |
|
Whoa, just found out about the Generate menu in Netbeans, pretty drat cool time saver
|
# ? Apr 23, 2016 13:12 |
|
Hey again, so I have been reading up on Java's pass by value. And just want to confirm if I fully understand what's happening. Specifically I'm talking about this:Java code:
Nude fucked around with this message at 02:06 on Apr 26, 2016 |
# ? Apr 26, 2016 02:03 |
|
In Java, with the exception of a small handful of types, everything you interact with is actually a pointer that points to a specific object in memory. Method parameters are always passed by value. For most types, when you pass it as a parameter, the called function receives a copy of the pointer that points to the same piece of memory. So, if you reassign a method parameter to point to somewhere different, that has no effect outside of the method - you're only changing the method's local copy of the pointer. But if you make a change to the actual object being pointed to, that will be visible outside of the method, because all the pointers refer to the same object in memory.
|
# ? Apr 26, 2016 02:21 |
|
Or to put the same thing another way, if you're not familiar with pointers - when you do something like thisJava code:
So when you have a method like Java code:
Java code:
It's called pass by value because when you call changeNameToSherlock(bob), you're passing in whatever the value of 'bob' is, not the actual 'bob' reference itself. So you can't change what 'bob' is looking at, reassigning it to another object or whatever - but if you can mutate the thing that 'bob' is looking at, 'bob' will see those changes because it's looking at the same object Same thing is happening when you pass in bob.name - you're taking the name reference inside that object, and passing its value to a method. And that value is a String, and those are immutable in Java, so you can't change what bob.name sees either.
|
# ? Apr 26, 2016 03:16 |
|
Jabor posted:In Java, with the exception of a small handful of types, everything you interact with is actually a pointer that points to a specific object in memory. baka kaba posted:A really good effort post. Okay I'm gonna need seem time to digest these, as my brain goes from understanding to . I'll throw out one last thing on what I took away from this, and if it's still off I suppose I'll have to start reading more in depth about it. I should read more about this stuff anyway as it's kind of fascinating to me. First thing I learned is some objects are immutable and some mutable (two key terms that I didn't really know until I looked them up). This seems to play a big role on how they're used/passed. Now what this suggests to me is that: Java code:
Nude fucked around with this message at 06:47 on Apr 26, 2016 |
# ? Apr 26, 2016 06:45 |
|
Whats key in cases like this is that while if you pass an object, say a Human named bob, and then assign that pointer to something else, you haven't modified the original object, BUT you can modify the state of the object, including other objects it has references to, and those will cause changes to other references because you're still referring to the same object. A key example is a List. You can pass a List like public void doStuff (List inventory){ //does stuff to inventory } If you were to then set inventory = new Arraylist(); That would only modify the local reference, not other references to that object. They'd still point to the original object, and you'd just lose your reference to it. However, if you do something like inventory.add(Bob); Then all other references to that List would see the change, with the new Bob object in the list, because you haven't changed the reference, you've modified the internal state of the object. (Its just in this case, a List, the internal state itself can be references to other objects) You could also do things like inventory.remove(Bob); And other references would see that the List inventory had its internal reference to Bob removed. Clear as mud? Nude posted:
Yep yep Zaphod42 fucked around with this message at 06:59 on Apr 26, 2016 |
# ? Apr 26, 2016 06:56 |
|
Zaphod42 posted:However, if you do something like I want to expand on this part a bit more because it's where everything you're studying starts to become relevant, interesting, and really loving hard See what the JavaDoc for ArrayList has to say about modifying a list while other threads have a reference to it. quote:Note that this implementation is not synchronized. If multiple threads access an ArrayList instance concurrently, and at least one of the threads modifies the list structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more elements, or explicitly resizes the backing array; merely setting the value of an element is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the list. If no such object exists, the list should be "wrapped" using the Collections.synchronizedList method. This is best done at creation time, to prevent accidental unsynchronized access to the list: What this means is that if one thread is iterating over the list and another thread calls add or remove then the first thread will throw that ConcurrentModificationException. Janitor Prime fucked around with this message at 19:41 on Apr 26, 2016 |
# ? Apr 26, 2016 15:31 |
|
Nude posted:Okay I'm gonna need seem time to digest these, as my brain goes from understanding to . I'll throw out one last thing on what I took away from this, and if it's still off I suppose I'll have to start reading more in depth about it. I should read more about this stuff anyway as it's kind of fascinating to me. It's actually pretty simple conceptually, so if we're confusing you then let me try and hamfist an analogy here Imagine there's a warehouse with all these spaces for boxes. Rows and rows of shelves, with each spot labelled with a specific code so you can specify and find that spot. Some of the spaces are empty, some of them have boxes in them. When you create a new object, it's filed away in the warehouse, and you get a location code back. If you want to interact with the object, you need to go to that location. So you'll probably want to write that location code down, along with a name you can refer to it by. Imagine you have a whiteboard with a list of names and their associated locations If you need someone else to do something with that object, you can give them the location code. That way they can access the same object, by going to the same location. They have their own whiteboard to write the code down along with a name - they can call it whatever they want on their own board, like "IMPORTANT_THING". Maybe later they're done with your object, and they change IMPORTANT_THING on their whiteboard to refer to a different location, some other spot in the warehouse. That won't affect your whiteboard - you'll still have the same name, and the same location code. They can't affect your reference, only you can change that. What they can do it go along to the location in the warehouse, and mess with the object at that location. This is where mutability comes in - if things inside the object can be changed, you'll see those changes when you go to that location yourself. You're both looking at the same object, because you both have independent references to the same location. Now imagine the object at that spot (call it Spot A) contains its own objects. They're not actually inside it, it's more like it contains its own whiteboard with names and location codes - the 'contained' objects are actually in different spots in the warehouse. The important thing here is that you and the other guy both have access to the same whiteboard, because it's inside the object you're both looking at. So in this situation, you can change a reference (say pointing "Name" from Spot B to Spot C), and everyone with access to the object will see that change, because they're looking at the same whiteboard. But if anyone anywhere has their own separate whiteboard reference to Spot B, that won't be changed So in Java, when you're working with objects, you're only passing around their location codes, not the whiteboard itself (which would be passing a reference). It's a subtle difference, but it means a method can only affect an object it's passed, it can't make other things that are looking at that object point to something else. If you want to do something like that (if you have several things that all need to be looking at the same object, with the ability to change where they're all looking) you need to stick the reference in an object and pass that around. That's all your Human.name field is, in the end - a reference to a String, and anything with access to that object can point it at a different String That's a lot of words for a basic concept I'm probably making it worse
|
# ? Apr 26, 2016 19:07 |
|
Nude posted:
This is correct, and you picked up on another interesting thing here. To help you understand it, I'll introduce a few more terms. Within the Java Virtual Machine's memory, there are two parts, the stack and the heap. How those are internally organized is not important right now. What is, is the way Java deals with them. Look at these examples: Java code:
So, in short, primitives (boolean, byte, short, int, long, float, double, char) are created on the stack and directly contain some number or a character. If you pass a primitive on to a method, it just passes the value, and the method doesn't know where the original primitive was located on the stack. Objects, such as Integer, are created on the heap and accessible by a pointer on the stack. When you pass an object to a method, it actually passes on the pointer and both the method and the place where it was called are now talking to the same object. Much of Object Orientied Programming is about passing on pointers to methods in the correct way and thinking about what effects that'll have. At my job, we often use Integer instead of int, because Integer can be a null pointer, and being able to tell your methods that a variable has not yet been assigned is often useful. In any case, this difference between objects and primitives leads to an interesting quirk: Java code:
In case of objects, such as Integer, == will compare the pointers on the stack. c and d point to different Integer objects, so this will return false. To test for equality, you basically have to check all relevant fields within an object one by one. This is what the equals() method in common JDK objects does, and when you want to compare objects you made yourself, you'll have to implement the equals() method in them. In your example, the == will return true because you are indeed comparing two references that point to the same object on the heap. So, basically, for primitives you want to always use ==, for objects you want to use equals() unless you have a very good reason to compare references. You do use x == null to check whether an object reference is actually a null pointer, an unassigned object. In that case equals() won't work because there's no actual reference yet to any object with an equals() method. Finally, there's the weird case with Strings. Strings are immutable objects and are strongly optimized by Java. Because they cannot change anyway, sometimes Java will take a shortcut to save some memory, and have foo and bar point to the same String object. If that happens, == will return true, otherwise it will be false. This actually depends on the current state of the program, and it's hard to predict what will happen, especially if that method can be called in different situations. So, while string1 == string2 may return true in some cases, it's not a safe way to check String equality, and you should always use string.equals() for that. Carbon dioxide fucked around with this message at 19:44 on Apr 26, 2016 |
# ? Apr 26, 2016 19:37 |
|
I'm worried you guys may be getting ahead of yourselves, when he/she's working out how pass-by-reference works we don't really need to start inserting thread safety or stack vs heap into the conversation right away. Its good stuff but can be very overwhelming and even confusing if you're still trying to nail down the references in the first place. I know, I do it too sometimes Baka kaba's post is just a nice metaphor explaining the concept asked about. code:
|
# ? Apr 26, 2016 21:10 |
|
Zaphod42 posted:
It's called String interning quote:The JVM performs some trickery while instantiating string literals to increase performance and decrease memory overhead. To cut down the number of String objects created in the JVM, the String class keeps a pool of strings. Each time your code declares a string literal, the JVM checks the string literal pool first. If the string already exists in the pool, a reference to the pooled instance returns. If the string does not exist in the pool, a new String object instantiates, then is placed in the pool.
|
# ? Apr 26, 2016 21:31 |
|
Carbon dioxide posted:
#JustJavaThings, but this isn't true right? As far as I remember (phoneposting when I shouldn't be) there's a pool of Integer objects for a certain range of values, and when you do Integer d = 3 it assigns d to the pre-existing object instead of creating a new one. You have to explicitly create a new Integer object if that's what you want. So Java code:
It's more of an issue with Strings, but the general rule is if you want to compare objects by value, use equals() to avoid weird edge case bugs
|
# ? Apr 26, 2016 21:40 |
|
baka kaba posted:#JustJavaThings, but this isn't true right? As far as I remember (phoneposting when I shouldn't be) there's a pool of Integer objects for a certain range of values, and when you do Integer d = 3 it assigns d to the pre-existing object instead of creating a new one. You have to explicitly create a new Integer object if that's what you want. So I just checked the bytecode that line generates and you're right. The autoboxing makes it Integer d = Integer.valueOf(3), which does check a cache for values between -128 and a system property that defaults to 127. I didn't know that, but that's okay; I should never care exactly which Integer instances I'm dealing with.
|
# ? Apr 26, 2016 22:16 |
|
Yeah, it's more that == behaves 'differently' depending on how you got your Integer objects, or what values you autoboxed. Ideally you'd never put yourself in a situation where it would trip you up, but it's still a gotcha that could be real confusing if you had no idea it was even a thing
|
# ? Apr 26, 2016 22:24 |
|
I was tinkering around was just about to ask how come:code:
Carbon dioxide posted:This is correct, and you picked up on another interesting thing here. To help you understand it, I'll introduce a few more terms. Within the Java Virtual Machine's memory, there are two parts, the stack and the heap. How those are internally organized is not important right now. What is, is the way Java deals with them. Look at these examples: Janitor Prime posted:It's called String interning This clears that up, had a mini hard attack thinking I was still not getting it ha ha. That Integer vs int stuff that Carbon Dioxide posted is really interesting. I want to thank you guys for the effort posts and analogies extremely useful for grasping this concept. Nude fucked around with this message at 03:39 on Apr 27, 2016 |
# ? Apr 27, 2016 03:17 |
|
I'm testing a game based out of a JFrame. I'm testing the results of methods that happen when you hit a button with JUnit. An example method definition is something like this:code:
|
# ? Apr 27, 2016 05:00 |
|
I'd probably debug that method and see what gets passed in when you click the button normally, then create an instance of ActionEvent in your test that matches that. I don't know if that counts as valid testing, or what.
|
# ? Apr 27, 2016 05:52 |
|
CPColin posted:I'd probably debug that method and see what gets passed in when you click the button normally, then create an instance of ActionEvent in your test that matches that. I don't know if that counts as valid testing, or what. Well, on a TDD course I took, this is exactly what the instructor did, with a more trivial example: Java code:
Java code:
Java code:
|
# ? Apr 27, 2016 06:21 |
|
Wheany posted:Well, on a TDD course I took, this is exactly what the instructor did, with a more trivial example: This sort of bothers me. What if the sum method was incorrect? Then you're just asserting wrong results and your test is worthless. In a nontrivial case you can't just do that. I know it doesn't stop people though. I've seen plenty of tests that just assert that the method does what it says it does, tautologically, rather than what it's *supposed* to do.
|
# ? Apr 27, 2016 07:12 |
|
In a perfect world maybe tests would be great at making things do what they should do in some grander principled sense, but really what they're supposed to do is make sure things keep doing what the programmer originally expected them to. If you think tests primarily exist to make things work how they "should" you're wrong about tests. They just make sure things keep working how they do, and if not, you know about it sooner rather than later.
|
# ? Apr 27, 2016 07:28 |
|
Kilson posted:This sort of bothers me. What if the sum method was incorrect? Then you're just asserting wrong results and your test is worthless. In a nontrivial case you can't just do that. Unit tests help you make sure that your changes do not change the behavior of existing code. If a test breaks, then your behavior has changed. If that was because you fixed a bug, then you need to fix the test. If it was because your new code caused some side effect you were unaware of, well now you're aware.
|
# ? Apr 27, 2016 08:09 |
|
"Refactoring" has a very specific meaning that I just learned a couple of years ago. I used to think that it's just "do whatever (to make the code better?) and try not to break poo poo" Actually it means that "Whatever changes you do, don't loving change the behavior" and making sure you don't change things requires you to have good unit test coverage. Refactoring and fixing bugs are two different things, and if you find a bug while refactoring, you're supposed to leave it it until you start debugging. This also means that you might have to do a lot of "best effort" changes that might break something while you don't have testable code, to make the code testable (and add tests).
|
# ? Apr 27, 2016 08:16 |
|
Wheany posted:Unit tests help you make sure that your changes do not change the behavior of existing code. Of course if you are fixing a bug you should first write a test for the bug that fails until the bug is fixed. then you know when you have fixed it and you can always confirm there has been no regression
|
# ? Apr 27, 2016 09:00 |
|
Wheany posted:Well, on a TDD course I took, this is exactly what the instructor did, with a more trivial example: Um, isn't this a bit backwards if you are calling it TDD? You are supposed to change the code to make the test green, not the test. So the test should always say 3 (when you write it first), but the sum() method might have originally just returned the constant 3 instead of a+b. smackfu fucked around with this message at 11:55 on Apr 27, 2016 |
# ? Apr 27, 2016 11:50 |
|
smackfu posted:Um, isn't this a bit backwards if you are calling it TDD? You are supposed to change the code to make the test green, not the test. So the test should always say 3 (when you write it first), but the sum() method might have originally just returned the constant 3 instead of a+b. It might have been that, or maybe the teacher was bad. I don't know, all I remember is that the process involved "lol idk, let's just see what the result is"
|
# ? Apr 27, 2016 13:12 |
|
Yeah the teacher was bad lmao. TDD means you write valid tests before you write a single line of implementation code.
|
# ? Apr 27, 2016 15:10 |
|
Wheany posted:Unit tests help you make sure that your changes do not change the behavior of existing code. I understand the general point of tests, and the workflow involved in adding/changing them. I don't understand why asserting wrong behavior through tests is particularly useful. Also what smackfu said.
|
# ? Apr 27, 2016 15:18 |
|
Janitor Prime posted:It's called String interning Wow, and its specifically for strings? Well, that's exactly the kind of compiler voodoo I was talking about. Cool. CPColin posted:I just checked the bytecode that line generates and you're right. The autoboxing makes it Integer d = Integer.valueOf(3), which does check a cache for values between -128 and a system property that defaults to 127. I didn't know that, but that's okay; I should never care exactly which Integer instances I'm dealing with. Yeah it should be irrelevant which is why they do it, but that's good to know. speng31b posted:In a perfect world maybe tests would be great at making things do what they should do in some grander principled sense, but really what they're supposed to do is make sure things keep doing what the programmer originally expected them to. If you think tests primarily exist to make things work how they "should" you're wrong about tests. They just make sure things keep working how they do, and if not, you know about it sooner rather than later. Well, there's unit testing and there's integration testing. Integration testing is definitely about making sure that things keep working as expected when plugged together, and unit tests can be used as regressions testing as well, but you can also use unit testing to verify the original requirements too. TDD is all about that. Making sure things keep working as they did doesn't make sense when you're writing tests before you even started writing code. That's for verifying requirements. smackfu posted:Um, isn't this a bit backwards if you are calling it TDD? You are supposed to change the code to make the test green, not the test. So the test should always say 3 (when you write it first), but the sum() method might have originally just returned the constant 3 instead of a+b. Yepyep. Zaphod42 fucked around with this message at 15:25 on Apr 27, 2016 |
# ? Apr 27, 2016 15:19 |
|
I loving knew mentioning tdd was a terrible idea
|
# ? Apr 27, 2016 18:11 |
|
Wheany posted:I loving knew
|
# ? Apr 27, 2016 18:20 |
|
CPColin posted:I'd probably debug that method and see what gets passed in when you click the button normally, then create an instance of ActionEvent in your test that matches that. I don't know if that counts as valid testing, or what. This is what I'm getting from a different button press: This is where the function is defined. code:
code:
|
# ? Apr 27, 2016 19:43 |
|
Most of that stuff is internal stuff you can't set. You can call the ActionEvent constructor:code:
But, at that point, you're not really testing much.
|
# ? Apr 27, 2016 20:11 |
|
So I'm feeling a bit overwhelmed by the task before me. I took up Java a few years back after working in Perl for years. I'm a biologist who started programming because of the size of the datasets I was working with and because existing tools didn't always do what I wanted them to. I've gotten reasonably far googling and just working my way through problems, but more and more I'm starting to feel limited. I'm purchasing a few recommended books to try to fix this. Anyways, my client has requested I set up a data sharing system. Basically, they want to be able to remotely access and search datasets I've generated. I can do a reasonable amount of database programming. I have a sample tracking app I made that interfaces with a mySQL server through JDBC. It's not too complex, but that part of the problem I at least have an understanding of. The part I'm having trouble with, and this is something I've avoided doing for a while, is actually doing client-server stuff. I want to build a simple interface app that will allow the client to contact my server and request data off of it, but I have no idea where to start. There're a lot of frameworks and a lot of information out there for how to implement a system, and it's a bit overwhelming. Where's a good starting point for building an app like this? Is there a recommended framework to start working with? Down the road I may need to think about creating a dynamic web page for clients to access information, so it might be time for me to start looking into building an actual webserver. Basically, what's the best way to get started on these problems?
|
# ? Apr 27, 2016 22:16 |
|
Adventure Pigeon posted:So I'm feeling a bit overwhelmed by the task before me. I would stay away from a desktop application, for the simple reason that the easiest way for the application to connect to the database would be to simply make the database available on the network. It doesn't matter what database you use, how good your password is, how up to date are you with the patches, a database exposed on the network (internet ... even worse) is a ticking bomb. The question is "when will that data end up all over the internet?" not if. Therefore, my recommendation would be to start with a web application from the get-go. That would allow to (at least) protect the database somewhat. The web application servers are not the pinnacle of security either, but at least some of them are trying. And, to top it off, a web UI should be relatively easier to implement than a desktop app (depending on your skillset of course). But, honestly, at this stage it would be a great idea to just hire a developer (as experienced as you can afford), since it sounds like you're spending a fair bit of time on things that you'd rather not spend time on.
|
# ? Apr 27, 2016 22:23 |
|
Volguus posted:I would stay away from a desktop application, for the simple reason that the easiest way for the application to connect to the database would be to simply make the database available on the network. It doesn't matter what database you use, how good your password is, how up to date are you with the patches, a database exposed on the network (internet ... even worse) is a ticking bomb. The question is "when will that data end up all over the internet?" not if. Thanks for the advice. I'd be fine with starting with a webserver. Honestly, I don't have an issue spending time on this. This isn't a time sensitive project, it's more along the lines of "Something that'd be nice to have", and for me, it represents a chance to improve my skillset. I'd like to give it a serious shot before I hire a developer, especially if there's a chance I might have to modify it later on. If it becomes a time sensitive project or if the data becomes something that has to be protected, I'll look into hiring someone, but for now I want to give it my best shot on my own. The data is nothing sensitive or proprietary, so it ending up on the internet wouldn't be the end of the world either. I'd rather start learning now than when it is something highly proprietary.
|
# ? Apr 27, 2016 22:41 |
|
Adventure Pigeon posted:Thanks for the advice. I'd be fine with starting with a webserver. Yeah, make it a web application. If you dont want to waste too much time with the UI part of it, use bootstrap: http://getbootstrap.com/components/ Gives you a lot of elegant effective UI elements right out of the box. I would recommend using a framework for the server side stuff too., though I cant recommend you one if you mean to do it in java, as I never did any server side java. If you willing to try other languages, you might start with Django (Python) or Symfony (PHP)
|
# ? Apr 27, 2016 22:51 |
|
I recommend you use Spring Boot since that will get you a built in web server that will be easier to maintain than trying to setup it all up from scratch. Also you can use as much or as little of the Spring framework to glue together your bootstrap frontend and the database backend as you feel comfortable with.
|
# ? Apr 28, 2016 00:36 |
|
Janitor Prime posted:I recommend you use Spring Boot since that will get you a built in web server that will be easier to maintain than trying to setup it all up from scratch. Also you can use as much or as little of the Spring framework to glue together your bootstrap frontend and the database backend as you feel comfortable with. Looking at simpler web "microframeworks" like Spark (have used this in production) or Rapidoid could also be an option. They use modern Java features and are very easy to use with little-to-no boilerplate. Spring is usually not a tech stack that makes people happy in the long run, especially if they just want to get something simple up and running.
|
# ? Apr 28, 2016 00:50 |
|
|
# ? Jun 1, 2024 09:21 |
|
I'll give this a look, thanks for the advice. I was also wondering, given your statements about how allowing direct access to the database on the network, much less the web, is a bad idea, what is the best way to set up my database? I was already planning on having a system along the lines of Client <----> Server <----> Database, since I don't want anyone directly accessing the database, but I don't know all that much in terms of how to physically set that up.
|
# ? Apr 28, 2016 01:02 |