Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2005, 1:11 PM   #1
Jerry
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 Jerry is on a distinguished road
Starting to learn...

So, I woke up a couple of days ago, and just kind of decided I'd like to learn a programing language... After some some thought, I decided to research Java, solely on the basis that It seemed pretty flexible, and I really don't care what I learn, as long as I have something to learn. I just got through Howstuffworks.com's Java introduction and was wondering where to go from there, and also I need some help with some basics...

I still really dont understand what a class IS

And

I can't figure out how to use basic drawing/looping functions to make the second, or third pictures:



I dont mind not having the second answered as much as the first, because classes seem to be quite important to Java, and not understanding them would probably render functions I learn useless...

Oh yea, and I'd also like a link or two to some sites with good tutorials for beginners.


Thanks
Jerry is offline   Reply With Quote
Old Jun 5th, 2005, 5:24 PM   #2
Pilgrim
Newbie
 
Join Date: Jun 2005
Posts: 11
Rep Power: 0 Pilgrim is on a distinguished road
As to your first question, in Java a program is contained in a class. The primary purpose of a class is to define and manipulate an object you would like to create. For example,

public class Cow
{
     public int age;
     public String color;
 
     public Cow()
     {
          age = 3;
          color = "red";
     }

     public void graze()
     {
      ......

Now, I don't know how much you know about java, but hopefully my code segment can be somewhat helpful. Above, I have created a Cow class. The public Cow() is a constructor that defines what variables make up a Cow object. The graze method is an example of a method that could be applied to a Cow object.

Anyway, I don't know how helpful this was, but I hope it helped. I can explain things more if necessary.
Pilgrim is offline   Reply With Quote
Old Jun 5th, 2005, 5:31 PM   #3
Jerry
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 Jerry is on a distinguished road
Okay... I just faintly heard the hissing noise as that flew straight over my head... Could you try to explain more?
Jerry is offline   Reply With Quote
Old Jun 5th, 2005, 7:28 PM   #4
Gilward Kukel
Newbie
 
Join Date: Jun 2005
Location: Vienna, Austria
Posts: 15
Rep Power: 0 Gilward Kukel is on a distinguished road
Quote:
Originally Posted by Jerry
Oh yea, and I'd also like a link or two to some sites with good tutorials for beginners.
You probably know the SUN tutorial?
http://java.sun.com/docs/books/tutorial/
Gilward Kukel is offline   Reply With Quote
Old Jun 5th, 2005, 8:35 PM   #5
Pilgrim
Newbie
 
Join Date: Jun 2005
Posts: 11
Rep Power: 0 Pilgrim is on a distinguished road
Quote:
Originally Posted by Jerry
Okay... I just faintly heard the hissing noise as that flew straight over my head... Could you try to explain more?

Ok, um, this is so much easier to explain in person..... classes are used in Java to create custom-made objects. They also contain methods to manipulate these objects. String, int, and boolean are data types. An object is a custom-made data type. You use different variables as characteristics of the object. You assign values to these variables through a constructor. A method is used to manipulate data or access data for you.

Here's a link I found through Google: http://www.javacoffeebreak.com/tuto...rted/index.html
Pilgrim is offline   Reply With Quote
Old Jun 5th, 2005, 10:34 PM   #6
Knight
Newbie
 
Join Date: Jun 2005
Posts: 28
Rep Power: 0 Knight is on a distinguished road
Try thinking of classes as this:

An automobile has a gas tank size, a top speed, and also a gas mileage. Lets say you want to enter in information for (5) different kinds of automobiles. Since they're all automobiles, they all should have some information for the gas tank size, top speed, and gas mileage. Now you wouldn't want to write the same code (5) times for each different vehicle now would you? No, didn't think so

So, why not create a "class" called "Automobile" with variables to hold the information for the automobile's gas tank size, top speed, and gas mileage. Then, all you have to do to create a new "object" (in other words, add a new automobile).

The code below is an example of how the "Automobile" class may look:
public class Automobile
{
     // For simplicity sake, I'll create each variable separately

     private String nameOfCar;
     private int tankSize;
     private int topSpeed;
     private int mileage;
 
     public Automobile(String name, int gasSize, int highSpeed, int theMileage)
     {
          nameOfCar = name;
          tankSize = gasSize;
          topSpeed = highSpeed;
          mileage = theMileage;
     }
     private String getInfo()
     {
          // The "\n" means to jump to the next line, like the Return key

              System.out.println("Name of automobile: " + nameOfCar + "\nTank
Size: " + tankSize + "\nTop Speed: " + topSpeed + "\nGas Mileage: " +
mileage);
     }
}

Now the code below is an example of how it may be used in another program:
public class Tester
{
	public static void main(String[] args)
	{
                // You can make prompts for the user to enter information for
                // their own automobile, but for now, I'll just show how to
                // create (1) automobile. Let's say it is a Dodge Ram, which 
                // will have a 20 gallon tank, a top speed of 120 mph 
                // (yeah...right.. :p), and has a gas mileage of 12 miles per
                // gallon.

		Automobile Dodge = new Automobile("Dodge Ram truck!",20,120,12);

                // Now, you have an object named "Dodge" of class "Automobile".
                // Now, remember when we wrote the method "getInfo()" in 
                // class Automobile? Since "Dodge" is now of class "Automobile", 
                // it can call its methods. 

                 Dodge.getInfo();

                // The following will be printed out to the screen:
                //  Name of automobile: Dodge Ram truck!
                //  Tank Size: 20
                //  Top Speed: 120
                //  Gas Mileage: 12
         }
}

Hope that answers some questions you may have had.

Last edited by Knight; Jun 5th, 2005 at 10:40 PM.
Knight is offline   Reply With Quote
Old Jun 6th, 2005, 7:02 AM   #7
Jerry
Newbie
 
Join Date: Jun 2005
Posts: 6
Rep Power: 0 Jerry is on a distinguished road
So the class basically is there to tell what the variables are, and how to use them? For an example, you'd enter an object, and the class that it is in, and then define the variables for the object. The variables are then entered into the class? I think I may have missed the mark on this one...



*this is making me feel quite stuipid, I have to say*


Oh, and another thing... Seeing as I'm probably going to need quite a bit more help, does anyone have Aim, so I don't flood the forum with my newbish questions?

Last edited by Jerry; Jun 6th, 2005 at 7:05 AM.
Jerry is offline   Reply With Quote
Old Jun 6th, 2005, 8:48 AM   #8
Knight
Newbie
 
Join Date: Jun 2005
Posts: 28
Rep Power: 0 Knight is on a distinguished road
You almost have it. First, you write the code for the class. Then, you never need to write the class code again. All you ever have to do if you want to use the class that you have written, is declare an object of that type of class (i.e. " Automobile bigTruck = new Automobile("My big truck", 20, 100, 12); " If you still do not understand, I will see if I have time after work to write an example program for you.

Don't worry about feeling stupid. No one (no matter what they say, including me :p ) gets it the first time.
Knight is offline   Reply With Quote
Old Jun 6th, 2005, 3:40 PM   #9
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 5 uman is on a distinguished road
I've seen the HowStuffWorks Java tutorial, and it isn't that great.

About the other 2 problems, look up "Bresenham's Line-Drawing Algorithm" and "Bresenham's Circle-Drawing Algorithm"
uman is offline   Reply With Quote
Old Jun 6th, 2005, 3:50 PM   #10
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 5 uman is on a distinguished road
ok, it looks like Java includes a line-drawing function, and probably a circle-drawing function too. Forget Bresenham.
uman is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:45 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC