• Advertisement
Sign in to follow this  

Some really amateur questions

This topic is 4243 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I am new to Game Dev, and generally new to programming. I have started to learn some Java, however in the books that I am reading (Java in a Nutshell, and Learning Java), they assume that you know the bases of programming, so they explain the syntax, but without noob programmers in mind. So could it be possible for someone to explain a few things to me, just to get me off with programming. What are: 1. Classes 2. Variables 3. Methods 4. Fields 5. Members 6. Method Parameters 7. Arguments 8. Objects I understand that these are all to do with the structure of the programs and the syntax, I sort of understand these things, however I don't feel that I understand them enough to move onto learning the actual language. I hope that what I am saying is making sense, and that I am not making a complete fool out of myself. Thankyou OSM [Edited by - Old Speckled Monkey on July 6, 2006 4:15:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
I would try to explain what I could, but I am short on time and that would take a while. In the meantime, just use google :).

Share this post


Link to post
Share on other sites
I don't understand what you mean by learning all that stuff before learning the actual language. The reason you learn a language is to learn those stuff. You can't learn how to spell before you've learned a language to spell with.

Since you seem to have a book that assume you have some knowledge, here are some random links:
Variables
OOP
Random Beginner Java Tutorial

Hope that helped..

Share this post


Link to post
Share on other sites
You might also get good help from wikipedia, for example, look here for variables : http://en.wikipedia.org/wiki/Variable#In_computer_programming

I'm just going to reorder the concept you said in order of complexity so you can learn more easily :
1. Variables
2. Functions
3. Arguments
4. Classes
5. Members variables (data members)
6. Member functions (methods)

Also, you must know that you will not be able to acquire all of these concepts easily, and you must always be sure to understand correctly what you know before trying to learn anything more.

Share this post


Link to post
Share on other sites
Thanks.
The thing is, I find that all these tutorials can be confusing.
For instance here is a snipet out of a tutorial, defining a class:
A class--the basic building block of an object-oriented language such as Java--is a template that describes the data and behavior associated with instances of that class. When you instantiate a class you create an object that looks and feels like other instances of the same class. The data associated with a class or object is stored in variables; the behavior associated with a class or object is implemented with methods. Methods are similar to the functions or procedures in procedural languages such as C.

This tries to define a class, but however it uses a whole load of other words connected to programming, that hasn't been explained, therefore I find the explanation difficult to understand, for instance it uses the word class, method and object.
I don't whether this is just me, trying to understand everything straight away, or wheter I should just crack on with learning the language.

OSM

Share this post


Link to post
Share on other sites
I think of it the same as trying to explain how to tie your shoe. You really just need to practice and play around with it.. Find something that works, and toy around with that.

Share this post


Link to post
Share on other sites
Classes are definetly not something you should try to learn right away without knowing the basics. Learn the basics first, variables, operators, create a hello world program for example and work up to the more advanced stuff like classes.

Since it says you only need to learn the bases of programming for those books, i'm sure knowing the basic and getting a little background is enough:
Language Basics

Share this post


Link to post
Share on other sites
Quote:
Original post by Old Speckled Monkey
The thing is, I find that all these tutorials can be confusing.

Well, most of them are. Many of them even technically wrong. Most are not good. Start with a good textbook instead. Oh, and apparently you can learn javascript in 10 minutes as opposed to Teach Yourself Programming In Ten Years (<- read this, it's good).

Best of luck!

Share this post


Link to post
Share on other sites
A little example might help you :

Let's say you want to define a dog, what it is and what does it do. To describe these caracteristics, you use a class. Dog is a class. Now, if I have a dog which is called Raymund, then Raymund is a particular instance of a dog. Raymund is an object of class Dog. Raymund shares caracteristics of all dogs in the world, it has every caracteristic that the Dog class has. We know (at least I do) that dogs have a tail. Raymund is a dog so he has a tail. Tail is a (member) variable of class Dog. Also, Raymund, like all dogs, can bark. therefore, the dog class contains the method Bark. A method is an "action" that can make a class. Bark is a method (member function) of class Dog. Every instance of class Dog, like Raymund or his friend Fido, have the same member variables and member functions.

I hope that helped a little bit!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
Hi...
I agree that it could be confusing...
Here is some good link I recommend.. it is redder easy to read.


ENG
http://www.cplusplus.com/doc/tutorial/

SWE
http://www.infa.abo.fi/~chakie/kurser/c++/html/book1.html

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Object is like a box. There are variables and functions in it.
So only one variable from that object is not the whole object, just a part of it.
I hope you understand.

Share this post


Link to post
Share on other sites
We will start with 8 first. And object is a way of thinking about the parts or your code. There are two types of programming (this is not really true, but close enough for what we are talking about here), procedural and Object oriented. In procedural programming, we think in verbs or actions. In Object Oriented programming we think in Nouns or classes. Let’s take a car, in procedural, we would talk about, turning, go forward, go reverse, stop. In object oriented programming we would have, tires, engine, transmission, steering box.

A class is a way to describe a noun in object oriented programming. A class has member variables and methods. A member variable holds data of a specific type (there are ways around this, but those are special cases). A method does some type of action. In the car we have a steering box, a variable might be the current rotation of the box, a method might be Turn left, Center, or Turn right. Your functions often act on your variables. In a class variables and methods can be private, protected or public. Private means that they can only be used within that class, public means that they can be directly accessed outside the class. Protected is kind of a special access type we will talk about in a couple.

When you “declare” a method (declaring a method is creating a template in code that shows how this method will be used) in your code you set your method parameters and the method’s return type. So back to the steering box, we make a method Turn_Left and define is as follows; float Turn_Left(float amount). This says we will turn left by a given amount and when it is done it returns a float saying how much it turned. The reason they might be different is if we reached the left limit. The return value lets you know how much you really turned it, the amount you sent into the function was just really a request of how much you wanted to turn it. The reason you do it this way is because the code that uses your class does not care about how the inner workings of your class work, it only cares about the implementation of the class. This is called encapsulation.

To use your class in your code you first have to instantiate it. This means we create it in memory. Once we create it in memory we then call it an object. It is now something we can use. So we instantiate the Steering_Box class and name it My_Steering_Box. We now use the Turn_Left function we created. My_Steering_Box.Turn_Left(35.5). The 35.5 is an argument. It is how we tell the function what we want it to do. You can use literals (the 35.5 is a literal) or a variable in the argument.

Well I think that covers everything you asked. Hope that helps.

theTroll

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement