Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By jim829

Thread: Resources to practice classes, objects, constructors etc.

  1. #1
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Resources to practice classes, objects, constructors etc.

    Where can I find a lot of exercises (short programs to write to test and practice concepts) for the basics of classes, objects, constructors, methods, static and non-static methods and variables etc.

    I know what all of these are. I know the syntax to write these constructs, so it's not the syntax which I need to practice, but the concepts.

    But things like "You can not call a member function defined in a superclass from a static method in a subclass - example", "You should use static methods to get or set static variables - example" etc. seem to confuse me.

    I do understand the answers I get when I post a question in forums, but the problem is that I do not understand the mentioned topics fully.

    Actually, so far, any compiler error or statement which has the word "static" in it hasn't failed to confuse me. When I tell this to somebody, they always start telling me what static vs. instance methods/fields are, but I do know that. I have read about it.

    So I have decided to read this chapter and practice all the examples and I am doing that, but it does not cover all the hundreds of details associated with these concepts.

    So I want to write tons of small, minimalistic (especially this, so that I don't get confused with other things) programs so that (1) I understand all the details associated with these concepts (2)What I am reading, and the details associated with those topics, can sink into my brain, and the incorrect concepts get reset.


    Thank you in advance.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Resources to practice classes, objects, constructors etc.

    Quote Originally Posted by Zarah View Post
    "You should use static methods to get or set static variables - example" etc. seem to confuse me.
    The example mentioned above is my response to your earlier question. What I recommended is not any rule that I ever remember reading. Based on my own experience it just makes sense to me that you should not set static variables with instance methods. Others may disagree. But hiding implementation details by using getters and setters is just basic OO philosophy.

    But what you really want is probably a best practices guide. One that says something like always use getters and setters; prefer composition over inheritance; strive for immutability (if it can get the job done); program to an interface, etc. Best practices tend to be in the eyes of the beholder. But I have found the book "Effective Java Programming, 2nd Ed.", by Joshua Bloch very useful. It delves into the types of things you are talking about.

    If you write some programs and submit them to the forum with specific questions, I am certain you will get some guidance/suggestions.

    Regards,
    Jim
    Last edited by jim829; 06-01-2015 at 02:31 PM. Reason: grammar
    gimbal2 likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Zarah is offline Senior Member
    Join Date
    Mar 2014
    Posts
    286
    Rep Power
    6

    Default Re: Resources to practice classes, objects, constructors etc.

    But what you really want is probably a best practices guide.
    Firstly, thank you very much for your suggestion. I think a best practices guide will be more suitable when i understand these topics. I strongly feel that I need to write tons of small programs to let the concepts set in my brain.

    For example, if I want somebody to understand the for loop really well, I'll get them to write programs which print patterns like

    *
    **
    ***

    and

    *
    **
    ***
    **
    *
    etc., and I will make sure that the programs I make them write do not involve/require concepts like anonymous class or generics or concurrency (i.e. distractions), so that the person can focus on the loop only. That's why I say "minimalistic".

    So that's why I was looking for exercises which contains practice questions to write programs for understanding the mentioned concepts. I have found a couple of exercises on the internet, but they seem to be more focused on teaching the syntax. (example and example)

    Edit: Actually I am downloading the book, it IS probably a best practices guide that I need. Thank you.
    Last edited by Zarah; 06-04-2015 at 04:11 AM.

Similar Threads

  1. Classes and constructors
    By Qaqiaq in forum New To Java
    Replies: 4
    Last Post: 09-23-2014, 01:30 PM
  2. Best practice for persisting objects
    By blackb1rd in forum Advanced Java
    Replies: 1
    Last Post: 05-18-2014, 09:00 AM
  3. Replies: 4
    Last Post: 10-11-2011, 11:48 PM
  4. Constructors Objects and Classes
    By Tykk in forum New To Java
    Replies: 4
    Last Post: 10-10-2009, 11:31 PM
  5. [SOLVED] Best practice for creating test classes
    By mwildam in forum New To Java
    Replies: 3
    Last Post: 08-27-2008, 04:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •