Unit 3 - Programming classes in Java Flashcards

Goals: – what elements are required to run and program Java applications. – which basic elements a Java class consists of and how to program them in Java. – how attributes of classes are programmed in Java. – how methods of classes are programmed in Java. – how to specify what a Java program should execute when it starts.

1
Q

What are the 3 activities of programming?

A
  • programming: the production of program code
  • compiling: automatic translation of program code produced into a form that can be executed by a computer
  • executing a program: starting and running the generated and compiled program code to see whether the system perform as expected
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How is Java different from other programming languages?

A

It can run on virtually every operating system, because it uses Java runtime environment (JRE). Java compiler translate programmed source text into bytecode. The bytecode is then loaded, started and executed by the Java runtime environment.

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

What is the Java runtime environment (JRE)?

A

Java runtime enviornment is required to run a Java program as a user. It consists of the Java virtual machine (JVM) and the class library.
The JVM is responsible to interpret the bytecode and both starts it and runs it on the operating system.
The Java class library provides functions that are already part of Java programming language, so that commonly used data structures can be reused.

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

What is a Java software development kit (Java SDK)?

A
  • basic tool for Java developer
  • includes a compiler, which generated bytecode and JVM for running Java programs.
  • is required to develop with Java
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the basic elements of a class in Java?

A
  • Visibility modifier: defines the visibility of the class for other classes
  • Keyword for the class declaration: indicates to the Java compiler that a Java class is programmed in the following
  • Class name: defines the name for the class and is used as a file name
  • curly brackets: marks the contents of a class (attributes and methods); everything inside the braces belongs to a class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the naming restrictions for Java classes?

A
  • Begins with an upper case letter
  • Consists of Unicode characters (with restrictions, e.g., no empty characters, no umlauts)
  • Can theoretically be of any length (only limited by the maximum length of a file name)
  • Cannot be a keyword (e.g., class or public)
  • If the class name contains multiple words, these are combined without separator (e.g.,
    WordWord, NameOfClass)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the basic elements of a attribute in Java?

A
  • Visibility modifier: defines the visibility of the attribute for other classes
  • data type: defines the data type of the attribute and thereby determines the number and type of values that can be stored in the attribute
  • attribute name: defines the name of the attribute of the class, each name can only be assigned once inside a class
  • default value: defines the initial value of the attribute; this value is assigned to the attribute when creating an object of the class
  • semicolon: marks the end of the attribute declaration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the basic elements of a method on Java?

A
  • Visibility modifier: defines the visibility of the attribute for other classes
  • return data type of the method: defines the data type of the object in which the result of the method is output after processing the method body
  • method name: defines the name of the method, method name can be used more than once
  • parameter list: list of required objects and their data types which are needed for processing the method; if no parameters are defined, the list remains empty
  • method body: contains the specific statements for what is done when the method is invoked and in what order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a method signature?

A
  • can uniquely identify a method, it consists of the name of the method and the parameter list
  • return type is not part of the signature
  • each signature can only occur once in a class since only then can the JRE determine which method should be invoked and processed at the runtime of the program
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are getter and setter methods?

A

They are used for writing and reading attributes. A getter method returns the value of an attribute and a setter method changes the value of an attribute to the value that is passed as a parameter to the setter method.

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

What is method overloading?

A

It means that there are methods in a class with the same name. With this you have the ability to define various method behaviors based on the give parameters

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

What is the main method?

A

It is the fixed starting point for each Java program. The generation of all the objects that are required by the program start inside this method.

It contains the following elements:
- visibility modifier
- declaration of the main method as static method
- specification that there is no return type
- name of method
- parameter list

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