IL's JAVA WORLD

Discussion in 'Education & Personal Growth' started by chaitusri, May 22, 2009.

  1. itsmeteddy

    itsmeteddy New IL'ite

    Messages:
    84
    Likes Received:
    0
    Trophy Points:
    6
    Gender:
    Female
    Archana, Sounds like a great idea. We wont be mixing up two things.

    I will start it now.
     
  2. chaitusri

    chaitusri Silver IL'ite

    Messages:
    590
    Likes Received:
    17
    Trophy Points:
    50
    Gender:
    Female
    Today's ?s

    1)What is the name of collection interface used to maintain unique elements.

    2)TreeMap class is used to implement which collection interface

    3)What happens when the following code is compiled and run. for(int i = 1; i < 3; i++)
    for(int j = 3; j >= 1; j--)
    assert i!=j : i;
     
  3. Priya_Mommy

    Priya_Mommy Gold IL'ite

    Messages:
    3,087
    Likes Received:
    93
    Trophy Points:
    128
    Gender:
    Female
    Hello java'ites,
    This forum seems to be informative.
    Count me in too....I too worked in java for around 2 years in my initial days. Ofcourse now settled as a CRM specialist almost 4 years now.
    Atleast want to be a silent reader and will try to contribute based on my experiences.
     
  4. archana2008

    archana2008 Gold IL'ite

    Messages:
    1,741
    Likes Received:
    420
    Trophy Points:
    165
    Gender:
    Female
    Chaitu. I never implemented WeakHashMap in my project. Also can we set timer to this, i mean it says automatically release the value if no longer in use.But not using for how long? can we set that value?
     
  5. archana2008

    archana2008 Gold IL'ite

    Messages:
    1,741
    Likes Received:
    420
    Trophy Points:
    165
    Gender:
    Female
    1)What is the name of collection interface used to maintain unique elements.
    Set Interface
    2)TreeMap class is used to implement which collection interface
    SortedMap
    3)What happens when the following code is compiled and run. for(int i = 1; i < 3; i++)
    for(int j = 3; j >= 1; j--)
    assert i!=j : i;
    Not sure! No Output when i complied and ran
     
  6. archana2008

    archana2008 Gold IL'ite

    Messages:
    1,741
    Likes Received:
    420
    Trophy Points:
    165
    Gender:
    Female
    Chaitu,

    Can you ask questions step by step
    1. basics of java programming
    2. language fundamentals
    3. operations and assignments
    4. declarations and access control
    5. control flow, exception handling and assertions
    6. object oriented progamming
    7. nested classes and interfaces
    8. object lifetime
    9. threads
    10. fundamental classes
    11. collections and maps

    Add on topics if i missed any for exam.

    Question in :Basics of Java Programming
    which statement is true about a method
    select the one correct answer
    a) a method is an implementation of an abstraction
    b) a method is an attribute defining the property of a particular abstraction
    c) a method is a category of objects
    d) a method is an operation defining the behaviour for a particular abstraction
    e) a method is a blueprint for making operations
     
  7. renjana

    renjana Junior IL'ite

    Messages:
    59
    Likes Received:
    5
    Trophy Points:
    13
    Gender:
    Female
    Hi chaitusri,
    So nice of u start such a thread. Even I have 4yrs of experience in Java(only core java)

    Pls continue the discussion regarding patterns

    Thanks
    Renjana
     
  8. chaitusri

    chaitusri Silver IL'ite

    Messages:
    590
    Likes Received:
    17
    Trophy Points:
    50
    Gender:
    Female
    Hi Archana!

    Usually we never implement weakhasmaps in projects as its main purpose is to help JVMs in garbagecollection.

    The staright answer to your question is we can't set time for clear things in weakhashmap, JVM doesn't provide the option for us :).

    And for your reference- sorry for long paragraphs :(


    The elements of a WeakHashMap cache could be cleared at any time by the JVM, and there is no selectivity. Normally all the elements which can be cleared, are cleared in one go. This takes control away from the cache-builder. A more useful cache would be signalled by the JVM that memory was needed and would then be allowed to select which elements to clear.

    Some Consequences of the WeakHashMap Implementation

    · Reference clearing is automatic; consequently, there is no need to worry about achieving some sort of corrupt state if you try to access an object and the garbage collector is clearing keys at the same time. You will either get the object or you won't.
    · The values are not released until the WeakHashMap is altered. This is specific to the implementation, and was done to avoid getting ConcurrentModificationExceptions. If the ReferenceQueue were processed on an accessor, this could be from an Iterator accessing elements. Then even if there was only one thread running, it would be possible for the map to be altered as you iterated through it, giving a surprising ConcurrentModificationException. Specifically one of the mutator methods, put(), remove(), or clear(), need to be called directly or indirectly (e.g. from putAll()) for the values to be released by the WeakHashMap. If you do not call any mutator methods after populating the WeakHashMap, the values and WeakReference objects will never be dereferenced.
    · WeakHashMap (at least up to version 1.3) wraps an internal HashMap. This means that practically every call to the WeakHashMap has one extra level of indirection it must go through (e.g. WeakHashMap.get() calls HashMap.get()), which can be a significant performance overhead. This is a specific choice of the implementation.
    · Every call to get() creates a new WeakReference object to enable equality testing of keys in the internal HashMap. Although these are small short-lived objects, if get() was used intensively this could generate a heavy performance overhead. Again this is a specific choice of the implementation. The WeakHashMap could implement a hash table directly in the class and avoid the need for extra WeakReference objects.
    · Unlike many other collections, WeakHashMap cannot maintain a count of elements, since keys can be cleared at any time by the garbage collector without immediately notifying the WeakHashMap. This means that seemingly simple methods such as isEmpty() and size() have more complicated implementations than for most collections. Specifically, size() actually iterates thorugh the keys, counting those that have not been cleared. Consequently size() is an operation that takes time proportional to the size of the WeakHashMap. Similarly, isEmpty() iterates through the collection looking for a non-null key. This produces the perverse result that a WeakHashMap which is empty, due to having all its keys cleared, requires more time for isEmpty() to return than a similar WeakHashMap that is not empty.
     
  9. chaitusri

    chaitusri Silver IL'ite

    Messages:
    590
    Likes Received:
    17
    Trophy Points:
    50
    Gender:
    Female
    Hi Renjana!

    Welcome to our Java thread.

    We just started with core Java discussions and once we are done with all the pure Java related stuff then we will move to design patterns.
     
  10. chaitusri

    chaitusri Silver IL'ite

    Messages:
    590
    Likes Received:
    17
    Trophy Points:
    50
    Gender:
    Female
    Archana I can back to IL only after 4 days. So from coming wednesday we will start with your agenda
     

Share This Page