Quote:Original post by Old Speckled Monkey
Do you think that perhaps not diving straight into object-oriented programming is a good idea, and perhaps start by learning something more simple like BASIC?
OSM
starting with OO isn't necessarily a bad idea and java is a pretty decent first language.
i can try to explain some of the stuff atleast.
a variable could be seen as a container,
int a; would create a "container" for an integer and name that container 'a'.
a=5; would then put the number '5' into that container.
and if(a==5) { do some stuff } would do some stuff if a contains the number '5'.
a function does something (java doesn't have functions though, only methods, but a method is pretty much a function that belongs to a class).
a simple function would be
int add(int a, int b) {
return a+b
}
the first int is the return type (so the add function would return an integer)
int a,int b is the arguments or parameters
if you then do int result = add(5,15);
result would contain the number '15'.
a class describes an object
for example
public class Point {
private int x;
private int y;
public Point() { //simple constructor
x=0;
y=0;
}
public void setPosition(int px, int py) {
x=px;
y=py;
}
public void draw();
//code to draw the point to the screen.
}
}
you can then create instances of that class like this:
Point myPoint = new Point();
Point myPoint2 = new Point();
and then use that point.
myPoint.setPosition(100,100);
myPoint.draw();
myPoint2.setPosition(100,100);
myPoint2.draw();
so the class contains the code (methods) and data members (attributes) that describes a type of object. a car could have attributes such as speed, acceleration, weight, etc and methods such as turnLeft(), turnRight, Accelerate(), etc.
im sure someone else can explain it better though.