J Solomon

Ranch Hand
+ Follow
since Oct 08, 2012
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by J Solomon

What about the following example..........




What gets printed:


Before....
e.name is: something
s.name is: something
After....
e.name is: CHANGED
s.name is: CHANGED


4 years ago



What I would expect to print:


Before...
x is: 10
y is: 10
After re-assigning x
x is: 20
y is: 20




What actually prints:


Before...
x is: 10
y is: 10
After re-assigning x
x is: 20
y is: 10




I'm assuming that when you declare y and assign it to x, you are actually copying the actual value that lives at location aliased by x. Is this a pass by value as opposed to pass by reference?
Can someone please explain this one to me?

Thanks.
4 years ago

Bear Bibeault wrote:I'd feel that adding extends Object is too far on the spectrum for even me, but I do add this. to the front of all references to member variables, so I'm not one to talk!



I almost always add this. to the front of all member vars, makes code much easier to read, especially if your formal parameters are going to shadow your member vars.
4 years ago
I feel most languages today implement an implicit return.........Python, Ruby, even Groovy has an implicit return and it's built on top of Java.
4 years ago
Does Java not have an implicit return? I would expect if I write a function with return type 'int' and within that function I call another function that returns 'int', then I would not have to explicitly declare 'return'. When I test this theory out, I see that I am wrong:



Javac output:
Test.java:13: error: missing return statement
}
^
1 error


So you must define bar() as such:



Am I missing something here, I would assume that since bar() is calling foo() which has an explicit 'return', then you would not have to explicitly declare return within bar(), or is there no implicit return in Java?
4 years ago
Thank you for all the quick replies, much appreciated. Now that I see the wrong in my ways, can someone please explain how you would possibly ever use an object that is initialized with a constructor that throws an Exception. If your constructor throws an exception, then whenever you try to instantiate an instance of that object, you'll have to wrap it in a try/catch. That reference to that object will only be in scope while you are inside the try portion of the try/catch; seems pretty worthless.

BUT............. i guess as long as you allocate a var to hold whatever it is that you are trying to instantiate outside of the try and just instantiate and assign in the loop, then you are good.

Example:


Right?
4 years ago


Java 1.8 compiler output:
MyList.java:45: error: cannot find symbol
m.add(1);
^
symbol: variable m
location: class MyList<E>
where E is a type-variable:
E extends Object declared in class MyList
1 error



I am trying to define a class MyList, which i just a wrapper around an ArrayList, no real purpose, just for the sake of learning Generics. Idea here is that I create a parameterized class, MyList<E>, which holds a parameterized instance var of type List<E>. I have an add method which adds an element of type E to the List<E>. If I create an instance of MyList, call it 'm', for some reason when I try to call a method on that instance the compiler complains that 'm' cannot be found. Any help would be greatly appreciated.

Thanks!
4 years ago


Output:
1 2 3 4 5 %

Just wondering if anyone else hit this, looks like when you compile and run on mac, the EOL char is tacked on the end of the output. Do not see this when I compile and run on just about any other machine.

Here is the output of 'g++ --version':


Anyone have any explanation for this one? Thanks in advance.
5 years ago
I'm currently running Groovy 1.8.8 on Java 1.6.0_16. I have a grails project that I'm trying to make simple get requests to and HTTPBuilder looks like just the tool for this type of job. I've hit a brick wall with this and I'm not sure where to go from here. I've used Grape to install the http-builder module via the following command:



Looks like Grape picks up the dependencies and installs everything:



Now I would assume that if i fired up a groovy console, I would be able to import any of these classes, but I'm not able to:


but I get the following error:


Am I missing something here?

5 years ago
New to grails here and I'm looking to model a one-to-many relationship, but I only want creates and updates to work in one direction.



So what I'm looking for is when I create a new environment, I don't want to be able to add PropertiesFiles to it, since you cannot have a properties file without first having an Environment (kinda like the whole chicken and egg thing). When I create a new Properties file, you should have to associate it with a pre-existing Environment. I hope this makes sense. Thanks for the help in advance.

5 years ago
Thanks for input.
5 years ago
I currently have a grails project running in tomcat that acts as a container for a bunch of various information. I would like to build a client app (using java) that is capable of querying the grails project for particular information, based on parameters passed to it. I'm curious as to the best approach for something like this. My first inclination is to build the client in such a way that it just directly querys the DB on the back end of the grails project (the grails project will then just be used as an entry/modification method for the data). I was wondering if there is a better approach, maybe building a particular URI and then sending a GET request to the URI (this seems like a better approach as you only have one entry point then and you are not mucking directly with the DB). Just looking for some input from anyone who has worked on anything similar. Thanks in advance.
5 years ago
I currently have a grails project running in tomcat that acts as a container for a bunch of various information. I would like to build a client app (using java) that is capable of querying the grails project for particular information, based on parameters passed to it. I'm curious as to the best approach for something like this. My first inclination is to build the client in such a way that it just directly querys the DB on the back end of the grails project (the grails project will then just be used as an entry/modification method for the data). I was wondering if there is a better approach, maybe building a particular URI and then sending a GET request to the URI (this seems like a better approach as you only have one entry point then and you are not mucking directly with the DB). Just looking for some input from anyone who has worked on anything similar. Thanks in advance.
5 years ago

Steve Luke wrote:

J Solomon wrote:Figured this out, it was my own stupidity. Thanks again for all the help.


Can you post the fix so we can all learn from it please?



The issue was with my input, I should have normalized it so I didn't hit issues with the "if statement".
5 years ago
Figured this out, it was my own stupidity. Thanks again for all the help.
5 years ago