Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Dreke Droga

Greenhorn
+ Follow
since Oct 10, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
14
Given in last 30 days
4
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Dreke Droga

Campbell Ritchie wrote:
Which book are you using?



Do you have any suggestions for me? I'm beginner for coding.
1 week ago

Campbell Ritchie wrote:Which book are you using?


I don't have any book. I have list of topics gathered in order to learn. I downloaded it from some site. And then for the topic I saw youtube video or tutorialpoint etc. I had pdf of Java by Herbert Schildt. I read through couple of chapters and lost interest. Not that it's fault of book. But I found it difficult understand with my minimal english skills and in bonus - I'm a slow learner Please let me know if you have suggestions.
2 weeks ago

Campbell Ritchie wrote:It is best to reduce mutability as much as possible.


Took notes!

Campbell Ritchie wrote: Also, setXXX() and getXXX() methods may break encapsulation and therefore violate some of the principles of object‑orientation. (Old thread about setXXX() methods.)[/list]


  • I'm still learning on objects and honestly, I gave a pass on Abstraction and encapsulation. Both seemed confusing. I felt both are same. But today I gave another reading, and I still feel both are same.  

    Campbell Ritchie wrote:2: If you allow the field to retain its default value, you will have your object in an inconsistent state; there is no such thing a a circle with radius 0. You might have radius 0.000...0001 but not 0. Remember there is no way to “force” your users to call any setXXX() methods.


    I couldn't find on references on leaving object values to defaults will leave object in inconsistent state. I would like to know more about this. Can you please give me any reference to this subject area?

    Campbell Ritchie wrote:Don't call the method Calculate() with a capital C. Say calculateArea() or similar instead.


    Ah.. the basics said this. I forgot. Below code after changing.



    But there's confusion. I think I need to start reading objects from concepts from beginning again.
    2 weeks ago

    Campbell Ritchie wrote:Why does its area always come out as 0?



    method action is not present. default value is zero for the data field radius. Calculate method is taking int value. I should make it this way.

    2 weeks ago
    Can you please review my program? Below is the Question. Please Suggest me ny changes and especially the class design.

    Design a class named Time. The class contains:
    ■■ The data fields hour, minute, and second that represent a time.
    ■■ A no-arg constructor that creates a Time object for the current time. (The
    values of the data fields will represent the current time.)
    ■■ A constructor that constructs a Time object with a specified elapsed time
    since midnight, January 1, 1970, in milliseconds. (The values of the data
    fields will represent this time.)
    ■ A constructor that constructs a Time object with the specified hour, minute,
    and second.
    ■ Three getter methods for the data fields hour, minute, and second,
    respectively.
    ■ A method named setTime(long elapseTime) that sets a new time for the
    object using the elapsed time. For example, if the elapsed time is 555550000
    milliseconds, the hour is 10, the minute is 19, and the second is 10.

    Write a test program that creates three Time objects (using new Time(), new
    Time(555550000), and new Time(5, 23, 55)) and displays their hour,
    minute, and second.
    (Hint: The first two constructors will extract the hour, minute, and second
    from the elapsed time. For the no-arg constructor, the current time can be
    obtained using System.currentTimeMillis(). Assume the time is in GMT.)



    2 weeks ago

    Campbell Ritchie wrote:

    I can see two design errors in your Circle class. Please tell me what they are.



    The "public double PI = 3.14;" should be "public static  final double". Value is constant and should not be changed by another object from Circle. So static final is needed. "METERS_PER_INCH" constant is redundant. Please let me know if there are more design errors.

    I moved the Circle object initialization outside main method. The object variable was not accessible until I made the object variable static at declaration.
    2 weeks ago



    I thought static method cannot access instance variables/methods.

    In circle class PI is instance variable and in the "public static void main", main method, I created Object of circle and able to modify instance variable. Where did my understanding went wrong?
    2 weeks ago

    Paul Clapham wrote:There's a concept called "N-and-a-half loop" which means that a loop will be executed N and a half times. This situation occurs when the loop looks like this:



    It happens fairly often, and that's what Campbell has posted there. Only in the posted code, the "initialize" part is score = myScanner.nextInt() and the break-out test is score < 0. So the "initialize" and "break out" parts can be combined and put into the loop header.

    But sometimes the "initialize" part is too complicated to do that and then the loop looks like this:



    You don't see this very often, though, because there's somewhat of a prejudice against breaking out of the middle of a code block which dates back a couple of decades or so, back to when "structured programming" was the new big thing. So if the "initialize" part is too complex to roll into the loop header, people will make it into a method and then put that into the loop header.





    Thank you for explanation. I understood your code. I don't know Structural programming. Although I didn't grasp what you said completely, I will go through this again. I will start learning Structural programming along with java now.
    2 months ago
    Thank you. This is definitely better code. May I please know how you analyzed your algorithm inorder to come to this approach?
    2 months ago

    Paul Clapham wrote:I put your code fragments into the "code" tags. Please do that in future so that it's easier to discuss code fragments. (Select the code fragment in your post and click on the "Code" button at the top of the box.)

    Anyway: Look at line 3 in your second code fragment. Notice that you don't have the same thing in the first code fragment, so the two aren't equivalent.



    Thank you for pointing out. I didn't notice that. Even no compiler error (Obviously). When I changed it, it stopped with one iteration while we want it to stop iteration only if input is -1. So I wrote below code.



    This worked.

    Thanks again.
    2 months ago
    Hello, Please point me mistake in my for loop.



    I thought this is equivalent to below while loop:

    2 months ago

    Tim Moores wrote:It will not be the same Activity object, because Android does not know beforehand which activity will be called as the result of a startActivity call (that can change dynamically at runtime). This is easy to test by comparing the references of the different activity objects.

    There are other circumstances under which an existing Activity object might get reused; the Activity Lifecycle documentation talks about that.



    Thank you. I will print the references and verify. You said "Activity object might get reused". Can you please give me an example?

    2 months ago

    Norm Radder wrote:

    will it be same Activity B object that got called previously or a new object


    Why do you need to know that?  I imagine the old object is collected and a new one created as needed.



    Well, I may not be able to give you why I need to know, but I need to concretely understand how the objects are behaving. Any reference to article or documentation in this subject area in order to understand will be greatly helpful.

    Thank you,
    Dreke
    2 months ago
    I'm not passing the Activity B reference. Below is the method signature.

    public void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
     switch(requestCode) {
         if (resultCode == Activity.RESULT_OK) {
           String returnValue = data.getStringExtra("ab");
    2 months ago
    With activityResult, yes
    2 months ago