• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/39

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

39 Cards in this Set

  • Front
  • Back
What is an identifier?
A name of a class, object, variable or method
Which five rules apply to an identifier?
1. Must start with a letter, currency character ($) or connecting character (_), but NOT with a number
2. After the first character can contain letters, currency characters, connecting characters or numbers
3. There is no limit to the number of characters
4. Can't use a java keyword
5. Is case-sensitive
Which java keywords do you know?
abstract, boolean, break, byte, case, catch, char, class, const, continue, default, do, double, else, extends, final, finally, float, for, goto, if, implements, import, instanceof, int, interface, long, native, new, package, private, protected, public, return, short, static, strictfp, super, switch, synchronized, this, throw, throws, transient, try, void, volatile, while, assert, enum
What's the naming convention for a class or interface?
Starts with a capital letter and capitalizes every next word (e.g. BufferedReader)
What's the naming convention for a method?
Start with a lowercase letter and capitalizes every next word (e.g. readLine)
What's the naming convention for a variable?
Start with a lowercase letter and capitalizes every next word. Sun recommends keeping the names short. Example: readAheadLimit
What's the naming convention for a constant?
They're in all uppercase letters, with an underscore between seperate words: AUTO_RESIZE_OFF
What are java beans?
Java beans are classes that contain properties and methods named in a certain way so that third party tools like editors and frameworks can assist in using these classes.
What are the java bean property naming rules?
A property is usually a private instance variable (but doesn't have to be). This private instance variable is named using the naming convention for a variable.

A property will always be get and set through public method, and not directly using the variable. When you want to get a property there's two options:
1. public PropertyType getPropertyName()
2. public boolean isPropertyName()
2) only applies to boolean typed properties. 1) applies to both boolean typed properties and the rest.

So when you have a private instance variable: private boolean ready = false;
You use either: public boolean getReady() or public boolean isReady()
When you have a variable: private String name = "Name";
You use: public String getName()

When you want to set a property there's only one option:
1. public void setPropertyName(PropertyType propertyName)
So when you have a private instance variable: private String name = "Name;
You use: public void setName(String name)
What are the java bean event naming rules?
An event is used to notify components when something important happens. An event is listened to by listeners. A class can fire an event that needs to be listened to. This class contains two public methods:
1. A public method to add a listener as a listener for this event. An example: public void public void addActionListener(ActionListener m)
The method starts with 'add', then the type starting with an uppercase letter. The method has one argument of the type that was used in the method name.
2. A method to remove a listener as a listener for the event. An example:
public void removeActionListener(ActionListener m). The same naming rule as in 1) applies to 'remove'.
Listener methods must end with 'Listener'.
What are the 8 rules associated with declaring classes, import statements and package statements in a source file?
1. Only one public class per file
2. Comments can be at the beginning or the end of a line
3. If there is a public class, the name of the file must correspond with this name (Example: class BufferedReader will be in file BufferedReader.java)
4. If a class is part of a package, the package name must be the first line in the file
5. If there are imports, the imports must go between the package and the first class declaration. If there isn't a package specified, the imports go before everything else.
6. import and package statement apply to all classes specified in the file
7. A file can contain several non public classes
8. A file containing no public classes can have any name.
What is the minimum class declaration?
class MyClass {}
What are the types of modifiers that can be applied to a class?
Access modifiers and non-access modifiers
What access modifiers are there?
public, protected, private
What non-access modifiers are there?
strictfp, final, abstract
How many access controls are there?
Four: default, private, public, protected
How many access modifiers are there?
Three: private, public, protected
What does 'having access' to a class mean?
1. You can create an instance of the class
2. You can extend it
3. You can access certain methods and variables, depending on the access control of those methods and variables.
What access modifier does a default class have?
None, there is no access modifier for the default access control.
What does default access control mean?
You can see it as package level access. A class with default access can only be seen by classes in the same package.
What does the 'public' access modifier do to a class?
All classes are allowed to access that class. But only when this class has been imported using the import statement or is in the same package.
What does the 'strictfp' modifier do to a class?
This turns on strict floating point processing which is not platform dependent, in contrast with the default floating point processing.
What does the 'final' modifier do to a class?
This class can not be subclassed, so no other class can ever extend this class. Final was invented for safety/security to guarantee a certain behavior.
What does the 'abstract' modifier do to a class?
An abstract class can never be instantiated. It needs to be extended by a subclass first, before it's behavior can be used.
How do you define an abstract method?
public abstract void myMethod();

Pay particular attention to the semicolon ; at the end of the line instead of the curly brace {
Will a class that is marked with abstract and final compile or not? Why?
This will not compile. An abstract class must be subclassed, where a final class cannot be subclassed. This is a contradiction, resulting in a compile error.
What are the 9 rules about interfaces?
1. All interface methods are implicitly abstract and public.
2. All variables in an interface must be public, abstract and final. Interfaces can only declare constants.
3. Interface methods must not be static
4. Interface methods cannot be marked final, strictft or native
5. An interface can extends one or more interfaces
6. An interface can't extend anything other than an interface
7. An interface can't implement another interface or class
8. An interface must be declared with the word 'interface'
9. Interface types can be used polymorphically
What is the access level of an interface?
It is defined as default when you haven't specified anything. All methods of an interface are defined as public and abstract when you haven't specified anything.
Is it allowed to have the following method definition in an interface?
protected void myMethod();
No it isn't. Methods in an interface must be public.
How do you define a constant in an interface?
interface Writable {
public static final int LEFT_TO_RIGHT = 1;
}

You could also have used:
interface Writable {
int LEFT_TO_RIGHT = 1;
}

This means the same (the compiler adds public static final by itself internally)
Is the following interface variable declaration allowed or not?

public static int x = 1;
Yes, it is. But it's also final, as all interface variables are:
public static final
What are the two types of members a class can have?
1. Methods
2. Variables
Is it possible to define a class to have protected access, like so:

protected class MyClass {}
No, a class can only have public or default access, as in:

public class MyClass {}

or:

class MyClass{}
What access levels can members have?
1. protected
2. default
3. public
4. private
What are the three ways to access a method?
1. Invoking a method in the same class
2. Invoking a method using a reference of the class
3. Invoking an inherited method
In what ways can a public method be invoked?
1. Invoking a method in the same class
2. Invoking a method using a reference of the class
3. Invoking an inherited method
In what ways can a private method be invoked?
Only by invoking a method in the same class
The method can't be invoked by an extending class, and also can't be invoked using a reference of the class
In what ways can a protected method be invoked?
1. A protected method can be invoked in the same class
2. A protected method can't be invoked by a reference to the class
3. A protected method can be invoked from extending classes
In what ways can a default method be invoked?
A default method can be invoked:
1. From the same class
2. From any class in the same package
3. From a subclass in the same package

A default method can't be invoked:
1. From a subclass outside the package
2. From any non-subclass outside the package