.111 15-20 Flashcards
What does the volatile type do?
stops usual memory optimisation by telling it to not cache the variable value but to retrieve from memory as it may change
Define composition -
classes may hold attributes of class type
How does referencing work in java?
100% pass by value
What is a primitive type?
aka value types
= data itself is being accessed/modified/passed into a function
e.g. int, char, float, etc.
What is a reference type?
use object references to objects, reference is being accessed/modified
e.g. ObjectName
What does the this keyword do?
returns an object reference to the object instance which the current method is executing in
can be used to differentiate between object attributes and parameter’s w/ same name
What happens to java objects when they have no references?
get deleted
What is API documentation?
documentation of classes so other programmers can learn how to use them
JavaDoc = java standard
What are some standards in javaDoc?
begins w/ /** and ends **/ with * on each line between
@param/@return <varname> followed by explanation</varname>
How to automatically generate written documentation?
use javadoc -d doc name.java to generate web pages that can be found in index.html
What is swing?
standard java package for GUIs
- very large + flexible
- heavily OO
- platform independent!
How do components work in swing?
graphical components implemented as java classes
classes reside in javax.swing package (need to import)
What is a JFrame?
represents window in host OS (matches the style), inc. title bar + icons for minimise, resize, close, etc.
can be initialised w/ or w/o a title
What is JFrame automatically instantiated as?
JFrame.HIDE_ON_CLOSE + invisible
What is a static variable/method?
called on a whole class (all the objects, not just an instance)
What is a final variable?
cannot have its value changed after it has been initialised - like a constant
What holds a component in swing?
JPanel = holds a list of components
add new components via componentName.setContentPane(panelName);
What are some common components in swing?
JLabel, JButton + JTextField
What is a layout manager?
(Give examples)
provided by Swing to dynamically layout GUI components for you
e.g. FlowLayout, GridLayout + BorderLayout
What are pros + cons of layout managers?
efficient and help keep application flexible + platform independent
but limits control
What does FlowLayout do?
arranges components to best fit panel size (left-right, top-bottom)
- dynamically changes so simple to use
- lack of control other than specifying left/right/centre centring
How do you set a layout manager?
instantiate a manager - e.g. FlowLayout layout = new FlowLayout;
then panel.setLayout(layout);
What does GridLayout do?
fits components in a fixed size matrix (specify rows + column as param. in layout instantiation)
- good for repeating sets of components
- little control
What does BorderLayout do?
provide relative positioning of up to 5 components in north, south, east, west, center positions
- a little more control
- but only 1 component per region