java public static void main(String[] args) 抛出异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33840694/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
public static void main(String[] args) throws Exception
提问by Duleepa Alupotha
What is the meaning of this?
这是什么意思?
public static void main(String[] args) throws Exception?
I don't know it. If someone know please help me. I really want to know about "throws Exception".
我不知道。如果有人知道请帮助我。我真的很想知道“抛出异常”。
回答by Madushan Perera
public : it is a access specifier that means it can be accessed by any other class in the program.
static : it is access modifier that means when the java program is load then it will create the space in memory automatically.
void(return type) : it does not return any value.
main() : it is a method or a function name.(First method to execute by JVM)
string args[] : its a command line argument it is a collection of variables in the string format.
- throws Exception : Use exceptions to notify about things that should not be ignored.
public :它是一个访问说明符,这意味着它可以被程序中的任何其他类访问。
static :它是访问修饰符,这意味着当 java 程序加载时,它会自动在内存中创建空间。
void(return type) :它不返回任何值。
main() : 它是一个方法或函数名。(JVM 执行的第一个方法)
string args[] :它是一个命令行参数,它是字符串格式的变量集合。
- throws Exception :使用异常来通知不应忽略的事情。
回答by Shiladittya Chakraborty
It's three completely different things:
这是三个完全不同的东西:
public
means that the method is visible and can be called from other objects of other types. Other alternatives are private, protected, package and package-private. See here for more details.
public
意味着该方法是可见的,可以从其他类型的其他对象调用。其他替代方案是私有的、受保护的、包和包私有的。请参阅此处了解更多详情。
static
means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.
static
意味着该方法与类相关联,而不是该类的特定实例(对象)。这意味着您可以在不创建类的对象的情况下调用静态方法。
void
means that the method has no return value. If the method returned an int you would write int instead of void.
void
意味着该方法没有返回值。如果该方法返回一个 int,您将编写 int 而不是 void。
回答by Linus
It is simply the usual entry point method public static void main(String[])
, except that it explicitly specifies an exception may be thrown. This is required by the compiler if any part of your code explicitly throws an exception without a try-catch block (excluding of course runtime-exceptions). For example, this will not compile:
它只是普通的入口点方法public static void main(String[])
,只是它明确指定了可能会抛出的异常。如果您的代码的任何部分在没有 try-catch 块的情况下显式抛出异常(当然不包括运行时异常),则编译器需要这样做。例如,这不会编译:
public static void main(String[] args){
throw new Exception();
}
回答by Janaka Sampath
Those three keywords are pretty much different from one another. Public=This type can be called by any place from the program. not protected from other classes. Static=This type of methods does not have to be instantiated in order to invoke them. Void=This type of methods does not have a return value
这三个关键字彼此非常不同。Public=这个类型可以被程序中的任何地方调用。不受其他类的保护。静态=这种类型的方法不必为了调用它们而被实例化。void=这类方法没有返回值
回答by user8934196
Public: it is an access specifier which can be access throughout the program. Static: it is a keyword which can be used for single copy of that variable. Void: it is an empty return type.
public:它是一个访问说明符,可以在整个程序中访问。静态:它是一个关键字,可用于该变量的单个副本。void:它是一个空的返回类型。