Questions tagged [main-method]

117 questions
3
votes
2 answers

How do I run a main method in a Java Gradle project from command line?

I have a Gradle project (say, MyProject) that has a main method that I only want to use to run a small Java app. Say, the script is in a class and package as follows: MyScript.Java package com.car.ant; import…
aCarella
  • 2,369
  • 11
  • 52
  • 85
3
votes
4 answers

Is it worth to ensure that non-callable Python classes do not get called?

If yes, can you suggest a better way than below? Please elaborate/justify. class X: ... if __name__ == '__main__': # TODO: Should we bother doing this? errorMessage = 'This class is not meant to have a main method. Do not execute…
Hamish Grubijan
  • 10,562
  • 23
  • 99
  • 147
3
votes
4 answers

Error: main class not found

When compiling the program I get the error as Could not find the main class: Solution. Program will exit. The program is: import java.util.*; public class Solution{ public static long[] factors(long a){ long[] b; b=new long[50]; …
harvish
  • 195
  • 1
  • 4
  • 11
3
votes
1 answer

main methods and key listener

Would anyone be able to tell me why this program says I am missing a main method? I have one at the bottom of this code. import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; public class Collision extends…
Martin Marino
  • 375
  • 2
  • 5
  • 14
2
votes
2 answers

How to run a main method method without building the WHOLE maven project in idea?

I have a maven project with many demo classes with their own main methods, they don't dependent on each other. I used to be able to run a class by right clicking on its main method, and select Run MyClass.main(). But now instead of running it, it…
fall
  • 984
  • 11
  • 33
2
votes
2 answers

Java app lifecycle

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…
Albus Dumbledore
  • 12,368
  • 23
  • 64
  • 105
2
votes
2 answers

How to get an element from argv[]

This is C++ At the windows cmd line user types p3.exe X
greg
  • 338
  • 7
  • 17
1
vote
5 answers

Java methods and classes, how do they fit together?

Currently I am writing a program for an introductory Java class. I have two pieces to my puzzle. Hopefully this is a relatively simple to answer question. Firstly, here is what I am trying to use as my main program: import java.util.Scanner; public…
None
1
vote
2 answers

Run a CHILD in Eclipse of which the PARENT class has the main method but the CHILD class itself is just a class without the main method

//Package in which I have both the Parent and the Child class package learningJava; public class MainMethodDemoParent { //Main method of the parent class public static void main(String... args) { System.out.print("This is the…
Amrit
  • 135
  • 1
  • 5
1
vote
2 answers

What is a controller class in Java SE ?

Can someone explain the meaning and the position of a controller class in Java ? Why do we need to put the main method there ?
user10436512
1
vote
3 answers

How can I determine which class's `main` method was invoked at runtime?

I'd like to dynamically determine which class's main method was invoked, in order to allow for an easier to digest combined log file. Currently, a single (rotated) log file aggregates all the log output from a number of daemons, but there is no…
apg
  • 2,611
  • 1
  • 18
  • 19
1
vote
5 answers

How come there is no error if we name args[] as arhs[](or any other name) in java main method?

I'm a beginner in java.When executing a simple program I noticed that in main method public static void main(String args[]) args[] can be given any name and it executes successfully. Why is that?
1
vote
2 answers

Instantiating an inner class within a main method

When we try to instantiate an Inner class (aka: non-static Nested class) in java, say we do that in two cases: 1.in a main method in the same file of the outer Class in which we have two options: (ex:) public class Test1 { class InnerClass { …
Profess Physics
  • 317
  • 4
  • 11
1
vote
1 answer

Repeating the main method

I'm new to java and this forum. I wrote a code for a simple calculator. It's working. But how can I repeat the main method if I (let's say) put "=" instead of "(+, -, *, /)"? Should I use a loop, or something else? Thanks in advance! import…
Un_lh
  • 9
  • 2
1
vote
2 answers

How to create an object of List from another class in main method?

I have to create an Object of List in main Method but i have no idea how to do it. Constructor of class, that i want to create an Object has an List as a parameter. How can i create an Object of CashMachine class? By the way I am not going to write…
user6941415