Learning the Java Language Flashcards

1
Q

Real-world objects contain ___ and ___.

A

state and behavior

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

A software object’s state is stored in ___.

A

fields - je uložený

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

A software object’s behavior is exposed through ___.

A

methods - je odhalené prostredníctvom

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

Hiding internal data from the outside world, and accessing it only through publicly exposed methods is known as data ___.

A

encapsulation - Skrytie interných údajov pred vonkajším svetom a prístup k nim iba prostredníctvom verejne prístupných metód sa nazýva zapuzdrenie údajov.

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

A blueprint for a software object is called a ___.

A

class - Návrh softvérového objektu

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

Common behavior can be defined in a ___ and inherited into a ___ using the ___ keyword.

A

superclass subclass extends - a zdediť do podtriedy pomocou kľúčového slova extends.

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

A collection of methods with no implementation is called an ___.

A

interface - Súbor metód bez implementácie sa nazýva rozhranie.

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

A namespace that organizes classes and interfaces by functionality is called a ___.

A

package

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

The term API stands for ___?

A

Application Programming Interface - Termín API je skratka pre

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

The Java programming language defines the following kinds of variables:

A
  1. Instance Variables (Non-Static Fields)
  2. Class Variables (Static Fields)
  3. Local Variables
  4. Parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Instance Variables (Non-Static Fields)

A

objects store their individual states in “non-static fields”, fields declared without the static keyword. = instance variables, their values are unique to each instance of a class (to each object, in other words); the currentSpeed of one bicycle is independent from the currentSpeed of another.

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

Class Variables (Static Fields)

A

field declared with the static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. A field defining the number of gears for a particular kind of bicycle could be marked as static since conceptually the same number of gears will apply to all instances. The code static int numGears = 6; would create such a static field. Additionally, the keyword final could be added to indicate that the number of gears will never change.

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

Local Variables

A

Similar to how an object stores its state in fields, a method will often store its temporary state in local variables. The syntax for declaring a local variable is similar to declaring a field (for example, int count = 0;). There is no special keyword designating a variable as local; that determination comes entirely from the location in which the variable is declared — which is between the opening and closing braces of a method. As such, local variables are only visible to the methods in which they are declared; they are not accessible from the rest of the class.

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

Parameters

A

public static void main(String[] args) args variable = the parameter to this method. parameters are always classified as “variables” not “fields”.

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

An expression

A

is a construct made up of variables, operators, and method invocations, which are constructed according to the syntax of the language, that evaluates to a single value.

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

The Java programming language is statically-typed

A

which means that all variables must first be declared before they can be used, the variable’s type and name

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

byte

A

is an 8-bit integer, (-128) - 127 (inclusive), for saving memory in large arrays

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

short

A

is a 16-bit integer. -32 768 - 32 767, to save memory in large arrays

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

int

A

is a 32-bit integer, 0 - 231

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

long

A

64-bit integer, The Long class also contains methods like compareUnsigned, divideUnsigned etc to support arithmetic operations for unsigned long.

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

float

A

32-bit floating point, use a float (instead of double) if you need to save memory in large arrays of floating point numbers, not for precise values, such as currency. For that, you will need to use the java.math.BigDecimal class instead.

22
Q

double

A

64-bit; 0,00; For decimal values, this data type is generally the default choice, not for precise values, such as currency.

23
Q

boolean

A

two possible values: true and false, one bit of information

24
Q

char

A

16-bit Unicode character

25
Q

Integer literals can be expressed by these number systems

A

Decimal: Base 10, whose digits consists of the numbers 0 through 9;
Hexadecimal: Base 16, numbers 0-9 and the letters A-F;
Binary: Base 2, numbers 0 and 1;

26
Q

Examples of number 26 in Decimal, Hexadecimal, Binary

A
int decVal = 26;
int hexVal = 0x1a;
// The number 26, in binary
int binVal = 0b11010;
27
Q

example shows other ways you can use the underscore in numeric literals

A

long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;

28
Q

invalid underscore placements in numeric literals

A

float pi1 = 3_.1415F;
float pi2 = 3._1415F;
long socialSecurityNumber1 = 999_99_9999_L;
OK (decimal literal) int x1 = 52; int x3 = 5_______2;
NOT OK int x2 = 52
; int x4 = 0_x52; int x5 = 0x_52;
OK (hexadecimal literal) int x6 = 0x52;
NOT OK int x7 = 0x52
;

29
Q

Array

A

is a container object that holds a fixed number of values of a single(jedneho) type. The length is established (stanovená) when the array is created. After creation, its length is fixed.

30
Q

An element in array

A

is each item in an array and each element is accessed by its numerical index, numbering begins with 0. The 9th element, for example, would therefore be accessed at index 8.

31
Q

a tak ďalej

A

and so forth,

32
Q

// declares an array of integers

A

int[] anArray;

33
Q

// allocates memory for 10 integers

A

anArray = new int[10];

34
Q
// initialize first element in an array
// and print the first element
A

anArray[0] = 100;

System.out.println(“Element at index 0: “ + anArray[0]);

35
Q

an array declaration

A

has two components: type[] and name, the size of the array is not part of its type (which is why the brackets are empty).

36
Q

declare arrays of other types

A
byte[] anArrayOfBytes;
short[] anArrayOfShorts;
long[] anArrayOfLongs;
float[] anArrayOfFloats;
double[] anArrayOfDoubles;
boolean[] anArrayOfBooleans;
char[] anArrayOfChars;
String[] anArrayOfStrings;
37
Q

// create an array of !10 integers

A

anArray = new int[10];

38
Q

// Each array element is accessed by its numerical index

A

System.out.println(“Element 1 at index 0: “ + anArray[0]);
System.out.println(“Element 2 at index 1: “ + anArray[1]);
System.out.println(“Element 3 at index 2: “ + anArray[2]);

39
Q

the shortcut syntax to create and initialize an array

A

int[] anArray = { 100, 200, 300 };

the length is determined by the number of values provided between braces and separated by commas

40
Q

a multidimensional array

A

an array whose components are themselves arrays

41
Q
String[][] names = {{"Mr. ", "Mrs. ", "Ms. "},{"Smith", "Jones"}}; 
// S.o.p. Mr. Smith; Ms. Jones;
A
// Mr. Smith
System.out.println(names[0][0] + names[1][0]);
// Ms. Jones
System.out.println(names[0][2] + names[1][1]);
42
Q

The System class has an arraycopy method to efficiently copy data from one array into another //

A

public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length)

43
Q

The following program, ArrayCopyDemo, declares an array of String elements. It uses the System.arraycopy method to copy a subsequence of array components into a second array:

A
class ArrayCopyDemo {
    public static void main(String[] args) {
        String[] copyFrom = { "Affogato", "Americano", "Cappuccino", "Corretto", "Cortado", "Doppio", "Espresso", "Frappucino", "Freddo", "Lungo", "Macchiato", "Marocchino", "Ristretto" };
    String[] copyTo = new String[7];
    System.arraycopy(copyFrom, 2, copyTo, 0, 7);
    for (String coffee : copyTo) {
        System.out.print(coffee + " ");           
    }
} } output: Cappuccino ,2,3,4,5,6, Freddo
44
Q

Pre tvoje pohodlie

A

For your convenience

45
Q

The term “instance variable” is another name for

A

Non-Static Fields

46
Q

The term “class variable” is another name for

A

Static Fields

47
Q

A local variable stores temporary state; it is declared inside

A

a method

48
Q

A variable declared within the opening and closing parenthesis of a method is called

A

a parameter

49
Q

What are the eight primitive data types supported by the Java programming language?

A

byte, short, int, long, float, double, boolean, char

50
Q

Character strings are represented by the class

A

java.lang.String

51
Q

What is a container object that holds a fixed number of values of a single type?

A

An array

52
Q

Poďme vyriešiť obmedzenú verziu problému, kde potrebujeme nájsť súčet čísel, ktoré sú deliteľné 3.
Na tento účel môžeme použiť predchádzajúci prístup kontroly každého čísla a využiť základnú matematickú vlastnosť.

A

Let us solve the limited version of the problem where we need to find the sum of numbers that are divisible by 3.
For this, we can take the previous approach of checking each number of take advantage of a fundamental mathematical property.