Java Basics Flashcards

1
Q

Where is a local variable defined?

A

In a method.

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

Where are instance members defined?

A

In the scope

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

T/F: An instance member can be a variable, constant or method

A

True

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

What is an instance member?

A

A member variable or method that belongs to a specific object instance.

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

T/F: Non-static members are instance members.

A

True

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

Does Java support multiple package statements?

A

No

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

Where does the package statement go in a file?

A

The first statement in the file.

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

What happens if no argument is passed to a main method?

A

The args parameter is then an array of Strings of length zero.

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

How do you declare a method where an instance of the class is not needed?

A

Use the static keyword.

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

What is the correct parameter specification for the standard main method?

A

(String[ ] args)

or

(String args [ ] )

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

What does “class-level” mean in terms of access?

A

It means being accessible from anywhere (i.e. static as well as non-static methods) in the class (and from outside the class depending on their access modifier). This is done by using static methods.

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

What does “instance level” mean in terms of access?

A

It means accessible only from instance methods in the class. This is done with instance fields.

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

Which classes have access to a member with no modifier (default)?

A

Only members within the same package.

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

What is the visibility of local variables?

A

They are always accessible within the block in which they are declared.

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

Which modifiers can be applied to local variables?

A

Only final.

They cannot be transient, volatile, static, public or private.

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

Transient

A

An access modifier which marks the member variable as not to be serialized when persisted to streams of bytes.

17
Q

Volatile

A

Access modifier which lets the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in memory.

18
Q

Native

A

Access modifier applied to a method to indicate that the method is implemented in native code using JNI (Java Native Interface).

Cannot be applied to any kind of variable. (Methods only.)

19
Q

Synchronized

A

Access modifier applied to blocks on some object and can only have one thread executing inside them at a time

20
Q

What must be the return value of the main() method?

A

Void

21
Q

What commands must be run to compile and have the following code print “hello”:

public class Foo{
  public static void main(String[] args){
     System.out.println(args[1]);
  }
}
A

javac Foo.java

java Foo hello hello

22
Q

Consider:

package.com.foo.*

Is this a valid package statement?

A

No.

A package can never have a wildcard *.

23
Q

Which is the only package imported automatically?

A

java.lang

24
Q

What must be imported if the code uses IOException?

A

The java.io package (or just the java.io.IOException class)