Does every program in Java require a class?Is it possible to have a java program with just import statementClass, interface or enum expected (Java)Does every Java .class file contain a public class?Is Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?Java inner class and static nested classFastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?Comparing Java enum members: == or equals()?What is a JavaBean exactly?Creating a memory leak with JavaStatic Classes In JavaWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?
What makes Ada the language of choice for the ISS's safety-critical systems?
Is using haveibeenpwned to validate password strength rational?
Logarithm of exponential
Would the US government be able to hold control if all electronics were disabled for an indefinite amount of time?
How can this tool find out registered domains from an IP?
Do simulator games use a realistic trajectory to get into orbit?
Universal hash functions with homomorphic XOR property
Why doesn't Adrian Toomes give up Spider-Man's identity?
How to return a security deposit to a tenant
Why was the Sega Genesis marketed as a 16-bit console?
Should an arbiter claim draw at a K+R vs K+R endgame?
What is the `some` keyword in SwiftUI?
Why didn't Voldemort recognize that Dumbledore was affected by his curse?
SOQL Not Recognizing Field?
How is water heavier than petrol, even though its molecular weight is less than petrol?
Confusion around using "des" in sentences
What can I, as a user, do about offensive reviews in App Store?
How to construct an hbox with negative height?
How come the nude protesters were not arrested?
Winning Strategy for the Magician and his Apprentice
What ways have you found to get edits from non-LaTeX users?
Is counterpoint still used today?
Overlapping String-Blocks
Why would future John risk sending back a T-800 to save his younger self?
Does every program in Java require a class?
Is it possible to have a java program with just import statementClass, interface or enum expected (Java)Does every Java .class file contain a public class?Is Java “pass-by-reference” or “pass-by-value”?Does a finally block always get executed in Java?Java inner class and static nested classFastest way to determine if an integer's square root is an integerHow do I read / convert an InputStream into a String in Java?Comparing Java enum members: == or equals()?What is a JavaBean exactly?Creating a memory leak with JavaStatic Classes In JavaWhy don't Java's +=, -=, *=, /= compound assignment operators require casting?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Every Java program requires the
presence of at least one class.
Is the above statement always true ?
java
add a comment |
Every Java program requires the
presence of at least one class.
Is the above statement always true ?
java
2
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
3
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
1
@Peter: It's somewhere around 200 classes from thejava.*
package; see my updated answer.
– Sanjay T. Sharma
Mar 5 '11 at 15:20
add a comment |
Every Java program requires the
presence of at least one class.
Is the above statement always true ?
java
Every Java program requires the
presence of at least one class.
Is the above statement always true ?
java
java
edited Nov 4 '17 at 10:35
Ani Menon
16.7k106187
16.7k106187
asked Mar 5 '11 at 14:27
TonyTony
55751326
55751326
2
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
3
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
1
@Peter: It's somewhere around 200 classes from thejava.*
package; see my updated answer.
– Sanjay T. Sharma
Mar 5 '11 at 15:20
add a comment |
2
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
3
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
1
@Peter: It's somewhere around 200 classes from thejava.*
package; see my updated answer.
– Sanjay T. Sharma
Mar 5 '11 at 15:20
2
2
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
3
3
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
1
1
@Peter: It's somewhere around 200 classes from the
java.*
package; see my updated answer.– Sanjay T. Sharma
Mar 5 '11 at 15:20
@Peter: It's somewhere around 200 classes from the
java.*
package; see my updated answer.– Sanjay T. Sharma
Mar 5 '11 at 15:20
add a comment |
6 Answers
6
active
oldest
votes
Yes, you need at least one class to have a program, but no, you do not need any methods (contrary to some other answers).
The reason you need a class is because in Java, all code is inside classes. So to have any code, you need a class. However, code doesn't necessarily need to be in a method. It can also be in initializers. So, here is a complete Java program with no methods:
class LookMaNoMethods
static
System.out.println("Hello, world!");
System.exit(0);
And that gives...
$ javac LookMaNoMethods.java
$ java LookMaNoMethods
Hello, world!
$
EDIT : From Java 7 the above code with just static block and no main method does not produce any output. Main method is now compulsory. The code with no main method compiles successfully though.
1
Interesting. A class with a static initializer is a valid program, even though there is nomain
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.
– Matti Virkkunen
Mar 5 '11 at 14:53
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
This program works only because the static initializer invokesSystem.exit()
before the error message about a missing main method can be shown.
– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invokemain
.
– rlibby
Mar 5 '11 at 21:43
add a comment |
From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.
public enum AAA
AAA;
public static void main(final String[] args)
System.out.println("H");
EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.*
package) can be viewed by setting the -verbose:class
JVM parameter.
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
add a comment |
A program requires an entry point. An entry point has to be a method. In Java, every method must be contained in a class.
That would imply that every program must have a at least one class.
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
add a comment |
Yes. In Java you always need one class with the function main to have the JRE run it.
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
add a comment |
yes , you need minimum one class.
add a comment |
JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
so, it is compulsory to provide at least one class name to Java programs.
ex--->`
class Test
public static void main(String [] args)
System.out.println("Hello World");
so, javac _____ ("Here we have to give the name of java program in which we save")
java ______ ("Provide the name of a class which contain the main() method")
----->
according to our program
javac Hello (here I save the program name by Hello.java)
java Test (because Test class contains main() method)
Thank You
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5204385%2fdoes-every-program-in-java-require-a-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Yes, you need at least one class to have a program, but no, you do not need any methods (contrary to some other answers).
The reason you need a class is because in Java, all code is inside classes. So to have any code, you need a class. However, code doesn't necessarily need to be in a method. It can also be in initializers. So, here is a complete Java program with no methods:
class LookMaNoMethods
static
System.out.println("Hello, world!");
System.exit(0);
And that gives...
$ javac LookMaNoMethods.java
$ java LookMaNoMethods
Hello, world!
$
EDIT : From Java 7 the above code with just static block and no main method does not produce any output. Main method is now compulsory. The code with no main method compiles successfully though.
1
Interesting. A class with a static initializer is a valid program, even though there is nomain
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.
– Matti Virkkunen
Mar 5 '11 at 14:53
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
This program works only because the static initializer invokesSystem.exit()
before the error message about a missing main method can be shown.
– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invokemain
.
– rlibby
Mar 5 '11 at 21:43
add a comment |
Yes, you need at least one class to have a program, but no, you do not need any methods (contrary to some other answers).
The reason you need a class is because in Java, all code is inside classes. So to have any code, you need a class. However, code doesn't necessarily need to be in a method. It can also be in initializers. So, here is a complete Java program with no methods:
class LookMaNoMethods
static
System.out.println("Hello, world!");
System.exit(0);
And that gives...
$ javac LookMaNoMethods.java
$ java LookMaNoMethods
Hello, world!
$
EDIT : From Java 7 the above code with just static block and no main method does not produce any output. Main method is now compulsory. The code with no main method compiles successfully though.
1
Interesting. A class with a static initializer is a valid program, even though there is nomain
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.
– Matti Virkkunen
Mar 5 '11 at 14:53
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
This program works only because the static initializer invokesSystem.exit()
before the error message about a missing main method can be shown.
– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invokemain
.
– rlibby
Mar 5 '11 at 21:43
add a comment |
Yes, you need at least one class to have a program, but no, you do not need any methods (contrary to some other answers).
The reason you need a class is because in Java, all code is inside classes. So to have any code, you need a class. However, code doesn't necessarily need to be in a method. It can also be in initializers. So, here is a complete Java program with no methods:
class LookMaNoMethods
static
System.out.println("Hello, world!");
System.exit(0);
And that gives...
$ javac LookMaNoMethods.java
$ java LookMaNoMethods
Hello, world!
$
EDIT : From Java 7 the above code with just static block and no main method does not produce any output. Main method is now compulsory. The code with no main method compiles successfully though.
Yes, you need at least one class to have a program, but no, you do not need any methods (contrary to some other answers).
The reason you need a class is because in Java, all code is inside classes. So to have any code, you need a class. However, code doesn't necessarily need to be in a method. It can also be in initializers. So, here is a complete Java program with no methods:
class LookMaNoMethods
static
System.out.println("Hello, world!");
System.exit(0);
And that gives...
$ javac LookMaNoMethods.java
$ java LookMaNoMethods
Hello, world!
$
EDIT : From Java 7 the above code with just static block and no main method does not produce any output. Main method is now compulsory. The code with no main method compiles successfully though.
edited Feb 23 '16 at 12:15
Nirmit Srivastava
563623
563623
answered Mar 5 '11 at 14:41
rlibbyrlibby
5,4081524
5,4081524
1
Interesting. A class with a static initializer is a valid program, even though there is nomain
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.
– Matti Virkkunen
Mar 5 '11 at 14:53
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
This program works only because the static initializer invokesSystem.exit()
before the error message about a missing main method can be shown.
– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invokemain
.
– rlibby
Mar 5 '11 at 21:43
add a comment |
1
Interesting. A class with a static initializer is a valid program, even though there is nomain
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.
– Matti Virkkunen
Mar 5 '11 at 14:53
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
This program works only because the static initializer invokesSystem.exit()
before the error message about a missing main method can be shown.
– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invokemain
.
– rlibby
Mar 5 '11 at 21:43
1
1
Interesting. A class with a static initializer is a valid program, even though there is no
main
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.– Matti Virkkunen
Mar 5 '11 at 14:53
Interesting. A class with a static initializer is a valid program, even though there is no
main
method, which is then again required if there is no static initializer. I wonder what the standard says exactly about the requirement for an entry point.– Matti Virkkunen
Mar 5 '11 at 14:53
1
1
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
The static-block is implemented as special kind of method internally ("<cinit>"). At least AFAIK. But still a good answer, I never was aware that you could start a method without a main(), too... Nice to know.
– Boris
Mar 5 '11 at 15:05
5
5
This program works only because the static initializer invokes
System.exit()
before the error message about a missing main method can be shown.– Paŭlo Ebermann
Mar 5 '11 at 17:21
This program works only because the static initializer invokes
System.exit()
before the error message about a missing main method can be shown.– Paŭlo Ebermann
Mar 5 '11 at 17:21
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invoke
main
.– rlibby
Mar 5 '11 at 21:43
@Paŭlo Ebermann, yes, that's correct, but it is still orderly, not a race. The class is obviously loaded before any attempt to invoke
main
.– rlibby
Mar 5 '11 at 21:43
add a comment |
From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.
public enum AAA
AAA;
public static void main(final String[] args)
System.out.println("H");
EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.*
package) can be viewed by setting the -verbose:class
JVM parameter.
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
add a comment |
From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.
public enum AAA
AAA;
public static void main(final String[] args)
System.out.println("H");
EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.*
package) can be viewed by setting the -verbose:class
JVM parameter.
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
add a comment |
From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.
public enum AAA
AAA;
public static void main(final String[] args)
System.out.println("H");
EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.*
package) can be viewed by setting the -verbose:class
JVM parameter.
From the JVM's point of view; yes. From a programmers view point, it can be a Class or an Enum.
public enum AAA
AAA;
public static void main(final String[] args)
System.out.println("H");
EDIT: Even if you have a class with empty main method, there are a lot of core classes which work behind the scene to just run the "empty" class of yours. A list of those classes (around 200 from the java.*
package) can be viewed by setting the -verbose:class
JVM parameter.
edited Mar 5 '11 at 15:20
answered Mar 5 '11 at 14:35
Sanjay T. SharmaSanjay T. Sharma
19.9k34765
19.9k34765
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
add a comment |
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
1
1
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
Java enums are weird.
– Matti Virkkunen
Mar 5 '11 at 14:39
2
2
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
But an Enum is a class: download.oracle.com/javase/1.5.0/docs/api/java/lang/Enum.html. The new keyword is syntactic sugar that hides the class keyword.
– duffymo
Mar 5 '11 at 15:45
add a comment |
A program requires an entry point. An entry point has to be a method. In Java, every method must be contained in a class.
That would imply that every program must have a at least one class.
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
add a comment |
A program requires an entry point. An entry point has to be a method. In Java, every method must be contained in a class.
That would imply that every program must have a at least one class.
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
add a comment |
A program requires an entry point. An entry point has to be a method. In Java, every method must be contained in a class.
That would imply that every program must have a at least one class.
A program requires an entry point. An entry point has to be a method. In Java, every method must be contained in a class.
That would imply that every program must have a at least one class.
answered Mar 5 '11 at 14:29
Matti VirkkunenMatti Virkkunen
53.1k6100138
53.1k6100138
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
add a comment |
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
1
1
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
This is a very reasonable answer, but "an entry point has to be a method" is not completely true. See my answer for an entry point that is not a method.
– rlibby
Mar 5 '11 at 14:48
add a comment |
Yes. In Java you always need one class with the function main to have the JRE run it.
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
add a comment |
Yes. In Java you always need one class with the function main to have the JRE run it.
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
add a comment |
Yes. In Java you always need one class with the function main to have the JRE run it.
Yes. In Java you always need one class with the function main to have the JRE run it.
answered Mar 5 '11 at 14:28
KonerakKonerak
33.4k980109
33.4k980109
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
add a comment |
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
3
3
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
This isn’t the reason. Ruby too is object oriented but it doesn’t need any class. The reason is just “because”.
– Konrad Rudolph
Mar 5 '11 at 14:29
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
Hmm I agree the implication is not true. How about 'sun wants it so?'/.
– Konerak
Mar 5 '11 at 14:30
1
1
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
Groovy (obviously built on top of JVM) does not require any classes to run. But the generated bytecode defines classes behind the scenes.
– Tomasz Nurkiewicz
Mar 5 '11 at 14:33
1
1
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@Konrad - the statement wasn't that all object-oriented languages require a class, only Java. And other languages that have functions as first-class objects, unlike Java, might appear to allow functions as entry points, but they're still classes underneath.
– duffymo
Mar 5 '11 at 15:46
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
@duffymo Well, it was before @Konerak changed the answer. The current answer is correct.
– Konrad Rudolph
Mar 5 '11 at 22:00
add a comment |
yes , you need minimum one class.
add a comment |
yes , you need minimum one class.
add a comment |
yes , you need minimum one class.
yes , you need minimum one class.
edited Aug 14 '12 at 15:23
Jacob Schoen
10.2k156997
10.2k156997
answered Mar 6 '11 at 5:33
stinepikestinepike
44.3k1381103
44.3k1381103
add a comment |
add a comment |
JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
so, it is compulsory to provide at least one class name to Java programs.
ex--->`
class Test
public static void main(String [] args)
System.out.println("Hello World");
so, javac _____ ("Here we have to give the name of java program in which we save")
java ______ ("Provide the name of a class which contain the main() method")
----->
according to our program
javac Hello (here I save the program name by Hello.java)
java Test (because Test class contains main() method)
Thank You
add a comment |
JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
so, it is compulsory to provide at least one class name to Java programs.
ex--->`
class Test
public static void main(String [] args)
System.out.println("Hello World");
so, javac _____ ("Here we have to give the name of java program in which we save")
java ______ ("Provide the name of a class which contain the main() method")
----->
according to our program
javac Hello (here I save the program name by Hello.java)
java Test (because Test class contains main() method)
Thank You
add a comment |
JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
so, it is compulsory to provide at least one class name to Java programs.
ex--->`
class Test
public static void main(String [] args)
System.out.println("Hello World");
so, javac _____ ("Here we have to give the name of java program in which we save")
java ______ ("Provide the name of a class which contain the main() method")
----->
according to our program
javac Hello (here I save the program name by Hello.java)
java Test (because Test class contains main() method)
Thank You
JAVA required at least one class in a program because at the time of execution of Java programs we needed to provide the name of a class which contains the main () method.
so, it is compulsory to provide at least one class name to Java programs.
ex--->`
class Test
public static void main(String [] args)
System.out.println("Hello World");
so, javac _____ ("Here we have to give the name of java program in which we save")
java ______ ("Provide the name of a class which contain the main() method")
----->
according to our program
javac Hello (here I save the program name by Hello.java)
java Test (because Test class contains main() method)
Thank You
edited Mar 24 at 17:18
answered Mar 24 at 17:00
JATIN BEHUNEJATIN BEHUNE
12
12
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f5204385%2fdoes-every-program-in-java-require-a-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Always true, for core and enterprise Java and every other kind as well.
– duffymo
Mar 5 '11 at 14:30
3
You need Object and String to load before you can load an empty mian(String[]) method, that makes three ;)
– Peter Lawrey
Mar 5 '11 at 15:07
1
@Peter: It's somewhere around 200 classes from the
java.*
package; see my updated answer.– Sanjay T. Sharma
Mar 5 '11 at 15:20