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
https://forums.phpfreaks.com/topic/271066-basic-java-question/
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
https://forums.phpfreaks.com/topic/271066-basic-java-question/#findComment-1394594
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
https://forums.phpfreaks.com/topic/271066-basic-java-question/#findComment-1394595
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.