JAVA TERM 1

53 flashcards · Programming Languages · by inquisitive learner

  1. block

    a sequence of statements, local class declarations and local variable declarations

  2. How does a block act?

    A block acts as a single statement

  3. ==

    equal to (relational operator)

  4. !=

    not equal to (relational operator)

  5. >

    greater than relational operator

  6. <

    "less than" relational operator

  7. >=

    "greater than or equal to" relational operator

  8. <=

    "less than or equal to" relational operator

  9. A relational expression returns a result of type Boolean

  10. !

    "not" combinatory relational operator

  11. ||

    "or" combinatory relational operator

  12. &&

    "and" combinatory relational operator

  13. if-else syntax (Allman style)

    if (\\relational expression) { // statement or block } else { // statement or block }

  14. if-else multi-way selection

    if (\\relational expression) { // statement or block } else if (relational expression) // as needed { // statement or block } else { // statement or block }

  15. switch-case selection statement

    switch (exampleexpression) { case 'literal constant': // block or statement }

  16. fall-through

    (in switch-case selection statements) compiler executes the next statement if there is no break keyword; control flow 'falls-through' to the next case

  17. default

    Java keyword: in switch-case statements, this is the statement the compiler will execute if none of the previous cases match the conditions

  18. break

    Java keyword: causes the remainder of the switch-case statement to be skipped

  19. What is an advantage of fall-through?

    When multiple cases produce the same output, fall-through allows us to avoid redundant code

  20. Switch-case statements should be mutually exclusive and exhaustive.

  21. Punctuation in java ; marks the end of a statement

  22. inheritance

    the ability to derive a new class from an existing one. Inherited variables and methods of the original (parent) class are available as if they were declared locally

  23. parent class

    the class from which variables and methods are derived

  24. subclass

    the derived class

  25. superclass

    the parent class

  26. Inheritance should be used to model an "is a" relationship. A subclass represents a specialised version of the superclass

  27. accessor method getPages() // example

    An accessor method provides read-only access to a particular value

  28. extends

    defines a subclass as being derived from its superclass

  29. instance variable (aka attributes, Data members)

    A variable that must be referenced through a particular instance of a class, as opposed to a class variable; defines the state of an object

  30. Differences between instance variables and class variables Class variables are declared with the static keyword; instance variables are not Instance variables are specific to an object - they have a more limited scope - whereas class variables are shared across all occurrences | instances of a class The class name is used to access a class variable; instance variables are accessed directly within the class

    declaration, scope, access

  31. What should you do if the behaviour of a parent class is unsuitable for the subclass?

    override the superclass's behaviour by providing a method with the same signature as a superclass method

  32. Why is using inheritance good for your programme?

    Inheritance promotes reuse

  33. An object has: state - descriptive characteristics e.g each String object contains a group of specific characters in a particular order behaviours - what it can do (or be done to it) e.g toUpperCase method is a service the String object can perform.

  34. class

    the blueprint for creating objects defines a new data type

  35. method (aka operations, member functions)

    a named group of declarations and programming states that can be invoked (executed when needed); define behaviour

  36. object (3)

    the primary software construct in an object-oriented paradigm an encapsulated collection of data variables and methods an instance of a class

  37. cohesion

    the strength of the relationship among the parts of a software component

  38. abstraction

    the concept of hiding details , e.g through a class

  39. coupling

    the strength of the relationship between two software components. Ideally, programs are loosely coupled

  40. private

    Java reserved keyword; method or instance variable that can only be accessed by methods of the same class

  41. public

    can be accessed by external code

  42. Visibility modifiers public private protected

  43. package

    a group of classes

  44. How visible is a member declared without a visibility modifier?

    Members declared without a visibility modifier have default visibility

  45. support method

    a method created to assist a service method; should be declared with private visibility

  46. Which classes can access a member with default visibility?

    Members with default visibility can be accessed by any class in the same package

  47. Java convention for naming classes

    Class names start with a capital letter and use camel case

  48. Variable names start with lower case and use camel case and should be informative

  49. Relational operators are boolean operators: they result in either true| false or false | true

    Relational operators: == !=

  50. When is it best to use a for loop?

    When looping a fixed number of times When iterating through collections of objects

  51. for loop

    initialisation, termination, decrement

  52. When is it best to use a do-while loop?

    A do-while loop is best for when code must always be executed at least once

  53. When is it best to use a while loop?

    a while loop is best for when unmet conditions should result in unexecuted code