Jump to content

Basic Java Question


Samuz

Recommended Posts

Hey guys, i'm at university and we've been given a piece of practical work that I need a little help wiith.

 

I'm coming from a PHP background so I understand OOP and the concept etc.

 

Unlike PHP, in java you have to specify the data type of the variable or 'field' your setting.

 

e,g

 

private int cost;

 

And that seems right to me, because I understand 'int' is a java keyword and it lights up in my IDE.

 

But what if I needed the data type of that variable to be a string or time (as specified in my course)? 'String' or 'Time' doesn't seem to be a keyword in java because the keyword 'String' or 'Time' doesn't light up as it would do for 'boolean', 'char', 'int' etc.

 

So how would I set a variable or 'field' with the data type 'String' ?

Link to comment
Share on other sites

They "light up" because they're keywords.

 

Java has strings but they're a class: java.lang.String. Try importing that package first, then using the String datatype. As for Time I don't think there is one dedicated to that but you can probably use java.util.Date just fine.

Link to comment
Share on other sites

They "light up" because they're keywords.

 

Java has strings but they're a class: java.lang.String. Try importing that package first, then using the String datatype. As for Time I don't think there is one dedicated to that but you can probably use java.util.Date just fine.

Thanks for your reply, just realized 'Time' was referring to a custom Time object I had created previously.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.