PDA

View Full Version : More Java Questions! (Beginner's stuff)



Kik
10-22-2007, 09:45 PM
So, I checked a few tuts on Java, got my hello world! program running, made a few functions that added x + y, etc. Beginners Stuff. Now I've just got a few (more) questions.

1)What's the point of classes/what are they used for exactly?

2)(Sort of goes with 1) How/Why would one use more than one class in a script?

3)(Very easy question... I'm "new" at object-oriented programming) I sort of get the gist of objects and such, but I keep on seeing things like 'you need to use awt.robot in java for findcolor stuff', etc. Could someone explain, maybe giving some more knowledge about objects and such?

4)Is it possible to have a class within a class?

5)Someone mind explaining inheritance to me?

I think that's all... thanks for all your help. I'm using the Sun tutorials right now, and they're pretty detailed and very well written, however I think it's sometimes better to get help from a real person.

Dan Cardin
10-22-2007, 10:06 PM
javaomatic.com
http://www.3dbuzz.com/vbforum/showthread.php?t=129704
or i have some java tutorials on my comp for the learnign from another person part.

4) yea im pretty sure

as for all the others i dont know java well enough :(

Kik
10-23-2007, 12:03 AM
Thanks for the tuts, I might look at them later. I was sort of hoping for straight answers, thought...

anybody else?

R0b0t1
10-23-2007, 02:25 AM
1). Classes are like a "Black Box" utility. This simply means you know what goes in, comes out, but not what actually happens. This is useful because you can restrict classes to only doing some things, make them un-inheritable as to prevent tampering, and hide the contents from a user. (A classes information is called its fields, and its functions are methods)

2). Calling a Java application a script annoys the hell out of me. But anyway, you usually don't need to create classes - most of the functionality is provided in the libraries. However, you might need more than one for some applications where you need to juggle a variety of data. (You actually might want to use a struct for this, but thats different as it contains no methods. A struct is comparable to a Delphi record)

3). OO programming is kind of different... But what you are referring to as "Java.awt.Robot" is technically an object, in the "awt" library. (http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html , read that)

4). Yes, but those classes are only accessible from within that class, unless referenced.

5). Later, long subject. Look here: http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html



Read farther before asking more questions. Thanks :).

EDIT: Just google "Java <SUBJECT>" and it'll come up.

tyler1993
01-02-2008, 12:58 AM
I think i know the answer for number 1... a class is something that runs the program. when you type something like this in the CMD

C:\Java\bin1.6.0_03>java addition

the java is refering to the addition.class

the java reads from the class and that makes what ever you coded in the class

confusing?

R0b0t1
01-02-2008, 01:12 AM
Besides grave-digging, you're wrong. A class is <my description here>.


How a class works in compiling a program though is that it has the same name as the file, and it has a "main" method. I think you can make a main method for any class and it get run... I'm not sure though. Might be some Java compiler thing.

chrisn2323
01-05-2008, 11:54 PM
only the main class needs a main method. There can be other classes that hold methods

3). OO programming is kind of different... But what you are referring to as "Java.awt.Robot" is technically an object, in the "awt" library. (http://java.sun.com/j2se/1.4.2/docs/...awt/Robot.html , read that)

No it is a class in the awt package, an object is an instance of a class.

Is it possible to have a class within a class?

Yes