Questions tagged [main-method]
117 questions
-1
votes
1 answer
Why Are the Instance Variables Declared in the Main Method?
I'm learning Java on Codecademy and recently completed a project that calculates monthly payments for a car loan. The problem is that I don't understand the solution, and no one has responded to my question about it on the Codecademy forum.
Why are…

smlisk0630
- 15
- 3
-1
votes
1 answer
C-Problem: How do I pass a main method argument to a string variable of the method?
I want to use a given string (given as console app argument) within the main-method and don't know how to assign the console app argument to a string variable which is declared and used in the main method:
console:
~/substitution/ $ ./test…

ALL
- 9
- 1
- 6
-1
votes
5 answers
What is the difference between a constructor and a main method?
I've been using C# for a little while now, but mostly in Unity. I've only recently started just simply writing C# code in Visual Studio.
I was simply playing around with implementing a Queue with an array and was doing a bit of research into…

Tom Ryan
- 397
- 2
- 6
- 26
-1
votes
7 answers
no method main - but main is there?
class TapeDeck {
boolean canRecord = false;
void playTape() {
System.out.println("Tape Player");
}
void recordTape() {
System.out.println("Tape Recording");
}
}
class…

NelPerry
- 1
-1
votes
1 answer
Exported runnable Java program does not work with main method
I created a small game from my Java book of exercises, when I compile it in Eclipse it runs fine, but once I add the main method and export it as a .jar onto my desktop it does not work when I double click it, neither does it work on the command…

Pav
- 57
- 9
-1
votes
2 answers
How to test my program from the main method JAVA
I am new to Java. I would like to test the methods available in the Calculator. What could be the most efficient way you could test this?
package BeginnerLevel;
import java.util.Scanner;
public class Calculator {
This is the…

Klayd Pro
- 1
- 1
- 2
- 7
-1
votes
2 answers
How to use main method in method overriding?
I have just started learning Java and I am learning method overriding. I am getting an error in a program while trying to run it in eclipse. The program is as follows:
class Vehicle{
void run(){System.out.println("Vehicle is running");}
} …

Rahul
- 9
- 4
-1
votes
1 answer
Calling a static method on an abstract class outside the main method
This program works with no problems
public class Test{
static int DAY_IM = 1000*60*60*24;
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
c.set(2004,0,7,15,40);
long day1 = c.getTimeInMillis();
for…

covans
- 41
- 9
-1
votes
1 answer
Server/Client Running with command line
I have a question regarding server/client running on the command line. The server should be run something like this
Server should run with a command line passing port number
java Server port_number
Client should run with command line as following…

j doe
- 83
- 1
- 7
-1
votes
1 answer
How to access variable in main method from actionlistener
I have three classes that are concerning me at this point: a Car class, CarGUI class, and actionlistener. I want to create a new instance of a Car class and have it referenced in the actionlistener. When I declare it outside of the main method,…

R Mason
- 1
- 2
-1
votes
2 answers
Why are (String[] args) not used as main method arguments in BlueJ?
I've been using the Java IDE - BlueJ but I can't understand why the main method cannot be defined as
public static void main(String[] args)
in it. I get a syntax error when I try it.

Srirag vu
- 72
- 1
- 7
-1
votes
3 answers
How to return string with error "void method cannot return a value"?
I turned a codingbat warmup exercise into a program on Eclipse. The exercise calls to take the last char of a word and tack it onto both the front and end of a word, e.g. "cat" → "tcatt."
First attempt:
I started with this set of code and received…

user9503053
- 107
- 3
- 15
-1
votes
1 answer
Error: Main method not found in class... why am I getting this?
Before people start flagging this question as a duplicate, know that I took the time too look at similar questions, and found that the answers to other "Error: Main method not found in class..." were not clearly applicable to my situation (according…

Patrick
- 87
- 1
- 7
-2
votes
1 answer
Difference of args vs arg in main-method, java?
Why does
" public static void main(String[] arg) { "
work instead of
"public static void main(String[] args) { " ?
Does it have anything to do with the String-Array?
And how exactly does it work?
May using "arg" instead of "args" just be a tiny bit…

flyingcyclops
- 1
- 1
-2
votes
1 answer
I want to use main variable(Scanner) in another method
import java.awt.*;
import java.awt.event.*;
import java.util.Scanner;
class Graph_mod extends Frame {
public static void main( String[] args ) {
Scanner input = new Scanner(System.in);
System.out.println("enter v :");
double v =…

이석준
- 3
- 2