Java Flashcards

1
Q

What did you learn about static functions?

A

static signature makes the function unique. That is, we don’t need to create an instance of the class in order to use the function. We can simply call <classname>.<functionname>.</functionname></classname>

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

There’s a big difference between j = i-1; and j=i–;

What is it?

A

i– changes the value of i. i-1 does not.

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

Is it possible to use macros in java?

A

It is, not recommended though.

Using macros is using the C pre-processor. We can use macros, then run the C pre-processor, through the command line, on our code to generate the required code to be compiled.

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

What does static mean in Java?

A

it means that you can call a method, even if you’ve never created the object to which it belongs

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

What does <> mean in java

A
  • It is placed after “public static” with some capital letter between ‘<>’, like <t>, and it signals a <strong>generic function</strong>. That is, the function can get any <strong>object.</strong></t>*
  • For instance,*
  • Public static <t> T[] justReturn(T[] arr){</t>*
  • return arr;*
  • }*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between extends and implements?

A

extends is for extending a class

implement is for implementing an interface

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

What does serialization mean?

points to explain - marker interface, serialize, deserialized, serial version UID

A

If we implement Serializable it means we tell the java serialization classes that this class is intended for serialization. That is, intended for writing(serialization) and reading(deserialization) of objects.

java.io.Serializable - is the Java interface. It is called a marker interface since we don’t need to implement any method.

Only thing we should include is a private static final long serialVersionUID, which signifies the current “version” of our class, so that if we wrote some object to disk, and then changed the class, when we readback, it knows it now reads to a different class.

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

What does transient mean?

A

It is a keyboard which marks a memeber variable not to be serialized. They will not be saved using serialization; they are lost intentionally.

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

Explain the comparable interface

A
  • We implement the Comparable interface when we want to compare between objects.*
  • This interface has only one method, with the signature: int compareTo(obj o)*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Describe the super keyboard

A

Extending class uses the super keyboard for calling a method/variable of the parent class(a method they both share, of course) or initiate the constructor of the parent class.

Note that the constructor of the base class is called automatically

NOTE: when a class uses some method/variable, the compiler first looks within its fields/methods. If the name is not found, it searches in the parent’s class. If not found in the parent’s class, it goes to the parent of the parent’s class and so on.

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

Describe this keyboard

A

It is a keyboard used to refer to the instance of the object:

  • using it we can call the constructor; this(..);
  • using it we can the object’s methods, this.method();
  • using it we can refer to the object’s fields: this.field;
  • using it we can give the instance of the object as a method parameter; display(this);
  • using it we can give the instance of the object as a parameter to a constructor; A a = new A(this);
  • using it we can return the current class instance; return this;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the need of instance of?

A

You may have several classes extending some parent class, and you want to have a function which takes as argument an object which extends the parent class, and operate according to the class which was given. The argument is of course of the type ParentClass p, so that the extending classes could be passed as parameters. How can we identify between all these classes? using instanceof.

if(p instanceof <someextendingclass>)</someextendingclass>

do something

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