lecture 10 - Enumerate , Java doc and annotations Flashcards

1
Q

What is enum?

A

type/class is a special reference type that holds a set of predefined constants.

We don’t instantiate an enumerated class. Instead, get one pre-allocated fixed instance via ClassName.VALUE NAME

Java’s enum type can behave like normal classes, and can have
other attributes and methods in addition to their fixed values.

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

Enum example

A

enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY
}

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

enum convention

A

By convention, the variable names are all capitalised.

All constants defined in an enum type are implicitly public static final.

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

How are comments upported in java ?

A

single line comment // …
multiple lines comment /* … */
documentation comment /** … */

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

What happens to the comments during compilation?

A

During compilation, all the comments are ignored.

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

What is Javadoc?

A

A JDK tool automatically creates fancy HTML-based

documentation based on /** …*/ in your source files.

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

You can include special doc tags in the documentation comments that provide specific information used by JavaDoc to format the documentation pages. What are these tags ?

A

@author Provides information about the author.
@version Indicates the version number.
@since Indicate the version.
@param Provides the name and description of a method.
@return Provides a description of a method’s return value.
@throws Indicates exceptions that are thrown by a method.

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

What is the difference between simple comment and annotations ?

A

An annotation always starts with the symbol @ followed by the annotation name.

Annotations are checked by Java
compiler. (Different from the doc tag)

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

Predefined annotations ?

A

@Deprecated
@Override
@SuppressWarnings
Custom annotations could be defined by using @interface

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

What does the @Deprecated tag mean ?

A

@Deprecated - indicates a marked element should no longer be used. It is usually also documented using the Javadoc @deprecated tag

/**
* @deprecated ← a doc tag, not checked by compiler
* explanation of why it was deprecated
*/
@Deprecated ← an annotation, checked by compiler
void anyMethod() { … }

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

What does the override tag stand for ?

A

@Override - informs the compiler that the element is meant tooverride an element declared in a superclass.

@Override
void overridingMethod() { }

If the method is not an overriding method, an error will be generated during compilation:
error: method does not override or implement a method from a supertype

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

What doe the predefined tag suppress warnings stand for ?

A

@SuppressWarnings - tells the compiler to suppress specific warnings.

@SuppressWarnings(”unchecked”)
@SuppressWarnings(”deprecation”)

@SuppressWarnings(“deprecation”)
_____void myMethod() {
________myObject.deprecatedMethod();
}

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