Author |
Message |
KRKux
Occasionally has a life
Joined: Thu Apr 23, 2009 6:50 pm Posts: 278 Location: London / Bedfordshire / Newcastle
|
hey guys, Couldn't find a sub forum for programming and has been long time since I have been on here, so shall just post here! Been busy in Uni with computer science course in Newcastle! Anyway what I need help with is understanding this little bit in Java. I have a book that says the construction of a method should always be like this; public static void main(String[] args)And that main is that starting point of all java applications and cannot be changed However in lectures we made the amazing Hello, World! application but my lecturer constructed the class like this; public static void HelloWorld()So why does the book say use main for the program and my lecturer used HelloWorld? Probably really simple but its a long day 
_________________I had the last spam thread in the TMP. 
|
Fri Jan 29, 2010 5:14 pm |
|
 |
Alexgadgetman
Occasionally has a life
Joined: Fri Apr 24, 2009 4:56 pm Posts: 306
|
Have you asked her yet?  (couldnt resist  )
|
Fri Jan 29, 2010 5:32 pm |
|
 |
KRKux
Occasionally has a life
Joined: Thu Apr 23, 2009 6:50 pm Posts: 278 Location: London / Bedfordshire / Newcastle
|
No. I don't see her anymore, plenty of new girls here which I talk to  .
_________________I had the last spam thread in the TMP. 
|
Fri Jan 29, 2010 5:34 pm |
|
 |
Fogmeister
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 7:35 pm Posts: 6580 Location: Getting there
|
Oh, ignore my previous reply.
You are interpreting your text book incorrectly.
When you create a method you do it in the form...
public void myMethod() {
}
there are variations like making the method private instead of public or making it return an int, string, etc... instead of void.
HOWEVER!
In order to know where to start, your program needs...
public static void main(String [] args) {
}
Without this your program won't do anything as it won't know where to run.
|
Fri Jan 29, 2010 5:40 pm |
|
 |
Nick
Spends far too much time on here
Joined: Thu Apr 23, 2009 11:36 pm Posts: 3527 Location: Portsmouth
|
main() is a special method - it is the starting point for the application. Exactly. The above is a method, which would have formed part of a class. I am going to bet that your lecturer had something similar to the following code: Here, you can see two methods - main and HelloWorld. The main() is where the program begins, and HelloWorld() is called from within main().
_________________
|
Fri Jan 29, 2010 10:04 pm |
|
 |
KRKux
Occasionally has a life
Joined: Thu Apr 23, 2009 6:50 pm Posts: 278 Location: London / Bedfordshire / Newcastle
|
Hey all, sorry for late reply have been busy! Heres the code he used to clear up the confusion! 
_________________I had the last spam thread in the TMP. 
|
Sun Jan 31, 2010 12:19 am |
|
 |
forquare1
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 6:36 pm Posts: 5150 Location: /dev/tty0
|
Try it out, it doesn't work: Not every class needs a main, only the "main" class. Did he not do something like: or ? An interesting point may be (and I've no idea why he'd be telling you this unless you were looking at ultra-advanced stuff) that you can somehow change the name of the main method...No idea, probably some JVM jiggery pockery, or some fancy setting somewhere. I'd ask your lecturer for clarification, because as far as I know, your program will always start in a class with a main method.
|
Sun Jan 31, 2010 12:51 am |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
I would say I'd hunt you down for a drink.... but I really can't be arsed and the bar I would have gone to would have been full of girls, however judging from the OLD thread you would be like Raj from BBT...sober.  is it Newcastle or Northumbria? Can suggest some books in the library you should have a look at, and even some lecturers to talk to depending on uni
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Sun Jan 31, 2010 2:11 am |
|
 |
KRKux
Occasionally has a life
Joined: Thu Apr 23, 2009 6:50 pm Posts: 278 Location: London / Bedfordshire / Newcastle
|
Forquare it work for me when I run it, I use BlueJ if that matters... I shall ask him next time I see him.
And Finlay I go to Newcastle....not the poly!
_________________I had the last spam thread in the TMP. 
|
Sun Jan 31, 2010 12:55 pm |
|
 |
forquare1
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 6:36 pm Posts: 5150 Location: /dev/tty0
|
I would presume BlueJ is doing something to make it run then...
|
Sun Jan 31, 2010 1:20 pm |
|
 |
Nick
Spends far too much time on here
Joined: Thu Apr 23, 2009 11:36 pm Posts: 3527 Location: Portsmouth
|
Ditch BlueJ - it's a piece of crap.
Do it properly!!
_________________
|
Sun Jan 31, 2010 2:24 pm |
|
 |
finlay666
Spends far too much time on here
Joined: Thu Apr 23, 2009 9:40 pm Posts: 4876 Location: Newcastle
|
You got the worse uni then for computer science courses 
_________________TwitterCharlie Brooker: Macs are glorified Fisher-Price activity centres for adults; computers for scaredy cats too nervous to learn how proper computers work; computers for people who earnestly believe in feng shui.
|
Sun Jan 31, 2010 3:21 pm |
|
 |
EddArmitage
I haven't seen my friends in so long
Joined: Thu Apr 23, 2009 9:40 pm Posts: 5288 Location: ln -s /London ~
|
++; Having said that, we had a fortnight of lectures using it. Don't think they do anymore though, based on our feedback.
|
Sun Jan 31, 2010 6:24 pm |
|
|