Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!

Sam Peterson

Greenhorn
+ Follow
since Sep 26, 2019
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
1
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 Sam Peterson

After much experimenting, I think I have got an understanding of numeric promotion rules. Please let me know if there are any misunderstandings in the code comments:

With all of that, I think I have simplified numeric promotion rules down to two simple facts:

1.) anytime you have a data type smaller than an integer on the left-hand side of the assignment operator, you need to either provide a cast or use a compound assignment operator.

2.) anytime you have an operand variable on the right-hand side of the assinment operator whose data type is larger than the data type of the operand variable on the left-hand side of the assignment operator, you get a conversion error.
3 days ago
Of the code below, line 10 prints out "40", and line 14 prints out "-5":

Neither 5 or 45 is anywhere near out of maximum or minimum bounds for an integer, so overflow and underflow can't be the issue.

So what causes line 14 to print out "-5"?
5 days ago
Even stranger yet then:

Am I missing an import statement or something?
5 days ago
I'm getting and out of range error for:

I don't understand why that is, because 2^63 - 1 is over 9 Quintillion, so 192 Quadrillion shouldn't be a problem, unless the following image is wrong:
5 days ago
Given the following code:

The output on lines 26 and 29 is the same (see the code comments on lines 6, 7, 15, and 16 to see the effects that the hightest e+number has on that output).
Since the output is the same, I don't see what strictfp double method does differently than the regular double method. What am I missing?
5 days ago
For the sake of number promotion testing, it would be very helpful if you could print out the data type of a value. I wasn't the first one to think about this idea, but does anybody know the answer?
5 days ago
I'm working on a spring boot project (following this tutorial). Consequently, I'm relying on the Apache Derby database to store my data.
When I tried running my spring boot application, I got this error:

***************************
APPLICATION FAILED TO START
***************************

Description:

Field TR in sam.springboot.service.TopicService required a bean of type 'sam.springboot.dao.TopicRepo' that could not be found.

The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'sam.springboot.dao.TopicRepo' in your configuration.



Here is my code:

CourseAPIdatabaseApp.java


TopicRepo.java


TopicService.java


TopicController.java


application.properties


pom.xml


What am I missing?

EDIT: here is my project structure by the way:
1 week ago
If you go to 1:44 in the video Spring Boot Quick Start 27 - Adding Spring Data JPA, he is adding dependencies without having to manually type them in the pom.xml file.

My question is, is it possible to go to that menu after you close it and your project is already created?
1 week ago
The first rule of Java Numeric Promotion says:
"If two values have different data types, Java will automatically promote one of the values to the larger of the two data types".

However, I got some unexpected output from the code:

Promoting b, which is: 6.78

Both variables appear to be assigned to the same value, 6.78. So why would the float be larger than the double, since a float data type is 4 bytes and a double data type is 8 bytes? What happened?
1 week ago
Junilu, your rabbit zoo analogy finally cleared the confusion about the solutions from the answer key:

Sam Peterson wrote:

The correct choices in the answer key are:

B. The Rabbit object from line 3 is first eligible for garbage collection immediately following line 8.

D. The Rabbit object from line 4 is first eligible for garbage collection immediately following line 9.


Following your analogy, I think I finally got the drawing correct:

[if place inline fails, the image that's supposed to be here is RabbitGCsolved.jpeg]

However, due to what you said here:

Junilu Lacar wrote:

Sam Peterson wrote:So does the garbage collector remove memory addresses, objects or both?


The garbage collector frees up memory that was used by an object, so the memory can be used by something else. I'm not sure what you mean by "remove memory addresses" but taken at face value, memory addresses cannot be removed.


And here:

Junilu Lacar wrote:
The floor is the memory space that objects can occupy. Your mom never removes sections of the floor, does she? Likewise, the GC will never "remove memory addresses".


I'm a little confused to why you brought this up:

Junilu Lacar wrote:
Your next question might logically be: Who cleans up the reference variables then?


Are reference variables literally temporary physical placeholders in memory space on the computer hard disk?

Also, since we still have the R3 object that's not eligible for garbage collection at the end of this program, what is the lifespan of that object and the two reference variable after the program finishes?

Also, whether or not we write code that stores that object and it's attributes to a database, would doing or not doing that also affect the lifespan of the object R3 and the reference variable two?
1 week ago

Koen Ursem wrote:I usually think about variables in java as pointers.

So :
Rabbit one = memory point 1008 = new instance object of Rabbit1Data.
When you then then get on line 5,
Rabbit three = one; That actually says, Rabbit three is the same memory addres of pointer Rabbit one. (It actually copys the pointing value of one, and it is not really referring to one at all after it has copied the adres).

So now both variable one and three reference to memory point 1008. (And java will check from time to time if there are any variables pointing to this same memory adress).

Now as long as there is a pointer(variable) to point 1008, Rabbit1Data should not be garbage collected.



So does the garbage collector remove memory addresses, objects or both? If it removes objects, then object R1 should have already been eligible for garbage collection on line 6 (contrary to the answer key saying that it's eligible after line 8):
2 weeks ago

Junilu Lacar wrote:

Sam Peterson wrote:On line 6, what is one referencing? Then how does four magically reference R1 on line 7 if you're assigning what one references to it?


One of the answers from the answer key says, "The Rabbit object from line 3 is first eligible for garbage collection immediately following line 8."

What does the context 'immediately following line 8' mean? Does that mean all of the lines after or before line 8?

2 weeks ago

Koen Ursem wrote:
So now both variable one and three reference to memory point 1008. (And java will check from time to time if there are any variables pointing to this same memory adress).

Now as long as there is a pointer(variable) to point 1008, Rabbit1Data should not be garbage collected.


Yes, but after the last pointer activity on line 10, the R1 object still has four still pointing to it, two is now pointing to an R3 object, and object R2 has nothing pointing to it. So in reality, isn't R2 the only 'object' eligible for garbage collection? And will it automatically be collected in this case, simply because it is 'eligible' for garbage collection?
2 weeks ago
The finalize method may be defined in the Main class, but it's also not called in the main method:

The function call is commented out on line 9, and yet I still get the output "Roar!". How is that possible?

Also, here's what the book (Jeanne Boyarsky and Scott Selikoff, OCA Java SE 8 Programmer I Study Guide, Chapter 1 review questions answer key, page 336) says about the garbage collector:
"Calling System.gc() suggest that Java might wish to run the garbage collector. Java is free to ignore the request. The finalize() method runs if an object attempts to be garbage collected."

I'm having a hard time understanding the sovereignty of the garbage collector. I thought the garbage collector was supposed to be automatic at the end of a program in Java, or is it?

Campbell Ritchie wrote:

Sam Peterson wrote:. . .  I have no idea what to draw for line 10: . . .

What about two→→→R3? It is a new object, so it isn't R2.


What about that one object created on line 3? Do you think it became eligible for garbage collection on line 6 or line 8?
2 weeks ago