Jump to content


Photo

Basic Java Question


  • Please log in to reply
2 replies to this topic

#1 Samuz

Samuz

    Advanced Member

  • Members
  • PipPipPip
  • 80 posts

Posted 23 November 2012 - 06:51 AM

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' ?

#2 requinix

requinix

    Transforming Moderator

  • Moderators
  • 6,121 posts
  • LocationWA

Posted 23 November 2012 - 07:40 AM

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.

#3 Samuz

Samuz

    Advanced Member

  • Members
  • PipPipPip
  • 80 posts

Posted 23 November 2012 - 07:42 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com