{ "@context": "https://schema.org", "@type": "Organization", "name": "Brainscape", "url": "https://www.brainscape.com/", "logo": "https://www.brainscape.com/pks/images/cms/public-views/shared/Brainscape-logo-c4e172b280b4616f7fda.svg", "sameAs": [ "https://www.facebook.com/Brainscape", "https://x.com/brainscape", "https://www.linkedin.com/company/brainscape", "https://www.instagram.com/brainscape/", "https://www.tiktok.com/@brainscapeu", "https://www.pinterest.com/brainscape/", "https://www.youtube.com/@BrainscapeNY" ], "contactPoint": { "@type": "ContactPoint", "telephone": "(929) 334-4005", "contactType": "customer service", "availableLanguage": ["English"] }, "founder": { "@type": "Person", "name": "Andrew Cohen" }, "description": "Brainscape’s spaced repetition system is proven to DOUBLE learning results! Find, make, and study flashcards online or in our mobile app. Serious learners only.", "address": { "@type": "PostalAddress", "streetAddress": "159 W 25th St, Ste 517", "addressLocality": "New York", "addressRegion": "NY", "postalCode": "10001", "addressCountry": "USA" } }

Learning Unit 2 Programming Theory Flashcards

(54 cards)

1
Q

In Java

A

Each variable has a data type.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Data types commonly used:

A
  • Integers (whole numbers)
  • Real numbers (numbers with decimals)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Important to tell Java what data type a variable will be so

A

It knows how much space in memory to allocate for each variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

For input

A

showInputDialog method of JOptionPane class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

= means

A

It gets the data or is assigned a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Strings

A

Are enclosed in double quotes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

String is

A
  • A class
  • An object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

All classes start with

A

A capital letter.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

A variable can be

A

Joined/concatenated to a text String using a + (plus) sign.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Assignment statement contains

A

An equals sign.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The subject variable

A

Has been assigned (or gets) a value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

The value that is assigned

A

Has been produced (returned) by the showInputDialog method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The 2 main types of variables used in Java

A
  • Primitive data type
  • Object reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Difference

A

Objects are stored differently in memory to primitive data types and different behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

No real difference between

A

The way the primitive and objects are declared (must specify type and give variable a name).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Several variables of same type

A

Can be declared at the same time (use of commas).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

After the variable has been declared

A

It must be initialized.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

If you use a variable without initializing

A

The compiler generates an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

The only object that can be declared & initialized like primitive types

A

Because it is so commonly used in programs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Important to declare variables once

A

Cannot be 2 boxes in memory with the same identifier.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Ever variable has 3 characteristics:

A
  • Identifier/name
  • Data type: Stating what type of data can be stored in it.
  • Value that is stored in it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

In a program every variable that is used must be:

A
  • Declared (created) given a identifier and a data type.
  • Given a value: This is done using assignment statement.
23
Q

String data is text data

A

That cannot have arithmetic calculations carried out on it.

24
Q

To input numbers

A

Convert the data from a string to an integer or real type.

25
Strings are enclosed in double quotes
So that Java identifies the data type and knows what operations can be performed on it.
26
String cannot be placed in a variable type int
As the are incompatible types (they are not stored the same way in memory).
27
+ Operator can perform different functions (joining or adding)
Depending on the types of the variables or values on either side of the + sign.
28
int is not a class but
Is one of the primitive data types.
29
Long ago programmers stored real numbers as either
Single precision or double precision (single or double for short).
30
Double precision could
Store real numbers more accurately, therefore double type remained.
31
Integers are
A sub-set of real numbers.
32
Simple assignment operator is
=
33
Direction of assignment
Right hand side of = to left; variable on left changes.
34
Java expects
A single variable on left-hand side.
35
Compound operator
Uses double symbols.
36
The computer works out arithmetic expressions in this order
First: Brackets Second: *,/ (integer and real division), % Third: +, -
37
Variables can be declared
At the beginning of a method/the first time they are used in a program.
38
Useful to declare variables at the beginning of method
Gives a summary of variables that are going to be used in the method.
39
It is essential
To follow the rules for identifier names.
40
Conventions make your program
Readable for other people and easy to understand.
41
Rules for variable names/identifiers
- Can contain numbers but may not start with a number. - Spaces are not allowed. - No special characters may be used. - Reserved words (keywords that have a special meaning in Java) may not be used.
42
By convention
- Identifiers of variables and methods in Java start with lowercase letters. - Identifiers that are names of classes start with a capital letter. - Identifier should reflect the contents of the variable, method/class. - Any identifier that contains more than one word must have the words joined together using camel case, to make identifiers more readable.
43
Eg. of primitive data types
- int - double - char - boolean - byte - short - long
44
Char variable in Java is
- Enclosed in single quotes - Represented with Unicode instead of ASCII code.
45
First 127 characters of
Unicode and ASCII are the same.
46
Values can be assigned
To variables in a program in an assignment statement.
47
Java provides
Addition (+), subtraction (-), multiplication (*) integer and real division (/) and modulus (%).
48
Plus operator is overloaded
Can add numbers together and join strings.
49
Subtraction and multiplication
Perform as expected, not overloaded.
50
Division can be used with integer and double
Produces different results depending on the type of data in which it is used.
51
Java has a mod operator
Depicted with a % sign
52
DIV (integer division) and division operator
Depends on types you are working with.
53
int/int =
(Integer division) int and remainder is ignored.
54
(Real division) real
As long as one of the numbers in the division is declared as double, ans. will be real and should be assigned to variable declared as double.