Clemson to Montana and Back

Well sometimes trips don’t start out in a perfect way. As we left Clemson we knew that Our good friends Les and Jane were going to come on behind us by a few hours. They had told us they were staying…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How well do you know the Java main method? 12 simple questions to test your knowledge!

A lot of the motivation behind this little quiz came after speaking to some of my friends about some basic Java principles and we quickly realized we greatly overlooked some of the basics, in particular, the main method. This article is meant to be a fun little quiz (yes quizzes can be fun) to see if you know some of the basics behind the most popular method out there!

Try cover the answer before you read the question to test your knowledge, don’t worry if you don’t get most of them, I had to research all of them :D.

The word main is purely a convention that originated from earlier languages like C & C++, it is not reserved as a keyword in Java.

The main method in Java must be declared static so to allow the JVM to easily locate it without the need of invoking the class’s constructor. A main method without the static modifier causes ambiguity to the JVM because non-static methods must be called via the constructor and the JVM won’t know which class’ constructor to call. If it picks a random class, it may have to input the args into that class’ constructor, it will have no idea what kind of args to pass in, if it can miraculously pass args, then which method in the class is the actual entry point? Remember, main is not a keyword.

The String []args in the main method can never be null even if no arguments are passed. It is simply an empty initialized array of strings.

Add a comment

Related posts:

On Principles

For as long as I can remember my mind has always searched for exceptions to the rule. On one hand it helps because it forces you to be discerning. On the other hand, it can make you insufferable…

True or False? The Clash of Social Media and Journalism

Journalism has always been an evolving medium: It has found a place off of newspapers into radio, television, and online. But the internet has proved a completely different beast due to the fact that…

Activity 31 Code Review

A form of peer review in which code is incrementally inspected with an eye toward architectural concerns as the code is developed. Code review is a fantastic practice that every team should do…