1e_namingVariables.pdf - Naming Variables and Constants Variables and constants need names • When you declare a variable or constant you need to give

1e_namingVariables.pdf - Naming Variables and Constants...

This preview shows page 1 - 6 out of 14 pages.

Naming Variables and Constants
Image of page 1

Subscribe to view the full document.

Variables and constants need names When you declare a variable or constant, you need to give it a name You’ll use that name to reference the stored value throughout your code
Image of page 2
Rules for naming variables Java has rules for valid identifiers for variables and constants Identifiers may contain only Letters Digits (0 through 9) The underscore character (_) Identifiers cannot be reserved words in Java These appear in blue in the syntax highlighting in NetBeans The first character cannot be a digit Otherwise, Java thinks this is a literal number, not a variable or constant name
Image of page 3

Subscribe to view the full document.

BE CAREFUL! Java is Case-Sensitive Case-sensitive means that Java distinguishes between UPPER-case letters and lower-case letters Therefore, all of the following are different variables So, be careful when you type your variable names! Make sure you spell it exactly the same way every time!
Image of page 4
How should you choose a name?
Image of page 5

Subscribe to view the full document.

Image of page 6
  • Winter '15
  • AlfredCastillo
  • Mathematical constant

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes