Java & OOP Basics Notes

  • Upload
    deep099

  • View
    227

  • Download
    0

Embed Size (px)

Citation preview

  • 8/3/2019 Java & OOP Basics Notes

    1/2

    *********************************************************************************************

    Abstract class vs Interface

    An interface is used to define a set of methods that a class can choose to implement

    An abstract class is similar but can include

    (i) data fields that can then be shared by subclasses" (ii) implementations of some methods that serve as default behavior when not overridd""*********************************************************************************************

    Information Hiding

    Information Hiding

    - language feature of capability that allows certain aspects of the software from being i

    - one way to achieve this is to provide a interface, which does not change" " " -- though the underlying implementation can change, but this does not affect the - hides design decisions that are likely to change

    *********************************************************************************************

    Encapsulation

    - way of organizing data and methods into a structure and concealing the way it is implem

    - provides the ability to validate/process the values in a method before they are applied" -- preserves integrity of the data- encapsulation defines access levels: public, protected, private

    - data does NOT have to be hidden" " -- difference from Information Hiding*********************************************************************************************

    Abstraction

    Abstraction means hiding the complexity of a system and providing a simple interface for it

    *********************************************************************************************

    Polymorphism

    - Dynamic binding: JVM decides at run-time which method to invoke, depending on the type

    - Polymorphism means you can use a variable of a superclass type to hold a reference to a" - the type of the object should be the same as the superclass or any of the supercla- Why are these two useful? Old code will work even when new subclasses are created."" " -- If Orange is a subclass of Fruit, then dynamic binding ensures that its method" " -- Code for orange need not have been written when Fruit was written and compile

    *********************************************************************************************

    try { } finally { ...}. . Finally creates a block of code that will be executed after the t

    So, if a database connection was opened in the try block (and closed towards the end of it),

    Final: prevent programmers from creating subclasses, or overriding certain methods. String c

    A security class can have the method that checks the password as a final method so that one

    *********************************************************************************************

    Advantages of Maven :

  • 8/3/2019 Java & OOP Basics Notes

    2/2

    quick project setup, no complicated build.xml files, just a POM and go

    all developers in a project use the same jar dependencies due to centralized POM.

    getting a number of reports and metrics for a project "for free"

    reduce the size of source distributions, because jars can be pulled from a central location

    *********************************************************************************************

    Volatile :

    The volatile keyword is used on variables that may be modified simultaneously by other thread

    Compiler does not cache these variables in registers.

    Inhibits certain optimizations that assume no other thread will change the values unexpectedl

    *********************************************************************************************

    HashMap and Hashtable do not guarantee that the order of the map will remain constant over ti

    Hashtable is synchronized, HashMap is not.

    Vector is synchronized, arraylist is not.

    *********************************************************************************************

    LinkedList vs. ArrayList

    ArrayList

    The ArrayList is actually encapsulating an actualy Array, an Object[]. When you instanciate A

    This gives you strengths and weaknesses:

    Fast Random Access

    You can perform random access without fearing for performence. Calling get(int) will just acc

    Adding values might be slow When you dont know the amount of values the array will contain w

    Slow manipulation When youll want to add a value randomly inside the array, between two alre

    LinkedList

    The LinkedList is implemented using nodes linked to each other. Each node contains a previous

    When new data is inserted, a node is inserted and the links of the surrounding nodes are upda

    When one is removed, the same happens The surrounding nodes are changing their links and th

    Fast manipulation As youd expect, adding and removing new data anywhere in the list is insta

    No random access Even though the get(int) is still there, it now just iterates the list until

    It has some optimizations in order to do that, but thats basically it.

    *********************************************************************************************

    Reflections:

    http://tutorials.jenkov.com/java-reflection/index.html

    Java's Reflection API's makes it possible to inspect classes, interfaces, fields and methods

    *********************************************************************************************