JM 5 Flashcards

1
Q

What is a Javadoc comment?

A

A Javadoc comment is set off from code by standard multi-line comment tags /* and */. The opening tag (called begin-comment delimiter), has an extra asterisk, as in /**. The first paragraph is a description of the method documented. Following the description are a varying number of descriptive tags, signifying: The parameters of the method (@param) What the method returns (@return) Any exceptions the method may throw (@throws) Other less-common tags such as @see (a “see also” tag)

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

Name 3 good uses for comments

A
  1. Explaining what a program does
  2. Explaining obscure lines of code
  3. Documenting the methods and classes that other programmers will use.
  4. Disable parts of code e.g “commenting out” lines.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Style vs Syntax?

A program begins with a comment.

A

Style

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

Style vs Syntax

Names of all methods begin with a lowercase letter

A

Style

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

Style vs Syntax

Each opening brace has a matching closing brace

A

Syntax

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

Style vs Syntax

All statements within a pair of matching braces are indented by 2 spances.

A

Style

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

Style vs Syntax

A closing brace is place on a separate line.

A

Style

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

Style vs Syntax

A class has a lank line before each method declaration.

A

Style

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

Style vs Syntax

The word IF is not used as a name for a variable.

A

Style

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

What are the Java primitive data types?

A
  1. char
  2. byte
  3. int
  4. long
  5. short
  6. double
  7. float
  8. boolean
  9. void
  10. enum
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the java buil in constants?

A
  1. true
  2. false
  3. null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are Java’s built-in storage/access modifiers?

A
  1. public
  2. private
  3. protected

above are access modifiers

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

What are Java’s built-in control statements (/keywords are used in control statements) ?

A
  1. if
  2. else
  3. for
  4. while
  5. do
  6. switch
  7. case
  8. default
  9. break
  10. return
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which Java keywords deal with classses and inheritance?

A
  1. import
  2. class
  3. interface
  4. extends
  5. implements
  6. new
  7. this
  8. super
  9. abstract
  10. instanceof
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Which reserved words deal with exception handling?

A
  1. try
  2. catch
  3. finally
  4. throw
  5. throws
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Other Java reserved words?

A
  1. continue
  2. package
  3. native
  4. volatile
  5. transient
  6. synchronized
  7. assert
  8. strictfp
17
Q

What are the components of a Java class?

A
The inner part of the class is where we define the fields, constructors, and methods that
give the objects of that class their own particular characteristics and behavior. We can
summarize the essential features of those three components of a class as follows:
  1. The fields store data for each object to use.
  2. The constructors allow each object to be set up properly when it is first created.
  3. The methods implement the behavior of the objects.

In Java there are very few rules about the order in which you

18
Q

What are the access modifying keywords in Java?

A
  1. public
  2. private
  3. protected
19
Q

Let us say you write a class without using the keyword public. Example:

class Foobar {

 .....

}

What restrictions come into play? Why did Gosling make Java so verbose, anyway? Python doesn’t have this public private nonsense and it seems to work OK?

A

A class may be declared with the modifier public, in which case that class is visible to all classes everywhere. If a class has no modifier (the default, also known as package-private), it is visible only within its own package (packages are named groups of related classes)

  At the member level, you can also use the public modifier or no modifier (package-private) just as with top-level classes, and with the same meaning. For members, there are two additional access modifiers: private and protected. The private modifier specifies that the member can only be accessed in its own class. The protected modifier specifies that the member can only be accessed within its own package (as with package-private) and, in addition, by a subclass of its class in another package.
20
Q

How can you identify a constructor of a class?

A
  1. It has the same name as the class.
21
Q

Does a constructor have to have a return?

A

No. Constructors usually do not have returns. I don’t know if this is syntactically enforced. We should try it out.

22
Q

What is the difference between an instance variable and a field?

A

They mean the same thing – object oriented programming has a lot of confusing, vague terminology which often resolve to simple things. Look at this nice example:

http://www.bluej.org/objects-first/chapters/objects-first-ch2.pdf

23
Q

What is the meaning of the //, /*, and */ character sequences in the code?

A

They denote comments, which are ignored by the compiler. A comment is either
text in between /* and */ or at the end of a line after //.

24
Q

Q. What are Java’s rules regarding tabs, spaces, and newline characters?

A
A. Such characters are known as whitespace characters. Java compilers consider all whitespace in program text to be equivalent. For example, we could write Hel-loWorld as follows:
public class HelloWorld { public static void main ( String [] 
args) { System.out.print("Hello, World") ; System.out.
println() ;} }
But we do normally adhere to spacing and indenting conventions when we write 
Java programs, just as we always indent paragraphs and lines consistently when we 
write prose or poetry
25
Q

Q. What are the rules regarding quotation marks?

A

Material inside question marks are an exception to the rule.

26
Q

. What happens when you omit a brace or misspell one of the words, like public
or static or void or main?

A

A. It depends upon precisely what you do. Such errors are called syntax errors and are usually caught by the compiler. For example, if you make a program Bad that is
exactly the same as HelloWorld except that you omit the line containing the first
left brace (and change the program name from HelloWorld to Bad), you get the
following helpful message:
% javac Bad.java
Bad.java:2: ‘{‘ expected
public static void main(String[] args)
^
1 error
From this message, you might correctly surmise that you need to insert a left brace.
But the compiler may not be able to tell you exactly what mistake you made, so the
error message may be hard to understand. For example, if you omit the second left
brace instead of the first one, you get the following messages: % javac Bad.java
Bad.java:4: ‘;’ expected
System.out.print(“Hello, World”);
^
Bad.java:7: ‘class’ or ‘interface’ expected
}

Bad.java:8: ‘class’ or ‘interface’ expected

3 errors
One way to get used to such messages is to intentionally introduce mistakes into a
simple program and then see what happens. Whatever the error message says, you
should treat the compiler as a friend, for it is just trying to tell you that something
is wrong with your program.

% javac Bad.java
Bad.java:4: ‘;’ expected
System.out.print(“Hello, World”);
^
Bad.java:7: ‘class’ or ‘interface’ expected
}

Bad.java:8: ‘class’ or ‘interface’ expected

3 errors
One way to get used to such messages is to intentionally introduce mistakes into a
simple program and then see what happens. Whatever the error message says, you
should treat the compiler as a friend, for it is just trying to tell you that something
is wrong with your program.

27
Q

Can a Java program use more than one command line argument?

A

You can use as many as you like; but we usually use just a few.

28
Q

What is a command line argument?

A

What is it, indeed?

29
Q

How many classes are available from the JDK?

A

One estimate was in the three thousand range!