Joe Bishara

Ranch Hand
+ Follow
since Nov 16, 2014
Cows and Likes
Cows
Total received
17
In last 30 days
0
Total given
0
Likes
Total received
59
Received in last 30 days
1
Total given
54
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Joe Bishara

Richard Hayward wrote:I had to change line 5 to "$VALUES" instead of "ENUM$VALUES" for it to work.


Some compilers generate this code

private static final CoffeeSize $VALUES[];

Others generate this code

private static final CoffeeSize ENUM$VALUES[];

This is fine since the field is private i.e. it is not designed to be directly accessed publicly.

Ganesh Patekar wrote:But here Strings, Literally by Corey McGlone says...


In your previous post,

Ganesh Patekar wrote:Does that mean "JAVA" has been GC?


you asked if the String literal "JAVA" has been garbage collected and the answer to that question is that it has not. It is still in the heap. String literals are never eligible for GC while a program is running because they are always referenced. The point I was making is that when using a tool like jhat to analyze the heap, you cannot tell exactly when an object that is eligible for GC will be garbage collected. You cannot make an object eligible for GC and expect that it will immediately be garbage collected.
4 years ago

Ganesh Patekar wrote:Will you please tell me exactly where you found that link I mean under which titles or subtitles? I searched a lot for that but couldn't found so tried with VisulVm.


I used Stephan's post as a guide.

Stephan van Hulst wrote:There's a link to a page that will show you instance counts of classes (including platform classes). Then you click the link to String instances. Then the password you entered will be among the instances listed, if it hasn't been garbage collected yet.


4 years ago

Ganesh Patekar wrote:Does that mean "JAVA" has been GC?


Using jhat (not VisualVm), I found the String object in the heap dump even after setting its reference to null.

P.S.
Setting an object's reference to null makes the object eligible for GC (if it is no longer referenced); however there is no guarantee that an object that is eligible for garbage collection will be garbage collected because you never know when the garbage collector will run.
4 years ago
This mistake has been noted in the errata.

Head First Java Page 191 wrote:Method overloading is nothing more than having two methods with the same name but different argument lists. Period. There’s no polymorphism involved with overloaded methods!

Tim Cooke wrote:Our Wiki pages are editable by all...


I can't find an edit button.

If Wiki pages are really editable by all, I hope that you have set up a system to rollback bad edits.
4 years ago
I thought I'd point out certain corrections that should be made to this Wiki

CORRECTION 1

The ability to post in the Rattlesnake Pit or to be given extra flexibility in editing posts...


The Wiki says nothing about who has extra flexibility in editing posts.

CORRECTION 2

Additionally, cows enable->s<- many privileges->,<- that ha->s<- been mentioned ->by<- this topic.


Change this to

Additionally, cows enable many privileges that have been mentioned in this topic.



CORRECTION 3

Earning cows ->are<- cool, so one should lead to the other right?


Change this to

Earning cows is cool, so one should lead to the other right?


OR

Cows are cool, so one should lead to the other right?



4 years ago
You may declare static methods in an interface if these methods are associated with classes that implement the interface. These methods are utility methods and an interface is a more appropriate place to define utility methods as opposed to utility classes, for example, all of the static methods defined in the java.util.Collections utility class could have been defined in the java.util.Collection interface.

You may declare default methods in an interface if these methods are associated with instances of classes that implement the interface. These methods allow you to evolve an interface i.e. you can add new methods to an interface without breaking classes that already implement the interface. In pre-Java 8 code, a non-abstract class that implements an interface is forced to implement every method in the interface. In Java 8 code, a non-abstract class that implements an interface is not forced to implement every method in the interface since it can inherit the interface’s default methods without being forced to provide an implementation.

Andrey Belkin wrote:but this source DOES compile.


No, the source code does not compile

The source code is
The book says

What import could we use if we want the java.util.Date version?


If we try this import
the source code does not compile

However, if we try this import
the source code does compile
Not all expressions are statements. This tutorial discusses the differences between an expression and a statement.

Vidya sagari wrote:SO Do you mean that the answer is actually 4?


No. The answer to the original question is 2. At the line containing the //doStuff comment, the 2 objects that are eligible for GC are:
  • the object referenced by c1 (a CardBoard object)
  • the object referenced by c1.Story (a Short object)

  • Vidya sagari wrote:I don't understand where and how a Short object is created. can you please elaborate on that?


    The source code shows that every CardBoard object has-a Short object.
    4 years ago
    I prefer to stick with the convention adopted by my team so that everyone is on the same page.
    4 years ago
    You’re welcome  
    4 years ago

    Ganish Patil wrote:At line code object whose reference was stored in reference variable c1 will be eligible for GC.


    I agree with this

    Ganish Patil wrote:...at line where comment //doStuff is written, an object whose reference is stored in reference variable c2 will also be eligible for GC


    I don't agree with this.

    The program creates 4 objects:
  • the object referenced by c1 (a CardBoard object)
  • the object referenced by c1.Story (a Short object)
  • the object referenced by c2 (a CardBoard object)
  • the object referenced by c2.Story (a Short object)

  • At line //doStuff, the 2 objects that are eligible for GC are:
  • the object referenced by c1 (a CardBoard object) - because c1 is null
  • the object referenced by c1.Story (a Short object) - due to island of isolation

  • Ganish Patil wrote:I think I should have said at line 15 where the main method ends


    At line 15 where the main method ends, 4 objects are eligible for GC.
    4 years ago
    What you're saying makes no sense to me either but let's agree to disagree.
    4 years ago