Java main method in class definition

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
User avatar
Bullet Pulse
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 89
Joined: Sun Feb 21, 2010 6:25 pm

Java main method in class definition

Post by Bullet Pulse »

I'm taking a Computer Science class that uses Java, and I've learned the same types of things plus a lot more in C++ at the same time, so I often see differences between them.
So anyways, I've noticed that the main method/function has to be in a class definition in Java, whereas in C++ it doesn't/isn't.
Did they make it this way because they are trying to keep Java Object-Oriented?
Image
User avatar
MrDeathNote
ES Beta Backer
ES Beta Backer
Posts: 594
Joined: Sun Oct 11, 2009 9:57 am
Current Project: cocos2d-x project
Favorite Gaming Platforms: SNES, Sega Megadrive, XBox 360
Programming Language of Choice: C/++
Location: Belfast, Ireland
Contact:

Re: Java main method in class definition

Post by MrDeathNote »

Bullet Pulse wrote:I'm taking a Computer Science class that uses Java, and I've learned the same types of things plus a lot more in C++ at the same time, so I often see differences between them.
So anyways, I've noticed that the main method/function has to be in a class definition in Java, whereas in C++ it doesn't/isn't.
Did they make it this way because they are trying to keep Java Object-Oriented?
Both java and C++ are object orientated. C++ inherits the C language and C declares main in this fashion so thats probably why C++ declares main like that. I'm not sure why there's a difference it's highly possible that it was just a design desicion made by the creators of the languages.
http://www.youtube.com/user/MrDeathNote1988

Image
Image

"C makes it easy to shoot yourself in the foot. C++ makes it
harder, but when you do, it blows away your whole leg." - Bjarne Stroustrup
User avatar
Bakkon
Chaos Rift Junior
Chaos Rift Junior
Posts: 384
Joined: Wed May 20, 2009 2:38 pm
Programming Language of Choice: C++
Location: Indiana

Re: Java main method in class definition

Post by Bakkon »

Bullet Pulse wrote:Did they make it this way because they are trying to keep Java Object-Oriented?
Typically everything in Java is seen as an object. It's the same way for C#.
Post Reply