Samuz Posted November 23, 2012 Share Posted November 23, 2012 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' ? Quote Link to comment https://forums.phpfreaks.com/topic/271066-basic-java-question/ Share on other sites More sharing options...
requinix Posted November 23, 2012 Share Posted November 23, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271066-basic-java-question/#findComment-1394594 Share on other sites More sharing options...
Samuz Posted November 23, 2012 Author Share Posted November 23, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/271066-basic-java-question/#findComment-1394595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.