main-method


Should I define a main method in my ruby scripts?

元气小坏坏 提交于 2019-12-18 10:13:33
问题 In python, a module doesn't have to have a main function, but it is common practice to use the following idiom: def my_main_function(): ... # some code if __name__=="__main__": # program's entry point my_main_function() I know Ruby doesn't have to have a main method either, but is there some sort of best practice I should follow? Should I name my method main or something? The Wikipedia page about main methods doesn't really help me. As a side-note, I have also seen the following idiom in

Could you technically call the string[] anything in the main method?

偶尔善良 提交于 2019-12-17 21:19:04
问题 The header for the main method is public static void main (String[] args) Could you technically replace "args" with anything you want? Also, why is the parameter an array? 回答1: args is just a name for the argument in a method. You can rename it to whatever you want. The JVM doesn't need to know what the argument is named ; only the type , String[] , is important. dont break the start point of the app static void main(String[] whateverYouNeed) 回答2: You can rename it to any proper Java

legal main method signature in java

自古美人都是妖i 提交于 2019-12-17 09:55:33
问题 class NewClass{ public static void main(String a){ System.out.print("Hello"); } } When I'm trying to execute above code, then it shows an error, main method not found . But when I changed public static void main(String a) to public static void main(String... a) or public static void main(String a[]) . Then, it works..!! So, My question is how many different ways we can write legal main method signature and what this signature public static void main(String... a) means ? 回答1: Simply because

legal main method signature in java

烂漫一生 提交于 2019-12-17 09:55:13
问题 class NewClass{ public static void main(String a){ System.out.print("Hello"); } } When I'm trying to execute above code, then it shows an error, main method not found . But when I changed public static void main(String a) to public static void main(String... a) or public static void main(String a[]) . Then, it works..!! So, My question is how many different ways we can write legal main method signature and what this signature public static void main(String... a) means ? 回答1: Simply because

Getting ExamQuestion@143c8b3 as print out in console

只愿长相守 提交于 2019-12-13 06:22:09
问题 I have a have a class that has a method which takes a string. Then I have a method which returns the value of the above method. When ever I get the return value in my main class and print it the printed value is "ExamQuestion@143c8b3". How do I get it to print correctly? Thanks 回答1: Whenever you get the format "@" this is the default format of an object's toString() method. Calling System.out.println(question); calls ExamQuestion.toString() . If the method isn't overridden, the version in the

Inheriting the main method

浪尽此生 提交于 2019-12-10 10:17:28
问题 I want to define a base class that defines a main method that instantiates the class, and runs a method. There are a couple of problems though. Here is the base class: public abstract class Strategy { abstract void execute(SoccerRobot robot); public static void main(String args) { Strategy s = new /*Not sure what to put here*/(); s.execute(new SoccerRobot()) } } And here is an example derived class: public class UselessStrategy { void execute(SoccerRobot robot) { System.out.println("I'm

Java app lifecycle

房东的猫 提交于 2019-12-07 23:36:50
问题 When does a typical Java app finish? If I start a new thread in the main method and then the main method finishes, but the other thread continues working, the app would still be on until all it's threads have died, wouldn't it? Thanks & Merry Christmas! 回答1: Yes, unless it's a deamon thread. Quoting from Thread API: When a Java Virtual Machine starts up, there is usually a single non-daemon thread (which typically calls the method named main of some designated class). The Java Virtual Machine

Inheriting the main method

青春壹個敷衍的年華 提交于 2019-12-06 02:45:31
I want to define a base class that defines a main method that instantiates the class, and runs a method. There are a couple of problems though. Here is the base class: public abstract class Strategy { abstract void execute(SoccerRobot robot); public static void main(String args) { Strategy s = new /*Not sure what to put here*/(); s.execute(new SoccerRobot()) } } And here is an example derived class: public class UselessStrategy { void execute(SoccerRobot robot) { System.out.println("I'm useless") } } It defines a simple execute method, which should be called in a main method upon usage as a

Main method is not static in class error [duplicate]

扶醉桌前 提交于 2019-12-02 16:19:47
问题 This question already has answers here : What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate] (13 answers) Closed 4 years ago . class useTent { Scanner keyboard=new Scanner (System.in); public void main (String[] args) { Tent t= new Tent(); HireContract hc = new HireContract(); ProcessHire(t, hc); } } this is my code, and i keep getting the same error: " Main method is not static in class useTent, please define the main method as: public static

Main method is not static in class error [duplicate]

拈花ヽ惹草 提交于 2019-12-02 11:58:20
This question already has an answer here: What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate] 13 answers class useTent { Scanner keyboard=new Scanner (System.in); public void main (String[] args) { Tent t= new Tent(); HireContract hc = new HireContract(); ProcessHire(t, hc); } } this is my code, and i keep getting the same error: " Main method is not static in class useTent, please define the main method as: public static void main(String[] args) " and when i make the it static i get the following error: "C:\Users\Emma\Documents\opps ass1

工具导航Map