main

Why the out put of below code is Thread[main,5,main]

余生长醉 提交于 2019-12-02 13:22:01
public class test1 { public static void main(String[] args) { // TODO Auto-generated method stub Thread t = Thread.currentThread(); System.out.println(t); } } Why the output of above code is - Thread[main,5,main] ? Please Explain Because thread.toString() returns a string representation of this thread, including the thread's name, priority, and thread group. Returns a string representation of this thread, including the thread's name, priority, and thread group. Source: https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#toString() Because of: /** * Returns a string representation

Why doesn't the main method run?

孤街浪徒 提交于 2019-12-02 12:20:43
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(); JFrame frame = new JFrame("Points"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add

c++ class why need main?

冷暖自知 提交于 2019-12-02 09:24:56
问题 Hello I'm writing a little project in c++ where I would like to have some classes that does some work, I wrote the interfaces and the implementation of the classes. The thing that surprises me is that I cannot have a simple class without a main(), I would like to have a class that once instantiated, It's methods can be called, do things, but I don't need (nor want) a main() in the class implementation. Here's an example I have in my head of what I'd like to have: file animal.h: class animal {

C++: Easiest way to access main variable from function?

吃可爱长大的小学妹 提交于 2019-12-02 08:51:56
I'm currently dealing with a string initialized in main() that for some reason freaks out (it becomes a string of non-characters) if I try and make it global. I'm wondering whether I can have a function declared in the program access this variable... the function itself will only ever be executed in main or functions called from main, but the compiler doesn't see the variable name until main() is reached. Here is a skinny version of the relevant code: string getCommand(int input_pos,string inputstring) { int temp_paren=0; int begin_pos = stdinstring.rfind("(",input_pos); int len = 0; while

What Exacly (args.length>0) means?

那年仲夏 提交于 2019-12-02 08:11:35
This may be simple to you people but as i am new to java, so i want know actually what is going on in the following part? if (args.length > 0) { file = args[0]; } public class DomTest1 { public static void main(String[] args) { String file = "test1.xml"; if (args.length > 0) { file = args[0]; } } } Those are called command line arguments , which you get as a String array in your program. Here is the Oracle tutorial A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched. The user

Use “*” as argument of function main()

懵懂的女人 提交于 2019-12-02 07:37:46
问题 When I want to use * as an argument of function main() , the shell will expand it to the all files in the current directory. How to avoid this? int main(int argc, char *argv[]) { printf("%d\n", argc); for(int i=0; i<argc-1; i++) { printf("%s \n", argv[i]); } printf("\n"); } On the command line, it will output: atlas@localhost ~/D/P/C> ./expr 2 3 4 + * 13 ./expr 2 3 4 + Command.c Readlines.c catlas.h expr expr.c find find.c 回答1: The * is a special wildcard used in shell context. The shell will

Main method not found in class/illegal start of expression

喜你入骨 提交于 2019-12-02 07:04:18
I am new to all of this and really only have a basic understanding of coding in general. I am actually trying to use a java code that was published in ChemMedChem (dx.doi.org/10.1002/cmdc.200900317 in the supporting information) i have all the appropriate programs/jar files they use (from ChemAxon) i am able to copy the code and compile it to a class file with no issues: javac -classpath C:\jarfolder\MarvinBeans-plugin.jar;C:\jarfolder\MarvinBeans.jar; MQN.java though i do get: Note: MQN.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. Then when it

C++ | main function error | beginners [duplicate]

只谈情不闲聊 提交于 2019-12-02 06:48:21
问题 This question already has answers here : What should main() return in C and C++? (17 answers) Closed 2 years ago . I'm totally new with c++ and I'm using eclipse. but... I don't know why I get this error at the main function: ERROR: ::main must return int My code is: void main() { char a; while (a!='q') { string ln = "enter option: "; cout<< ln; switch(a) { case 1: if (a=='1') func1(); break; case 2: if (a=='2') break; break; } } } 回答1: Because in C++, the main function must have a return

C# - Calling a function from static main

我们两清 提交于 2019-12-02 06:46:55
my question is probably very basic but I did not find an answer... I wrote a function (public checkSomething that gets 2 strings) in program.cs when I tried to call this function from static main I got this error: "An object reference is required for a non-static field, method or property 'checkSomething(string,string)' ". However,when I changed my main to Public (and not static)- there is no error. Why this happen? What is better - to have a Static main or not? Why would it even matter? thanks! The question here is not about static functions, but specifically why is main static in a C#

Error in Eclipse - Mainclass not found

≯℡__Kan透↙ 提交于 2019-12-02 06:38:01
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 description of class Light here. * * @author (Sunny) * @version (31.01.2014) */ public class Elevator { //