This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Variable type question? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variable type question?" Watch "Variable type question?" New topic
Author

Variable type question?

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Hi Friends,
If strSubmittedDate is Date type so is it the way that I can define it?
Date strSubmittedDate=" ";
Am I right? and Date will call "Variable type?"
Thanks,
Elahe


Thanks,
Elahe
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi elahe,
For initialization of an object you have three choices:
1. Assign it to another of the same type
Date submittedDate = anotherDate;
2. Assign it to null
Date submittedDate = null;
3. Assign it using the new operator.
Date submittedDate = new Date();
Regards,
Manfred.
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Thank you Manfred got it
and also are these two lines correct?
Date today=new Date();
dSubmittedDate = today;
thanks,
Elahe
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
and as you said so this variable type for dSubmittedDate is correct right?
try
{
int nBugNumber=0;
Date dSubmittedDate=null;
int userID=0;
String strContact=" ";
....
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
So what you have done with this code is to create a variable of type Date with the name dSubmittedDate, but the variable is not referencing ANY object at this time.
[ April 17, 2002: Message edited by: Cindy Glass ]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Now I defined dSubmittedDate and all related field in Date type but why I am getting this error?
Thanks,
Elahe
No method found matching setSubmittedDate(Date)
oBug.setSubmittedDate( dSubmittedDate );
^
1 errors
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Because dSubmittedDate is null. It is not pointing a a Date object yet.
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
But base on my code I put current date on it please have a look to my code:
Thanks,
Elahe
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
I compiled it but still I am getting this error?
Highly appriciate for any advice.
Elahe
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
And where in Bug is the code for the method
setSubmittedDate( Date d );
Can you show us that code?
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Cindy I didn't get exactly your question since I don't have such a code in my program. I hope I can answer this way...
Here is my whole code:
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You have a line of code:
Bug oBug = new Bug();
which means that you are constructing a variable of type "Bug" named oBug.
There is no class in the Sun API named Bug. Therefore YOU or your friends must have the code for that class. The compiler is saying that the code for the Bug class does not have the method that you requested.
Since WE can't look at the code for Bug - YOU will have to look.
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Thank you for the clarification. Yes I have a class with the name of Bug and the reason it is not in my program and I just call it because I used MVC method to refactor my code...
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
And I found my answer just I need to put "java.sql.Date " in front of SubmittedDate=null
in my code.
...
int nId =0;
int nBugNumber=0;
java.sql.Date dSubmittedDate=null;
String strFixedDate=" ";
int userID=0;
String strDesc=" ";
...
Thanks,
Elahe
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

Elahe:
just a suggestion: Since working on problems with you in various forums, I noticed that you use Date objects a lot but never specify which Date object you really want. What I mean is that if you have "import java.util.*;" and "import java.sql.*;" then you create a date objectwhich Date??? a java.util.Date or a java.sql.Date? I know from experience that a java.sql.Date does not have an empty constructor, but I still had to look at the docs to make sure! You will avoid confusion for the person that has to maintain your code(and for yourself!) by using the fully qualified name:
cheers, Jamie
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Very good notice thank you so much for your attention, So Jamie I have to choose one of them right? java.util.Date Or java.util.Date
Elahe
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
I am sorry I mean or java.sql.Date
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Variable type question?