intermediate programming

Cards (55)

  • Class
    A user-defined blueprint or prototype from which objects are created. It represents the set of properties or methods that are common to all objects of one type.
  • Components of a class declaration
    • Modifiers
    • Class name
    • Superclass (if any)
    • Interfaces (if any)
    • Body
  • Modifiers
    Access specifiers that determine the accessibility of a class or class member
  • Access specifiers in order of restrictiveness
    • Private
    • Default
    • Protected
    • Public
  • Superclass
    The class whose features are inherited
  • Subclass
    The class that inherits from the superclass
  • Interface
    A contract that defines a set of methods that a class must implement
  • Interfaces cannot be used to create objects
  • Interface methods do not have a body - the body is provided by the "implement" class
  • On implementation of an interface, you must override all of its methods
  • Interface methods are by default abstract and public
  • Interface attributes are by default public, static, and final
  • An interface cannot contain a constructor
  • Why and when to use interfaces
    To achieve security - hide certain details and only show the important details of an object
  • Method
    A collection of statements that perform some specific task and return the result to the caller
  • Components of a method declaration
    • Modifier
    • Return type
    • Method name
    • Parameter list
    • Exception list
    • Method body
  • Modifiers
    Define the method's access type
  • Access specifiers for methods
    • public
    • protected
    • private
    • default
  • Naming conventions for methods
    A single word that is a verb in lowercase or a multi-word that begins with a verb in lowercase followed by an adjective or noun, with the first letter of each subsequent word capitalized
  • Calling a method

    1. Method completes all statements
    2. Method reaches a return statement
    3. Method throws an exception
  • Method parameters
    Values passed to a method that can be used as local variables
  • Arguments
    Values passed to a method when it is called
  • Constructor
    A special method used to initialize objects, called when an object is created
  • Constructors do not have a return type
  • The constructor's name must be the same as the class name
  • Constructors are not considered members of a class
  • A constructor is called automatically when a new instance of an object is created
  • Inside a block, variables are local to that block only.
  • Enum type
    A special data type that enables for a variable to be a set of predefined constants
  • Common examples of enum types
    • Compass directions (values of NORTH, SOUTH, EAST, and WEST)
    • Days of the week
  • Defining an enum type in Java

    1. Use the enum keyword
    2. Separate constants with a comma
    3. Constants should be in uppercase letters
  • Enum
    A data type consisting of a set of named values called elements, members, enumeral, or enumerators of the type
  • BitSet
    A Java class that creates an array of boolean values, allowing non-negative integers as an index. It's easy to create and manipulate bit sets, representing a set of boolean flags, and provides detailed API usage examples.
  • BitSet class
    Creates an array of bits represented by boolean values, with a flexible size that can grow to accommodate additional bits. Its index can be non-negative integers.
  • BitSet
    • It is easy to create and manipulate, representing a set of boolean flags
  • BitSet class constructors
    • BitSet()
    • BitSet(int no_Of_Bits)
  • BitSet
    A boolean variable with a default value of false, representing 0 (off)
  • Using BitSet
    1. Set bit positions to 1 (on) using the set method's zero-based index
    2. Clear the BitSet to set the bit values to false
    3. Access a specific value using the get method with an integer argument as an index
  • BitSet class constructors
    • BitSet()
    • BitSet(int size)
  • BitSet class methods
    • and(BitSet bitSet)
    • andNot(BitSet bitSet)
    • cardinality()
    • clear()
    • clear(int index)
    • clear(int startIndex, int endIndex)
    • clone()
    • equals(Object bitSet)
    • flip(int index)
    • flip(int startIndex, int endIndex)