levo

Defining Data: Types, Variables and Classes

Declaring variables, scope and lifetime

  • 3 things to know
  • AS Unit 1

Overview

Scope of a variable and variable shadowing.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a constant, and how is a constant declared in Java?

Key term

What is variable shadowing, and how is a shadowed attribute reached in Java?

Key term

What two things must every variable declaration give?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a variable?

    Model answer

    A variable is a named area of memory that holds a value of a stated type and whose contents can change while the program runs.

  2. 2

    What two things must every variable declaration give?

    Model answer

    Every declaration must give the data type of the variable and the identifier by which the variable will be known.

  3. 3

    How does declaration differ from initialisation, using int count; and int count = 0; as the examples?

    Model answer

    The statement int count; declares the variable by reserving storage of that type, while int count = 0; also initialises it by placing a first value in that storage.

  4. 4

    What is an identifier, and what three rules must a legal Java identifier obey?

    Model answer

    An identifier is the name given to a variable, method or class; a Java identifier must not begin with a digit, must contain no spaces and must not be a reserved word.

  5. 5

    Why is the declaration int 2ndScore; rejected by the Java compiler?

    Model answer

    An identifier may not begin with a digit, because the compiler would otherwise be unable to tell the start of a name from the start of a number.

  6. 6

    What naming conventions apply to variables and to classes in Java?

    Model answer

    Java names variables and methods in camelCase, beginning with a lower-case letter as in numberOfPupils, and names classes in PascalCase, beginning with a capital as in BankAccount.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Defining Data: Types, Variables and Classes, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.