How to avoid this messsage (Static Issues)

Posted on 2004-08-17
Last Modified: 2010-03-31
This is my code:

program A:
public static synchronized Date getToday()
        return new Date();

trying to access from here..

Program B:
piObj.getContmstr().setInituwrtdt(new DateUtil().getToday());

And my "warning" message is this :

The static method getToday() from the type DateUtil should be accessed in a static way.

How can i resovel this issues?


Question by:acl6804
  • 3
  • 2

Expert Comment

ID: 11827486
I'm assuming program A is a class called DateUtil. If so, you can call it like this:


You do not need to use the 'new' keyword when calling a static method. You just use the class name and the method you are calling.

Hope that helps,


Author Comment

ID: 11828579
but if i remove the "new" in the line, i will haev this problem.

"The method DateUtil() is undefined for the type PropInputServlet

** PropInputServlet is the name of my program B.


Accepted Solution

pat5star earned 250 total points
ID: 11828911
Make sure your not writing it as DateUtil().getToday(), it should be DateUtil.getToday(). Also, are you importing your 2nd class? If the class is called DateUtil and is in your package my.package.DateUtil then you need to import it at the top of your page like this:

import my.package.DateUtil;


Author Comment

ID: 11837851
oh.. no wonder.. pat5star, can tell me what happend?

static means no need "new"??

Expert Comment

ID: 11838127
"static means no need "new"??"

Your right. Static methods or fields are like global variables or functions. You only use the "new" keyword when you are creating a new object.


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 182
login form jsp example 2 39
jsp insert to database example 2 47
ejb message driven bean mdb creation steps 2 24
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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

820 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