Computer Science Canada

Java functions/procedures/processes

Author:  Finaltank [ Tue Oct 11, 2005 8:38 pm ]
Post subject:  Java functions/procedures/processes

Ok as you probably see TONS of "Turing" examples ill just use Turing as my base lol...

Ex: In Turing you use

code:

procedure Name

// Statements

end Name


Then you call the procedure 'Name' later in the program to execute that section of code.

Can you do that in java?

Oh bad news, im using Ready To Program, meaning we learn stuff using consolse

Ex:
code:
// The "ClassNameHere" class.
import java.awt.*;
import hsa.Console;

public class ClassNameHere
{
    static Console c;           // The output console
   
    public static void main (String[] args)
    {
        c = new Console ();
       
        // Place your program here.  'c' is the output console
    } // main method
} // ClassNameHere class


Though seeing the code in regular java would be nice Smile

Author:  [Gandalf] [ Tue Oct 11, 2005 8:46 pm ]
Post subject: 

Yes, a procedure is a function that doesn't return anything.
code:
public static void sayHello ()
{
    System.out.println("Hello!");
}

and a simple hello world program in normal Java is:
Java:
public class ClassName
{
    public static void main (String [] args)
    {
         System.out.println("Hello World!");
    }
}

Author:  Finaltank [ Tue Oct 11, 2005 9:07 pm ]
Post subject: 

How would I make it so I can use classes in other parts of the program?

Like

code:
Class Name
{
Stuff
}


// Later on
class Main

call up class 'Name'
}

Author:  [Gandalf] [ Tue Oct 11, 2005 9:12 pm ]
Post subject: 

I suggest reading the great introduction to Java tutorial by wtd:
http://www.compsci.ca/v2/viewtopic.php?t=9576

It has all you need to know and more Wink.

Author:  Martin [ Tue Oct 11, 2005 11:07 pm ]
Post subject: 

Here's a tutorial by the man.

http://java.sun.com/docs/books/tutorial/

Threads are basically lightweight processes. I wouldn't worry about them until you get the fundamentals of Java down first though.


: