Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Poll

What programming topic would you want the next challenge to be about?  (It might be a good opportunity to focus on a subject you're not familiar with or to reinforce knowledge on one that you already know)

Control Flow
- 2 (2.2%)
Arrays, Strings, Pointers, and References
- 8 (9%)
Functions
- 4 (4.5%)
Basic object-oriented programming
- 30 (33.7%)
A bit more advanced OOP (Composition, Operator overloading, Inheritance, Virtual Functions)
- 18 (20.2%)
Templates
- 8 (9%)
Other (Explain)
- 4 (4.5%)
Working with files?  (Streams)
- 15 (16.9%)

Total Members Voted: 89


Pages: 1 ... 60 61 [62] 63 64 ... 78

Author Topic: Programming Challenges & Resources (#bay12prog) Initiative  (Read 95748 times)

TolyK

  • Bay Watcher
  • Nowan Ilfideme
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #915 on: February 16, 2011, 11:30:52 am »

I plan on playing around a bit with the free version, then get either the indie version or full dev version (depends on which) for my "team" of friends to make a game with.
Logged
My Mafia Stats
just do whatevery tolyK and blame it as a bastard mod
Shakerag: Who are you personally suspicious of?
At this point?  TolyK.

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #916 on: February 16, 2011, 11:33:17 am »

I would, but I need to focus on making numbers add properly first  :P
Logged

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #917 on: February 16, 2011, 11:45:38 am »

I've been learning the basics of Java just out of interest. This is giving me some problems.

My Java is rusty but I don't think your GradeBook class is supposed to be in your main method.  The main method should contain what is being run, not the definition of a class.

My memory has it being more like:

Code: [Select]
public static void main(String[] args)
{
//main code
GradeBook test = new GradeBook('blah')  //create an instance of the gradebook class
}


public class GradeBook
{
//class stuff
}

« Last Edit: February 16, 2011, 11:58:22 am by Levi »
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #918 on: February 16, 2011, 12:02:53 pm »

I've been learning the basics of Java just out of interest. This is giving me some problems.
For starters, you have a code block outside a class. You need to remove the outermost set of squiggly braces.

Methods must be members of a class. Your main method isn't. It needs to be inside the GradeBook class assuming you plan on running this class as an application. If this class is not an application on its own, you don't need a main method.
 
Your main method also has neither a body nor and ending semi colon. It needs the first, unless it is an abstract method on an abstract class or interface and then it would need the later.

I know you have not mentioned it, but you should note that the class name must be identical to the .java file name.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #919 on: February 16, 2011, 01:12:13 pm »

I've been learning the basics of Java just out of interest. This is giving me some problems.

My Java is rusty but I don't think your GradeBook class is supposed to be in your main method.  The main method should contain what is being run, not the definition of a class.

My memory has it being more like:

Code: [Select]
public static void main(String[] args)
{
//main code
GradeBook test = new GradeBook('blah')  //create an instance of the gradebook class
}


public class GradeBook
{
//class stuff
}
Java allows you to define classes within functions, so you can define a class within the main function. What it does not like, as Nadaka, is stray code. Everything has to be part of a class. What you'll want to do is define a class, then in that class provide all functions associated with the class. If that class is the whole program, you can just define all functions as static and add a main function to the class, which is where Java will start the program after compiling it.
(Not defining the functions as static is going to make the compiler scream at you because you're not making an instance of your class. Static tells the compiler it doesn't need an instance of the class to call the functions from, but that it can call them from anywhere. This also means that in theory you can define main inside a class and then inside the main loop make instances of that class, because main has to be static. But that's going to make your program like some arcane kind of voodoo if you don't watch out)
« Last Edit: February 16, 2011, 01:14:32 pm by Virex »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #920 on: February 16, 2011, 01:24:33 pm »

The arcane voodoo of instantiating an instance of a class inside your main method that virex mentions is standard operating procedure. It is this way so that even if you intend your class to run on its own, it is still possible to create safe instances of it in another application and use it like any old object.

I strongly recommend against the use of internal classes, it really is just a hack by the compiler to create separate classes and makes your code a bit more confusing.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #921 on: February 16, 2011, 01:39:29 pm »

Comes to show how much I know of proper code maintenance...
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #922 on: February 16, 2011, 03:04:36 pm »

Theres some problem with the main method. any ideas?
When the error says to look somewhere, it's usually a good idea to look there first.  ;)
Code: [Select]
{
public static void main(String[] args)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #923 on: February 16, 2011, 03:38:39 pm »

Theres some problem with the main method. any ideas?
When the error says to look somewhere, it's usually a good idea to look there first.  ;)
Code: [Select]
{
public static void main(String[] args)

If you havent noticed, this is one of the first basic Java tutorials. I got stuck there, hence, 'main thingy is broken' doesn't help me much as I don't know why. That said I quoted in the post that that was the problem, so I did indeed look at the error. I'll fiddle with it some more.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #924 on: February 16, 2011, 03:44:48 pm »

My problem is, in the examples that the tutorials give,

public static void main(String[] args)

Is never included... yet they insist it is an essential part of a class. So I'm playing in the dark trying to guess where its supposed to go and where the {} are placed etc.

Sometimes it works, sometimes it doesnt.

I've worked out what I did wrong, and understand it now, thanks for the comments!
« Last Edit: February 16, 2011, 03:56:04 pm by Deadmeat1471 »
Logged

eerr

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #925 on: February 16, 2011, 04:25:36 pm »

It sounds like you figured it out, nevertheless, I will give you my breakdown.

public static void main(String[] args)

must always be within a class.
You can have one in every class, but depending on how you are compiling/running, you will need to pick the correct main method.
Logged

Deadmeat1471

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #926 on: February 16, 2011, 04:39:44 pm »

It sounds like you figured it out, nevertheless, I will give you my breakdown.

public static void main(String[] args)

must always be within a class.
You can have one in every class, but depending on how you are compiling/running, you will need to pick the correct main method.

Yeah my mistake was I thought the class had to be inside the main block, I was wrong  :P thanks anyhow.
Logged

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #927 on: February 18, 2011, 11:43:44 am »

The arcane voodoo of instantiating an instance of a class inside your main method that virex mentions is standard operating procedure. It is this way so that even if you intend your class to run on its own, it is still possible to create safe instances of it in another application and use it like any old object.

I strongly recommend against the use of internal classes, it really is just a hack by the compiler to create separate classes and makes your code a bit more confusing.
There are not enough ++'s for this. Internal classes are useful in a very limited subset of situations (i.e., I could be convinced that a ListIterator<T> should be an internal class of List<T>), but should be generally avoided.

And before you ever, ever use an anonymous class, consider that you should be programming as if the person who will deal with your code when you're done is an angry psychopath who knows where you live. And, given that realization, you should rethink the use of them.
Logged

Virex

  • Bay Watcher
  • Subjects interest attracted. Annalyses pending...
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #928 on: February 18, 2011, 02:05:13 pm »

And before you ever, ever use an anonymous class, consider that you should be programming as if the person who will deal with your code when you're done is an angry psychopath who knows where you live. And, given that realization, you should rethink the use of them.
I would like to add that at the times that an anonymous class is useful, you'll probably use one without thinking about it anyway, because it's the right tool for the job. For example, if you need to add an event handler to a GUI element by hand, you'll probably use
Code: [Select]
GUI_Element.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
//Code to handle the action here
}})
without realizing that you're using an anonymous interface here (granted, it's an interface instead of a class, but it's the closest example I could think off of the top of my head). It's the times when you're conscienceless using an anonymous class that things tend to get icky because that usually means you're trying to do something your way instead of the way it should be done.
« Last Edit: February 18, 2011, 02:08:02 pm by Virex »
Logged

Blank Expression

  • Bay Watcher
    • View Profile
Re: Programming Challenges & Resources (#bay12prog) Initiative
« Reply #929 on: February 18, 2011, 02:16:21 pm »

I retract my previous comment; I forgot that it was basically necessary for doing GUI programming in Java.


New rule: don't do GUI programming in Java. :p
Logged
Pages: 1 ... 60 61 [62] 63 64 ... 78