Call function from another java file

Posted on 2003-03-31
Medium Priority
Last Modified: 2008-03-10
Hi all..

I'm new to java programming and i need your help to solve my problem..

if i have a file hello.java as below,

public class hello
  public static void main(String[] args)
  {    //do nothing - this will keep us from getting a compile error

   public static String SayHello(String name)
  return "Hello " + name;

how can i call SayHello function from another java file? let's say from file CallFunction.java hehe can i actually do this? can u give me any example?

thankss :)
Question by:pipinana2002
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

yongsing earned 80 total points
ID: 8242935
Just call hello.SayHello() like this:

public class CallFunction {
  public static void main(String args) {

Author Comment

ID: 8242964
Hi yongsing.. thanks so much for your reply :)

but why when i want to run the CallFunction.java, I always got this error:

Exception in thread "main" java.lang.NoSuchMethodError: main

hope u can help me.. tks :)

Author Comment

ID: 8243004
hi yongsing..

hehehe i solve the probs already.. tks so much for your help :) hehehe really helps me.. coz i've been looking through the internet n cannot find the answer :)

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn different types of Android Layout and some basics of an Android App.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question