main

Why main method is static in java [duplicate]

拜拜、爱过 提交于 2019-12-21 03:37:16
问题 This question already has answers here : Why is the Java main method static? (37 answers) Closed 2 years ago . I have heard some people saying " if main is not static then JVM could create an object of class containing main and call that main through object. But the problem is how JVM knows which constructor to call in case of overloaded constructors or even if there is only one paramaterized constructor, then what to pass." Is that the correct reason? Because how can object of class be

In C, main need not be a function?

感情迁移 提交于 2019-12-20 10:37:24
问题 This code compiles, but no surprises, it fails while linking (no main found): Listing 1: void main(); Link error: \mingw\lib\libmingw32.a(main.o):main.c:(.text+0x106) undefined reference to _WinMain@16' But, the code below compiles and links fine, with a warning: Listing 2: void (*main)(); warning: 'main' is usually a function Questions: In listing 1, linker should have complained for missing "main". Why is it looking for _WinMain@16? The executable generated from listing 2 simply crashes.

PHP equivalent of Python's __name__ == “__main__”?

≡放荡痞女 提交于 2019-12-20 09:15:54
问题 As per the title, is there PHP equivalent of __name__ == "__main__" ? Is there something that would work for both scripts executed through the command line and through a web request, or would a custom function be needed? For those unfamiliar with Python, __name__ == "__main__" allows you to define a module file, and also have some things that allow you to run it if it is the entry point. The equivalent structure in PHP would resemble this: // SomeClass.php <?php class SomeClass { function

Why doesn't the main method run?

梦想的初衷 提交于 2019-12-20 07:31:37
问题 A bit confused about the public static void main method in Java and was hoping someone could help. I have two classes public class theGame { public static void main(String[] args) { lineTest gameBoard = new lineTest(); } and public class lineTest extends JPanel { public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(Color.red); g2d.drawLine(100, 100, 100, 200); } public static void main(String[] args) { lineTest points = new lineTest()

Error in Eclipse - Mainclass not found

风流意气都作罢 提交于 2019-12-20 05:44:19
问题 I'm new in programing and I like it pretty much. I've just downloaded Eclipse and I got an error I can't help me with. Unfortunately it's in German but the meaning is something like: "Main class not found" - "Fehler: Hauptklasse konnte nicht gefunden oder geladen werden" I understand that it has something to do with " public static void main(String [] args) ". Due to the fact that this is totally new to me it would be cool you could assist me. Below the error source code; /** * Write a

Java - Cannot find symbol constructor

点点圈 提交于 2019-12-20 03:33:20
问题 I'm completely new to Java, so I'm sorry if my question is dumb. Im working on this assignment, and I've been reading about main methods for hours now, but I just cant figure it out. I put some of my code below. I might be way off here, but what I'm hoping to accomplish is to get the main method to start the constructor, but when I compile I get an error saying "cannot find symbol - constructor Player". Now, Im guessing this has something to do with the string parameters of the constructor,

Passing variables from Main function to another C# class

血红的双手。 提交于 2019-12-20 01:43:19
问题 I'm beating my head against the wall pretty severely with this. I have several variables inside a C# console application that I would like to re-use. However, I cannot for the life of me re-use the variables in another class. I would love any help or pointers you could provide - I've searched for quite some time and I'm completely stumped. EDIT: Yes, the variables are inside my Main function. Sorry for leaving this out. EDIT: Heavily redacted code below. The variable values I'd like to re-use

One JFrame opening another

☆樱花仙子☆ 提交于 2019-12-19 09:48:12
问题 I have a JFrame and JPanel full of Jsomethings with an actionlistener. When the user clicks an object I want to open another JFrame. Here is what I did: public void actionPerformed(ActionEvent e) { Object source = e.getSource(); if (source == rejectionbutton){ RejectApp ra = new RejectApp(); ra.main(null); } } (RejectApp calls a new JFrame.) So another JFrame opens on the screen with more options. It works OK (so far), but I want to know is this standard? I mean calling the main method like

Multiple classes in a single Java file, each with a main method - unexpected behavior?

末鹿安然 提交于 2019-12-19 09:07:11
问题 I have got the following code in a file called test.java which is located inside the directory C:\D\JavaProjects class test { public static void main( String[] str ) { System.out.println( "Hello, World! from test" ); } } class Test { public static void main( String[] str ) { System.out.println( "Hello, World!" ); } } When I do "javac test.java" it outputs test.class. Now, if I do "java test" I get the following output: Exception in thread "main" java.lang.NoClassDefFoundError: test (wrong

is this overkill for assessing Main(string[] args)

无人久伴 提交于 2019-12-19 06:04:28
问题 I've got the following and was wondering if the initial test is overkill: static void Main(string[] args) { if (args.Length == 0 || args == null) { //do X } else { //do Y } } in other words what I'm asking is are there possibilities of args.Length being zero, or args being null....or would just one of these conditions sufficed? 回答1: Well, Main is defined to never ever ever ever be called with a null parameter. If it does somehow receive a null parameter, then your environment is so broken