
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Valid Identifiers in Java
A valid identifier in java -
- Must begin with a letter (A to Z or a to z), currency character ($) or an underscore (_).
- Can have any combination of characters after the first character.
- Cannot be a keyword.
Example
Following example shows various possible identifiers used to declare a variable in Java.
public class VariableTest { public static void main(String args[]) { // Declaring a variable named num int num = 1; int _num = 10; int $num = 100; int num123 = 1000; int NUM = 10000; //Printing the value of the variable num System.out.println("value if the variable num: "+num); System.out.println("value if the variable _num: "+_num); System.out.println("value if the variable $num: "+$num); System.out.println("value if the variable num123: "+num123); System.out.println("value if the variable NUM: "+NUM); } }
Output
value if the variable num: 1 value if the variable _num: 10 value if the variable $num: 100 value if the variable num123: 1000 value if the variable NUM: 10000
Advertisements