JM 5 Flashcards
What is a Javadoc comment?
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)
Name 3 good uses for comments
- Explaining what a program does
- Explaining obscure lines of code
- Documenting the methods and classes that other programmers will use.
- Disable parts of code e.g “commenting out” lines.
Style vs Syntax?
A program begins with a comment.
Style
Style vs Syntax
Names of all methods begin with a lowercase letter
Style
Style vs Syntax
Each opening brace has a matching closing brace
Syntax
Style vs Syntax
All statements within a pair of matching braces are indented by 2 spances.
Style
Style vs Syntax
A closing brace is place on a separate line.
Style
Style vs Syntax
A class has a lank line before each method declaration.
Style
Style vs Syntax
The word IF is not used as a name for a variable.
Style
What are the Java primitive data types?
- char
- byte
- int
- long
- short
- double
- float
- boolean
- void
- enum
What are the java buil in constants?
- true
- false
- null
What are Java’s built-in storage/access modifiers?
- public
- private
- protected
above are access modifiers
- final
- static
What are Java’s built-in control statements (/keywords are used in control statements) ?
- if
- else
- for
- while
- do
- switch
- case
- default
- break
- return
Which Java keywords deal with classses and inheritance?
- import
- class
- interface
- extends
- implements
- new
- this
- super
- abstract
- instanceof
Which reserved words deal with exception handling?
- try
- catch
- finally
- throw
- throws
Other Java reserved words?
- continue
- package
- native
- volatile
- transient
- synchronized
- assert
- strictfp
What are the components of a Java class?
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:
- The fields store data for each object to use.
- The constructors allow each object to be set up properly when it is first created.
- The methods implement the behavior of the objects.
In Java there are very few rules about the order in which you
What are the access modifying keywords in Java?
- public
- private
- protected
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 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.
How can you identify a constructor of a class?
- It has the same name as the class.
Does a constructor have to have a return?
No. Constructors usually do not have returns. I don’t know if this is syntactically enforced. We should try it out.
What is the difference between an instance variable and a field?
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
What is the meaning of the //, /*, and */ character sequences in the code?
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 //.
Q. What are Java’s rules regarding tabs, spaces, and newline characters?
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
Q. What are the rules regarding quotation marks?
Material inside question marks are an exception to the rule.
. What happens when you omit a brace or misspell one of the words, like public
or static or void or main?
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.
Can a Java program use more than one command line argument?
You can use as many as you like; but we usually use just a few.
What is a command line argument?
What is it, indeed?
How many classes are available from the JDK?
One estimate was in the three thousand range!