00:00
00:00
Newgrounds Background Image Theme

YendorNG just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

A rather noobish Java question

365 Views | 2 Replies
New Topic Respond to this Topic

A rather noobish Java question 2016-11-25 06:46:07


Seems like the kind of thing that I should have known a long time ago, but I guess I got a little too comfortable with AS3 to know otherwise.

In AS3 the main method is bound to the document class (which, while not under a specific name like main(), is still called each time the program starts up). In Java, there's the main() method, and can be used as an entry point to start the application. Everything is fine so far. However, my confusion arises from this - unlike in AS3 where the method is like a normal function, in Java the main method is static, and there lies my problem.

Since the main method is static, it means that it can only access other variables and functions which are also static. How would I proceed from there? I don't want to make all the function static. Or am I missing something obvious? For the sake of, say, syntactic sugar, is it equivalent to what happens in AS3 if I create my java files as usual, but for the main program code I create a separate file that starts up the main application? Is there any other way that it's done? If so, what could be done instead?


Slint approves of me! | "This is Newgrounds.com, not Disney.com" - WadeFulp

"Sit look rub panda" - Alan Davies

BBS Signature

Response to A rather noobish Java question 2016-11-25 10:28:25


I think it would make sense to create a non-static "Application" class where you can do all you need to do in a non-static way, and then us the static "main" method to create an instance of this application class, and then call any more methods on the instance to get it going.


In the static method just start with something like

GameState game = new GameState();

Then continue coding from the GameState constructor. Main methods have to be static, AS3 just starts be creating a new instance of the document class. It's actually a bit of a shortcoming of AS3 to not let you start at the true static main.


If ya have something to say, PM me. I have a lot of time to spare.

Also never PM egg82.

BBS Signature