Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The teachings of basic, proper Java
#2
Very nicely written tutorial, thanks for sharing.

(02-21-2010, 10:43 PM)tsgh mike Wrote: I mentioned before that a method returns a value. Every method returns a value except for a void. Lets go over what they return.

void
No return type.

I think you got confused here, and its a common mistake either novice Java programmers make, or programmers who dont look at bytecode make. Beleive it or not, void is also return a type! Even though we dont include the keyword 'return' in it, it doesnt mean it doesnt return something. If it didnt return anything, how would it return data? Take a look at the following class and bytecode:
Code:
class MethodByteCode {

    public static void main (String args[]) {
        printMessage();
    }

    static void printMessage() {
        System.out.println ("Hello, world!!!");
    }

}

Code:
Compiled from "MethodByteCode.java"
class MethodByteCode extends java.lang.Object{
MethodByteCode();
  Code:
   0:   aload_0
   1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
   4:   return

public static void main(java.lang.String[]);
  Code:
   0:   invokestatic    #2; //Method printMessage:()V
   3:   return

static void printMessage();
  Code:
   0:   getstatic       #3; //Field java/lang/System.out:Ljava/io/PrintStream;
   3:   ldc     #4; //String Hello, world!!!
   5:   invokevirtual   #5; //Method java/io/PrintStream.println:(Ljava/lang/Str
ing;)V
   8:   return

}

Press any key to continue . . .

As you can see here,
Code:
8:   return
the printMessage() method actually did return something. Tongue

Also, the term 'void' is a return type(which you just learned). And in the sense your reffering it as, its called a method.

I hope you learned something form my own tutorial. ;)
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply


Messages In This Thread
RE: The teachings of basic, proper Java - by Project Evolution - 02-22-2010, 04:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why java haphazard 8 1,789 12-12-2011, 03:23 AM
Last Post: RDCA
  Need Java help from java expert. Blazin 2 2,101 09-07-2011, 02:43 PM
Last Post: AceInfinity
  Java help php 1 1,047 04-06-2010, 06:41 AM
Last Post: php
  Java Problem for real java programmer Testgamma1 10 5,190 03-14-2010, 09:08 AM
Last Post: uber1337
  How do i get java Mozz 4 1,614 02-13-2010, 12:29 PM
Last Post: Mozz

Forum Jump:


Users browsing this thread: 3 Guest(s)