Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Java functions/procedures/processes
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Finaltank




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Tue Oct 11, 2005 8:46 pm   Post subject: (No 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!");
    }
}
Finaltank




PostPosted: Tue Oct 11, 2005 9:07 pm   Post subject: (No 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'
}
[Gandalf]




PostPosted: Tue Oct 11, 2005 9:12 pm   Post subject: (No 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.
Martin




PostPosted: Tue Oct 11, 2005 11:07 pm   Post subject: (No 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.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: