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

Username:   Password: 
 RegisterRegister   
 Classes and Voids
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: Thu May 05, 2005 4:25 pm   Post subject: Classes and Voids

Can someone please tell me what a class is, since i saw everyprogram begins with a class, its not like turing where you can just start the code...
Also, what are "public static voids"...??
Also after declaring a variable, How do i "get" it? :S

I am a newbie to java and yes i am in Grade 9 and yes i have completed turing course and no I am not doing a java course right now. I like programming.
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu May 05, 2005 4:57 pm   Post subject: (No subject)

In Java, pretty much everything is an object. An object's behavior is defined by a class. Hence we use lots of classes.

Let's look at a simple class:

code:
class Foo
{
   public void bar()
   {
      System.out.println("bar");
   }
}


Now we can create a new Foo object.

code:
Foo f = new Foo();


And because the bar method is public, we can call it from outside the class.

code:
f.bar();


Now, what does "void" mean?

Well, void means that the method doesn't return anything.

What does static mean? Well, in the above we defined a "bar" method which we can call on the object. It doesn't always make sense to call methods on a specific object, so we have "static" methods which can be called on the class itself. Let's change our class.

code:
class Foo
{
   public static void bar()
   {
      System.out.println("bar");
   }
}


Now, we can call it like so:

code:
Foo.bar();
MysticVegeta




PostPosted: Thu May 05, 2005 8:56 pm   Post subject: (No subject)

oh i get it now. And an applet is something created using java that can be used to compile on the websites? Like all the online java games and stuff?
Hikaru79




PostPosted: Thu May 05, 2005 9:02 pm   Post subject: (No subject)

MysticVegeta wrote:
oh i get it now. And an applet is something created using java that can be used to compile on the websites? Like all the online java games and stuff?


Yes, but an Applet is just a certain type of class. Everything in Java is an Object. And Applets don't *compile* on websites, they just run on them. But yeah, most online Java games and stuff are Applets (with the very rare exception being jws apps)
MysticVegeta




PostPosted: Fri May 06, 2005 6:21 am   Post subject: (No subject)

thanks a lot
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: