Beginning Java Flashcards

Learn all the things.

1
Q

What are Java packages used for?

A
  • Java packages are used to bundle related functionality and programs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is this called? %s

A
  • That is a format specifier.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why would you use %n instead of \n for a new line?

A
  • The reason for this is that Windows and Unix based systems (Like Mac and Linux) use different newline sequences. %n makes the proper distinction.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The exit method takes an argument for the status code as shown below. What does 0 mean?

  • System.exit(0);
A
  • The 0 argument means that the system exited intentionally.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Primatives have special characteristics about the type of data that they can store, no methods or properties. What are the eight primative data types with Java?

A
  • int
  • double
  • long
  • byte
  • char
  • float
  • short
  • boolean
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Converting an integer to a string is also called what?

A
  • Parsing an integer out of a string.
  • Switching between types like this is also called casting.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Look at the text below, what is Integer? What is parseInt()?

  • int x = Integer.parseInt();
A
  • Integer is a class
    • This is also known as a wrapper or a boxed type.
    • It provides methods for us to use.
  • parseInt() is a static method of the Integer class.
  • Here we are using the Integer class’ static method of parseInt() to generate a primative int.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does REPL stand for?

A
  • Read Eval Print Loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What two things do all real world objects have?

A
  • State and Behavior
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a blueprint used to create objects in Java?

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

What is special about the System class?

A
  • The System class is automatically imported into a Java application.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does the System class provide to enable a developer to output information to the console? What is that thing called?

A
  • It provides a static public field called out.
    • System.out
  • out is a print stream and it exposes some methods that we have seen before for example: println.
    • System.out.println(“This is an example.”);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a variable called that is defined in the scope of a class definition?

A
  • A field or member variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you mark a field or member variable as private?

A
  • Put the private keyword before the type declaration.
  • Example:
    • private String name = “Bob”;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the most common way of exposing a class value, but not let someone set it?

A
  • Add a method to your class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are methods called that are used to get the state or field value of a class object?

A
  • Getters.
17
Q

What are methods called that are used to change the state or set a field value?

A
  • Setters.
18
Q

Why is a public method like a “getter” able to access a private field value?

A
  • A public method is able to do so since it is defined within the scope of the class.
19
Q

What is a constructer?

A
  • A constructer is a method that will run when you instantiate the class.
  • It is also a great place to input information that can be used for initial creation of the object.
20
Q

When does instantiation happen?

A
  • Instantiation happens when you create a new instance of the class, using the new keyword.
21
Q

How do you know that a method is in fact a constructer?

A
  • It has the same name as the class and there is no return type.
22
Q

What is the structure of a method?

A
  • access level modifer - Data Return Type - method name - parameters
  • Example:
    • public String exampleMethodName(String parameterExample)
23
Q

What happens if no constructor is defined?

A
  • A default constructor that takes no parameters is assumed and used.
24
Q

When using a constructor to set the values of a member variable the name of the variable passed into the constructor should be the same as that of the member variable that it is updating. How is confusion about the variable that is passed in and the actual member variable avoided?

A
  • By employing the keyword this within the definition of a method or constructor.
  • The variable which is prefixed with this is referring to the member variable.
  • Example:
    • this.characterName = characterName;
  • Alternatively some people use a different coding style and instead of this they prefix the member variable name with an m.
    • mCharacterName = characterName;
25
Q

What do you do when you want a variable to be assigned i.e. intialized once and only once?

A
  • Define it using the final keyword.
  • Example:
    • final private String characterName;
26
Q

How do you set a constant that you don’t want to be changed in your class?

A
  • Constants that we want to be exposed would be set as public and to ensure they aren’t set to a different value the final keyword is used.
    • public final int EXAMPLE_CONSTANT = 12;
  • If we want these variables to be accessible right off the class, class level variables, then we also add the static keyword.
    • public static final int MAX_PEZ = 12;
27
Q

What does the static keyword mean?

A
  • It refers to how a variable is stored in memory.
  • It allows you to have variables and methods available directly off your class (class-level) as opposed to have them be available off an instance (instance-level).
28
Q

What is used to make methods unique in Java?

A
  • The name and the parameter list is used to make methods unique in Java.