Results 1 to 9 of 9
Thread: Learn 2 method?!
- 08-21-2012, 03:34 PM #1
Member
- Join Date
- Jul 2012
- Location
- Norway
- Posts
- 29
- Rep Power
- 0
Learn 2 method?!
Hey guys, as I'm currently playing around with JComponents and stuff, I'm still left with this uncertainty about method headers and classes. It's kinda uncomfortable, because I feel like I'm moving on to the next steps without having fully understood the more basic stuff. Could someone please explain the following things?:
1. What does it mean that void doesn't "return anything" (I'm a bit uncertain what "return" means in the full sense of the word)? Is a void method just some auto-process going on and why? Aren't all processes intercommunicating? Or is it just that it doesn't store anything in memory?
2. What exactly is a static method that a non-static isn't? I know what static means etymologically, but how to describe it computationally?
3. I've seen examples where neither public nor private is being used, just "void method/Class", "abstract method/Class" or "method/Class" or similar? Is this even proper code and, if so, why aren't they specifying their types?
4. Is a superclass more or less abstract than a subclass? I've heard conflicted wordings, maybe those guys just misspoke. I'm assuming that JComponent is a more primitive (less abstract) superclass of JPanel, for instance. Is this correct? Do classes/subclasses extend superclasses, or is it opposite? (Also, I'm assuming that a subclass is just what you call any class that extends another class.)
Would really be nice to see some links or even examples of these different method types. I'm still waiting to get the money to buy Effective Java and similar books that I assume will answer these appropriately. I'm sure I'm just lost in translation or something, or otherwise seeing a problem that doesn't exist. But it's there, nonetheless.
Thanks in advance.Last edited by DrMadolite; 08-21-2012 at 03:46 PM.
May the Newtonian physics be with you.
- 08-21-2012, 03:48 PM #2
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Re: Learn 2 method?!
Here are some links for your questions:
1) Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
2)What's the difference between static and non-static methods (java)? - Yahoo! Answers
3)Lesson: Classes and Objects (The Java™ Tutorials > Learning the Java Language)
- 08-21-2012, 04:03 PM #3
Member
- Join Date
- Jul 2012
- Location
- Norway
- Posts
- 29
- Rep Power
- 0
Re: Learn 2 method?!
Thanks for the links, and I guess that came rather fast so I guess I should get a little better using resources too
. I guess I'm so fixed on some bad Google sources ending up with crappy links that don't explain thing very well that, in my frustration, I forget about the good ones hehe.
I guess I posted the 4th question after you started replying, but it's ok, I'll see if the links can redirect me to this as well. Thanks again.
====================
The way I understand these things are this:
1. A void method still has values inside it and does return a process to the JVM, but it just doesn't return a value to any parent method's process.
1b. Returning a class or Interface is similar, only more abstract in the sense that the entire code is either used or not used.
2. Non-static constructors creates an individual instance of a class, while static constructors gets the class itself.
3. n/a I'll go through all of this, I think.
4. I'm right about superclasses. They are extended by a class that is then defined as its subclass.
Correct?Last edited by DrMadolite; 08-21-2012 at 04:15 PM.
May the Newtonian physics be with you.
- 08-21-2012, 04:05 PM #4
Member
- Join Date
- Jul 2012
- Posts
- 55
- Rep Power
- 0
Re: Learn 2 method?!
yea that question wasn't there when i was posting but here is a good link for super classes and objects
Using the Keyword super (The Java™ Tutorials > Learning the Java Language > Interfaces and Inheritance)
the docs.oracle.com pages will help you a lot if you just read through the tutorials.
- 08-21-2012, 04:16 PM #5
Member
- Join Date
- Jul 2012
- Location
- Norway
- Posts
- 29
- Rep Power
- 0
Re: Learn 2 method?!
Ok cool. I'll take a look.
May the Newtonian physics be with you.
- 08-22-2012, 08:36 AM #6
Re: Learn 2 method?!
It still doesn't sound like you understand methods clearly. When a method returns a value, it writes that value somewhere (on the stack, but that doesn't matter right now) so that the caller can retrieve it and use it. Methods that return void simply don't write any return value. Returning a class or interface is no different. What's actually being returned is a reference to some object (or it could be null).
Your use of the word "headers" suggests you may have some experience with C. But Java does not have headers. Java's import statements are very different from C's includes. And your use of the word "process" is confusing. Do you mean threads? Threads do not necessarily correspond to processes.Get in the habit of using standard Java naming conventions!
- 08-22-2012, 08:41 AM #7
Re: Learn 2 method?!
Also, there is no such thing as a "static constructor" in Java. Apparently there is such a thing in C#, but I don't know anything about that. What Java does have are static initializer blocks.
I'm not just nitpicking semantics here. There are some important differences.Get in the habit of using standard Java naming conventions!
- 08-22-2012, 07:34 PM #8
Member
- Join Date
- Jul 2012
- Location
- Norway
- Posts
- 29
- Rep Power
- 0
Re: Learn 2 method?!
Nah I get it now, but thanks for elaborating further. Better to say too much than too little, IMO hehe.
I mean the literal header of the method (as opposed to its {} body) and the literal process of the computer (e.g. when the computer puts information into memory). I don't know anything about C, but I'm assuming you're talking about some separate "Header" function or something (not what I was talking about).
According to Mehran Sahami of Stanford University (2009), you got a method header (though most often not, it turns out) and a method Body. I guess I'm a bit confused myself, because you sound like I'm really talking about a "Thread" and that "method header" is actually the "thread header" and the "thread body" is the list of methods or "submethods" used?
By "constructor" I just meant the general method that creates an instance of another class. But I guess constructors are just a type of those, and initializers are another?
I'n either case, I got some spare time to go through these links now.
====================
Edit: Actually, I think it was thenewboston or some other youtube channel that talked about method headers and bodies. xDLast edited by DrMadolite; 08-22-2012 at 08:21 PM.
May the Newtonian physics be with you.
- 08-22-2012, 10:18 PM #9
Re: Learn 2 method?!
What you are calling "method header" might be two things: method signature or method definition. Method signature is the attributes of a method that uniquely identify it; no two methods can have the same signature. In Java, a method's signature includes its name and the number, type, and order of its arguments. The method definition includes the signature, the return type, and the modifiers (public, static, etc.)
Get in the habit of using standard Java naming conventions!
Similar Threads
-
Trying to learn GUI
By Osi in forum New To JavaReplies: 1Last Post: 11-25-2011, 10:13 PM -
How to learn EJB
By nobel in forum Enterprise JavaBeans (EJB)Replies: 7Last Post: 10-25-2011, 02:18 PM -
Where and what to learn next?
By ryanmk54 in forum New To JavaReplies: 1Last Post: 06-29-2011, 12:52 AM -
How did you learn?
By code_newbie in forum New To JavaReplies: 17Last Post: 12-25-2010, 01:25 AM -
To learn or not learn?
By Fuzzman3000 in forum New To JavaReplies: 5Last Post: 07-09-2010, 06:11 AM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks