Really simple: how to call a class from another class

L

Loic

hello

sorry but it's been a long time since I programmed in java and have
had a mind block. I have a separate class in the same program folder,
called decode.java and I want to send it a string from the main class
which is called read.java. The main method in decode.java is expecting
a string:

public static void main(String binarydata){
//code
}

so what do I do in read.java to send it this data?

sorry for my ignorance!
 
H

Heiner Kücker

Loic wrote
sorry but it's been a long time since I programmed in java and have
had a mind block. I have a separate class in the same program folder,
called decode.java and I want to send it a string from the main class
which is called read.java. The main method in decode.java is expecting
a string:

public static void main(String binarydata){
//code
}

so what do I do in read.java to send it this data?

This will not work.

Write
public static void main( String[] args )
{
if ( args.length > 0 )
{
System.out.println( args[ 0] );
}
}

The Parameter in String array args is the command line parameter.

java xxx Test

Or set the command line parameter in your ide run options.

Heiner Kuecker
Internet: http://www.heiner-kuecker.de
JSP WorkFlow FlowControl Navigation: http://www.control-and-command.de
Expression Parser: http://www.heinerkuecker.de/Expression.html
 
J

Johan Poppe

Loic skrev:
hello

sorry but it's been a long time since I programmed in java and have
had a mind block. I have a separate class in the same program folder,
called decode.java and I want to send it a string from the main class
which is called read.java. The main method in decode.java is expecting
a string:

public static void main(String binarydata){
//code
}

so what do I do in read.java to send it this data?

You call the method with a string as argument.

decode.main("100001100010");


A few other things:
- The classnames for your classes are not decode.java and read.java,
but just decode and read. decode.java and read.java are the names of
the files containing the source code.
- The most common Java naming conventions in java is to capitalize
class names, ie. Decode and Read.
- Calling the static main method of other classes is a somewhat
peculiar design. It's not wrong, but it's a bit strange.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top