• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Random questions about constructors, abstract, etc.

 
Ranch Hand
Posts: 37
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few questions I, a newb, have just to clarify a few things I'm studying in these few chapters for school.
---

In a hierarchy of subclasses, when you use "super" in the constructor, which constructor does it actually call? The superclass immediately above, or the one all the way at the top?

What would be the point of using "this" in the definition of a constructor, just to call a different constructor of the same class? It seems unnecessary, but that is just because I'm not fully understanding it I'm sure?
Like:


Can anyone tell me what the importance is of creating a copy constructor? A clone instructor? What the difference is? For which kind of circumstances each one "specializes" in? My book doesn't really go into depth about it, but my professor is making it seem like it's incredibly important (each for their own purposes...) Or perhaps have a good source where I can find some information in-depth on this subject?

Since abstract classes can't be instantiated, are they mainly/only used as a blueprint for subclasses? (Also, not sure I can grasp why we should create a variable, type abstract, to refer to any instances of its subclasses. Can anyone show me an example?)

Sorry for so many questions. There were so many pages to read, just need a few things cleared up. They seem like they're a lot simpler to answer than the other things I'm reading, but I don't think they're explaining it well enough or showing examples that are easy to understand.

Thanks.







 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

In a hierarchy of subclasses, when you use "super" in the constructor, which constructor does it actually call? The superclass immediately above, or the one all the way at the top?


Just the one immediately above. This is why it's important that all the classes in the hierarchy call super except the very top.

What would be the point of using "this" in the definition of a constructor


It makes things cleaner and saves code.



Since abstract classes can't be instantiated, are they mainly/only used as a blueprint for subclasses?


You *have* to implement an abstract class to use it. They might be "blueprints" or partial implementations of an Interface.

Also, not sure I can grasp why we should create a variable, type abstract...


There are no abstract variables in Java.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Danny Treart wrote: . . .
In a hierarchy of subclasses, when you use "super" in the constructor, which constructor does it actually call? The superclass immediately above, or the one all the way at the top?

The good news is, it is all in the Java Language Specification (=JLS). The bad news is, the JLS can be really difficult to understand. Simply: immediately above, and that calls super immediately above, etc. until you get to java.lang.Object.

What would be the point of using "this" in the definition of a constructor, just to call a different constructor of the same class? It seems unnecessary, but that is just because I'm not fully understanding it I'm sure? . . .

It allows you to call new Foo() and that sets default values. If you write the assignments in both constructors, you are repeating yourself.


Can anyone tell me what the importance is of creating a copy constructor? A clone instructor? . . .

What is a clone instructor? A copy constructor allows an object to duplicate itself easily. Look at this thread. Find a copy of Effective Java™ by Joshua Bloch and it tells you about copying objects. Also that the clone method is poor design.


Since abstract classes can't be instantiated, are they mainly/only used as a blueprint for subclasses? . . .

Mainly as a blueprint for subclasses, yes. They can be instantiated, but you need a bit of fiddling to convert them to anonymous classes.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the clone method is poor design.


I think the idea was that a copy constructor makes a shallow copy (one level only) and a clone would make a deep copy (copy any Objects all the way down). If clone() is a deep copy, it's a bad idea because that means an object (the one with the clone) would need to know about structure of another object, and that's a no-no.
 
Danny Treart
Ranch Hand
Posts: 37
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:What is a clone instructor?


Lol! Sorry, it's been a long day. I read it after I typed it, but I thought I went back and fixed it >.< ....but seriously, what is a clone instructor?! o.O

I'll pick up a copy of Effective Java tomorrow. So far I'm reading two Java books already, but I like comparing and combining information from different sources. I definitely need to sort my copy and clone stuff.

 
Marshal
Posts: 4499
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Danny Treart wrote:...but seriously, what is a clone instructor?! o.O



According to Wookiepedia, the Clone Instructors were Mandalorian mercenaries recruited by Jango Fett to train the Clone Army.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote: . . .
According to Wookiepedia, the Clone Instructors . . .



You may find Effective Java™ difficult to read. If you do, read the bits you don't understand and leave the rest until next year. Chances are, you will understand a lot more then.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote: . . .
I think the idea was that a copy constructor makes a shallow copy . . . and a clone would make a deep copy . . .

That sounds incorrect. The clone() method returns a shallow clone by default but can be overridden to return a deep clone. You also have to implement Cloneable.
A copy constructor takes a parameter of the same type… and therefore “knows” all about the structure of its parameter and can make its object into a deep copy.
 
Danny Treart
Ranch Hand
Posts: 37
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

Danny Treart wrote:...but seriously, what is a clone instructor?! o.O



According to Wookiepedia, the Clone Instructors were Mandalorian mercenaries recruited by Jango Fett to train the Clone Army.



Hahahahaha.
---

Well, I just finished some work a little bit ago, and I'm going to pick that book up tonight. When you say parts of it may be a little difficult for me, it kind of got me thinking a little bit. I plan on transferring somewhere to get my 4-year degree after I finish this associate's.. Assuming you guys are professionals in the industry, at what point would I be ready for an entry-level position as a Java (or software) developer, etc? I'm planning on picking up more languages eventually, and I want to learn about databases, etc. At what point should I feel comfortable, like, "Ok, I know a decent amount I can try setting up some interviews now." As you can tell by my questions, I'm still a ways off but --.

(Also, the reason I ask is because I only have 8 classes left, and I'm still feeling like eh-- I wouldn't be comfortable doing a professional interview).

Thanks.
Danny
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know from personal experience that it's hard to get even an entry level job with just an AA and book learning -- and I had 25 years of programming under my belt (but not in Java). But I did find a company that was will to train me (without pay) and then hire me, but it took a while. If you can wait for a BS that would be best IMO.
 
Danny Treart
Ranch Hand
Posts: 37
Netbeans IDE Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am 27, and a little late to college unfortunately. Right after high school I kind of fell into a decent job (or what I thought was my "career") and I thought I was set. I was able to buy a house, cars, etc., but it all kind of went downhill when the company moved. I'm getting a little older now, and a career change at this point seems less than ideal, but I'm still going to work towards a bachelor's even if it takes me into my 30s. At least this is something I really enjoy learning about and doing, despite the fact I still have a long way to go.

Thanks for the feedback.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The later parts of this discussion might fit well into our Jobs forum, so I shall duplicate the discussion there.
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic