bryant rob

Ranch Hand
+ Follow
since Jul 05, 2020
Cows and Likes
Cows
Total received
6
In last 30 days
0
Total given
0
Likes
Total received
3
Received in last 30 days
0
Total given
34
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by bryant rob

Thanks Stephan. I spent a little longer on ArrayList’s then I would have because I really liked experimenting with that topic.
1 week ago

Stephan van Hulst wrote:Yes, LinkedList is used only very rarely. The only time that a LinkedList will outperform an ArrayList is when you use an Iterator to insert multiple elements close to each other.



Stephan, For someone like myself learning java, I work full time (and work has kept me busy for the last 6-7 weeks) and have limited time throughout the week to spend on my java journey. I spent a couple of weeks learning arrays and arrayslists. Is linkedlists worth learning? How does someone like myself know when to spend more time on an item versus another if one will be used very rarely?
Thanks, Ron
1 week ago
Hey Paul and Campbell thanks for the reply. I will start paying closer attention to my method names. What about making my constructor protected accessible versus private?
1 month ago
I tried to edit the original post and totally forgot that I could not do this, and it created a new post today...sorry. (What was I thinking?? ) But, I wanted Campbell to see I changed the constructor access modifier to private.


Campbell,
After receiving my copy of Effective Java I have a couple of questions for you.

Campbell Ritchie wrote:Find yourself a copy of Effective Java by Joshua Bloch (page 5 in the 3rd edition). That tells you much more than I could tell you.
I am afraid neither of your implementations is ideal. In the first case the constructor should have private access, so you only create instances via the factory method (yes, you had that part right ). Neither of the methods in the second block is a factory method, and neither should therefore be called newCustomer. Call them addCustomerByName() or similar.


My createCustomer() method on Line 12 in the first block is the method that I was writing to be a factory method. According to the book this method would qualify as a factory method since it is a static method that returns an instance of the class. Am I correct with this?

With reference to the methods in the second block, you stated:

Campbell Ritchie wrote:and neither should therefore be called newCustomer. Call them addCustomerByName()


Why is this? Is it because I should not use the keyword new in a method name?

Lastly, for subclassing purposes, would it be safe to state that a constructor with protected access should be the access modifier to use?
1 month ago

bryant rob wrote:I am working on an exercise where I create bank branches, and customers of each branch. I have created two methods named newCustomer but only intend to use one of them: one calls the Customer constructor directly and the other calls the Customer.createCustomer method (which I created) to call the constructor (I believe this is called factory method). I prefer to call the createCustomer method because later if I decided to change something (don't know what as of now) I would just need to change the method of which I am calling and not affect the constructor.

Is one preferred over the other?  




1 month ago
Thanks Paul for The DailyWTF. I am always interested in that kind of reading. Just didn't know it existed.
2 months ago
Ok, so does experienced coders have issues with reading other coders code? When it comes to names, Junilu and Campbell never fail to tell me something about my names...and I am grateful. So I am always thinking of good names even though I did miss the branch name on this app. I changed it to bankBranch. But, if others have a hard time with the 90% crap out there how do supervisors and managers allow it to continue? Do they have the mindset as long as the code works lets get it into production and get paid?
2 months ago
Well, I definitely agree with Campbell and after his reply with regard to my "branch", I changed it to bankBranch. I like the idea of a 2 name variable. It helps me know what is what. But a lot of the code I read on the web that is actually code that is or has been in use is so hard to understand. I realize that I may not understand the flow of the code but when coders use letters and one word names I have to wonder how many people can understand it.

I am however still having a difficult time understanding what factory method is. It may be because I have not gotten far enough in my java studies but everything I read seems to be more advanced than where I am at.    
2 months ago
Campbell, I appreciate your feedback so much that I had to respond on almost everything you posted.

Campbell Ritchie wrote:Find yourself a copy of Effective Java by Joshua Bloch (page 5 in the 3rd edition). That tells you much more than I could tell you.


I have been reading a lot of good things about this book and put it on my "To get" list.

Campbell Ritchie wrote: In the first case the constructor should have private access, so you only create instances via the factory method (yes, you had that part right ). Once you do that I would buy the implementation as good.


I meant to change that and could kick myself for not doing so because I figured you would comment on that. But, I forgot to. As I am writing code I haven't quite gotten to the point where I know at first what should be public or private so I write my code. Then, I go back and analyze it to determine if I should make a method private. I try in the end to make as much private as possible especially my constructors.

Campbell Ritchie wrote:Do you actually want to start off the list of transactions with the opening balance on a new object? Why are you using doubles or Doubles, which are both unsuitable for precise arithmetic?


The way I see it is when a new customer opens an account they must have an initial amount(beginning balance) so that it is I agree with my code, but I am open to your suggestions here. As far as the double/Double, I realize that a double is not accurate for banking purposes and I should use a data type like big decimal but I haven't got to that point in java so I am using what I know.

Campbell Ritchie wrote:Neither of the methods in the second block is a factory method, and neither should therefore be called newCustomer. Call them addCustomerByName() or similar.


I like your method name better than mine. I have read about factory methods and I thought that by creating the createCustomer method and then calling the constructor, instead of calling the constructor directly I was in utilizing a factory method. So, I don't quite understand the difference but will go back and read some more. I just know that I would rather create a method to call a constructor rather than calling a constructor directly if possible. The main reason is that I believe I always want my constructor to be declared private so as to restrict its access.

Campbell Ritchie wrote:Why don't you write a contains() method? Is there a suitable method ready‑made in the List interface? (No, I don't think there is.)


I haven't got there yet. But, I am almost there. With my day job, I am a little behind on my studies but should be to the that section within a couple of weeks...hopefully sooner.

Campbell Ritchie wrote:Maybe you shouldn't call the class Branch because you can't tell whether that means branch of a bank or branch of a tree or branch of a railway line.


You are right here. I do plan on going back and changing some names especially since I am not a big fan of one name classes and methods. You did have me rolling on the floor laughing with this one...tree or railway line.

Campbell Ritchie wrote:Don't repeat the actual type parameter: write new ArrayList<>();


Thanks for this tidbit. I was wondering why IntelliJ skips over the <> and moves directly to the ();. Now I know, because it does not expect me to repeat the type parameter and type in <Double>. I have to laugh sometimes because when I start to think "how come IntelliJ does or doesn't do something like place my cursor in a specific position, I should know there obviously is a reason.
2 months ago
I am working on an exercise where I create bank branches, and customers of each branch. I have created two methods named newCustomer but only intend to use one of them: one calls the Customer constructor directly and the other calls the Customer.createCustomer method (which I created) to call the constructor (I believe this is called factory method). I prefer to call the createCustomer method because later if I decided to change something (don't know what as of now) I would just need to change the method of which I am calling and not affect the constructor.

Is one preferred over the other?  




2 months ago
Thank you Carey and Stephan for the explanations. It definitely makes sense and peaked my interest to learn more on iterators and get.

Campbell, you are correct as you always are.  I haven't made it to iterators yet. What I usually do while going through this Udemy course is when I get to a new section, like I am on Arrays and ArrayLists I will read the Oracle tutorials on the topic and this is where I usually write notes (on my paper . I saw where the enhanced for loop was preferred but I just figure that eventually the course will get to that specific topic (which normally it does cover what is mentioned in the tutorial), and if it doesn't I have it written in my notes and will go back at some time in the future and research it.  
2 months ago
After reading Oracle's tutorial and learning that the enhanced version of the for loop is the form designed for iteration through Collections and arrays, why would the way I used the get.Name not be recommended or accepted as proper code form when Oracle states " We recommend using this form of the for statement instead of the general form whenever possible"  when the way I used it in the general form of the for loop is clearly easy for anyone to read and understand the purpose of the code, and it gets the job done? I am not trying to be a rebel here, just understand why I should not do it. Is it less efficient?

2 months ago
Thanks Ron, I'll take any and all sites I can get for extra practice.
Campbell, I think I remember seeing a post of yours a while back where you mention another site for practice along with codingbat.com. If I am correct, can you please post that here since I can't seem to find it?