Overview:
Today I am going to discuss Variables and Constants here w.r.t JAVA. Please note that the definition of Variables and Constants is same for all languages so, whatever I tell here is not just limited to JAVA i.e you can apply it in any language the only syntax will change.
Let me start with Variables.
What are Variables?
It is a name given to a memory location where value can be out. A variable can hold only a single value at a time.
Syntax:
data_type variable_name; int a; float b; char c;
Value of a variable can change during execution of the program.
What are Constants?
Its value never changes during execution of the program.
to define a constant final keyword is used
Example:
final int A = a;
NOTE: A is a constant and it must be uppercase.
What are Identifiers?
It is a name given to a variable or constant or method or class.
Rules for Identifiers:-
- It can be a combination of alphabets (a-z, A-Z) or digits (0-9) and a special character '_'.
- Identifier name can begin with either alphabet of underscore only.
- space should not be given in identifier.
Examples:
Identifier | Comment |
a_b_c | correct |
abc | correct |
Abc | correct |
2abc | wrong |
@ab | wrong |
a b c | wrong |
a2b | correct |
a_2b | correct |
What is Data Types?
It specifies the type of data to be stored in a variable.
Data Types can be Predefined (or Library or Primitive) and User defined
Data Type | Comment |
boolean | |
byte | 1 byte |
char | 2 bytes |
int | 4 bytes |
float | 4 bytes |
double | 8 bytes |
Do you have questions in your mind or just need Help?
You can ask your questions here at https://thesmartware.com/ and get it answered or helped out within hours. that's it!
SignUp Now to Get FREE Access to our All in One Digital Marketing Platform!
We will continue to update Front; if you have any questions or suggestions, please contact us!
Follow us on Facebook, Instagram, Twitter, Pinterest, Linkedin, YouTube, and Medium.
erbhaveshkumar123
I create advanced website builders made exclusively for web developers.
3 Comments
As a Special Education teacher this resonates so well with me. Fighting with gen ed teachers to flatten for the students with learning disabilities. It also confirms some things for me in my writing.
ReplySince our attention spans seem to be shrinking by the day — keeping it simple is more important than ever.
ReplyPost a comment
Stay in the know
Get special offers and the latest news updates from ElanceMarket™.