LinkedList implementation

HGI Can any Body please answer this query:its urgent please do reply as soon as possible....
Create an interface to define Linked List classes. It should be
called LinkedListInt and should define all the methods necessary to
create a linked list of Objects.

HI kajolHi Frank,
This is not home work or assignment whatever it may
be if ur technically strong u have to answerNope. Why? If I'm a professional, I have to say "no" in order not to do the work you're supposed to do.
what if
it is home work or other if u have answer u can ,u
dont know how to solve and dont say any more reasons
that it is home work or so..Whatever you tried to tell me: see above.
if u know try to answe4r oe else keep calmWhat if I don't keep calm?

Similar Messages

  • Understanding method implementation for LinkedList class

    Hello
    I'm new to java and just trying to get my head around data structures, particularly ArrayList and LinkedList implementations. I've looked at the Sun API for both classes, but would like to see how the methods are implmented so I can venture into writing my own versions of these classes..
    Does anyone know if there is a resource showing the full method implementation so I can view how they work?
    thanks,

    a really strange licence: look but don't touch, and it's still under copyrightThis license seems to make sense: you can look at it and learn from it but you are not supposed to make an own, incomptabile version.

  • Redesigning the Collections Framework

    Hi!
    I'm sort of an experienced Java programmer, in the sense that I program regularly in Java. However, I am not experienced enough to understand the small design specifics of the Collections Framework (or other parts of Javas standard library).
    There's been a number of minor things that bugged me about the framework, and all these minor things added up to a big annoyance, after which I've decided to (try to) design and implement my own framework.
    The thing is however, that since I don't understand many design specifics about the Collection Framework and the individual collection implementations, I risk coming up short with my own.
    (And if you are still reading this, then I thank you for your time, because already now I know that this entry is going to be long. : ) )
    Since I'm doing my Collection framework nearly from scratch, I don't have to worry too much about the issue of backwards compatibility (altough I should consider making some parts similar to the collection framework as it is today, and provide a wrapper that implements the original collection interfaces).
    I also have certain options of optimizing several of the collections, but then again, there may be very specific design issues concerning performance and usability that the developers of the framework (or other more experienced Java progammers) knew about, that I don't know.
    So I'm going to share all of my thoughts here. I hope this will start an interesting discussion : )
    (I'm also not going to make a fuss about the source code of my progress. I will happily share it with anyone who is interested. It is probably even neccessary in order for others to understand how I've intended to solve my annoyances (or understand what these annoyances were in the first place). ).
    (I've read the "Java Collections API Design FAQ", btw).
    Below, I'm going to go through all of the things that I've thought about, and what I've decided to do.
    1.
    The Collections class is a class that consists only of static utility methods.
    Several of them return wrapper classes. However the majority of them work on collections implementing the List interface.
    So why weren't they built into the List interface (same goes for methods working only with the Collection interface only, etc)? Several of them can even be implemented more efficiently. For example calling rotate for a LinkedList.
    If the LinkedList is circular, using a sentry node connecting the head and tail, rotate is done simply by relocating the sentry node (rotating with one element would require one single operation). The Collections class makes several calls to the reverse method instead (because it lacks access to the internal workings of a LinkedList).
    If it were done this way, the Collections class would be much smaller, and contain mostly methods that return wrapped classes.
    After thinking about it a while, I think I can answer this question myself. The List interface would become rather bloated, and would force an implementation of methods that the user may not need.
    At any rate, I intend to try to do some sort of clean-up. Exactly how, is something I'm still thinking about. Maybe two versions of List interfaces (one "light", and the other advanced), or maybe making the internal fields package private and generally more accessible to other package members, so that methods in other classes can do some optimizations with the additional information.
    2.
    At one point, I realized that the PriorityQueue didn't support increase\decrease key operations. Of course, elements would need to know where in the backing data structure it was located, and this is implementation specific. However, I was rather dissapointed that this wasn't supported somehow, so i figured out a way to support this anyway, and implemented it.
    Basically, I've wrapped the elements in a class that contains this info, and if the element would want to increase its key, it would call a method on the wrapping class it was contained in. It worked fine.
    It may cause some overhead, but at least I don't have to re-implement such a datastructure and fiddle around so much with the element-classes just because I want to try something with a PriorityQueue.
    I can do the same thing to implement a reusable BinomialHeap, FibonacciHeap, and other datastructures, that usually require that the elements contain some implementation-specific fields and methods.
    And this would all become part of the framework.
    3.
    This one is difficult ot explain.
    It basically revolves around the first question in the "Java Collections API Design FAQ".
    It has always bothered me that the Collection interface contained methods, that "maybe" would be implemented.
    To me it didn't make sense. The Collection should only contain methods that are general for all Collections, such as the contains method. All methods that request, and manipulate the Collection, belonged in other interfaces.
    However, I also realized that the whole smart thing about the current Collection interface, is that you can transfer elements from one Collection to another, without needing to know what type of Collection you were transferring from\to.
    But I still felt it violated "something" out there, even if it was in the name of convenience. If this convenience was to be provided, it should be done by making a separate wrapper interface with the purpose of grouping the various Collection types together.
    If you don't know what I'm trying to say then you might have to see the interfaces I've made.
    And while I as at it, I also fiddled with the various method names.
    For example, add( int index, E element), I felt it should be insert( int index, E element). This type of minor things caused a lot of confusion for me back then, so I cared enough about this to change it to somthing I thought more appropriate. But I have no idea how appropriate my approach may seem to others. : )
    4.
    I see an iterator as something that iterates through a collection, and nothing else.
    Therefor, it bothered me that the Iterator interface had an optional remove method.
    I myself have never needed it, so maybe I just don't know how to appreciate it. How much is it used? If its heavily used, I guess I'm going to have to include it somehow.
    5.
    A LinkedList doesnt' support random access. But true random access is when you access randomly relative to the first index.
    Iterating from the first to the last with a for statement isn't really random access, but it still causes bad performance in the current LinkedList implementation. One would have to use the ListIterator to achieve this.
    But even here, if you want a ListIterator that starts in the middle of the list, you still need to traverse the list to reach that point.
    So I've come up with LinkedList that remembers the last accessed element using the basic methods get, set, remove etc, and can use it to access elements relatively from it.
    Basically, there is now an special interal "ListIterator" that is used to access elements when the basic methods are used. This gives way for several improvements (although that may depend how you look at it).
    It introduces some overhead in the form of if-else statemenets, but otherwise, I'm hoping that it will generally outperform the current LinkedList class (when using lists with a large nr of elements).
    6.
    I've also played around with the ArrayList class.
    I've implemented it in a way, that is something like a random-access Deque. This has made it possible to improvement certain methods, like inserting an element\Collection at some index.
    Instead of always shifting subsequent element to the right, elements can be shifted left as well. That means that inserting at index 0 only requires a single operation, instead of k * the length of the list.
    Again, this intrduces some overhead with if-else statements, but is still better in many cases (again, the List must be large for this to pay off).
    7.
    I'm also trying to do a hybrid between an ArrayList and a Linked list, hopefully allowing mostly constant insertion, but constant true random access as well. It requires more than twice the memory, since it is backed by both an ArrayList and a LinkedList.
    The overhead introduced , and the fact that worst case random access is no better than that of a pure LinkedList (which occurs when elelements are inserted at the same index many times, and you then try to access these elements), may make this class infeasible.
    It was mostly the first three points that pushed my over the edge, and made me throw myself at this project.
    You're free to comment as much as you like.
    If no real discussion starts, thats ok.
    Its not like I'm not having fun with this thing on my own : )
    I've started from scratch several times because of design problems discovered too late, so if you request to see some of the source code, it is still in the works and I would have to scurry off and add a lot of java-comments as well, to explain code.
    Great. Thanks!

    This sort of reply has great value : )
    Some of them show me that I need to take some other things into consideration. Some of them however, aren't resolved yet, some because I'm probably misunderstanding some of your arguments.
    Here goes:
    1.
    a)
    Are you saying that they're were made static, and therefor were implemented in a utility class? Isn't it the other way around? Suppose that I did put them into the List interface, that would mean they don't need to be static anymore, right?
    b)
    A bloated List interface is a problem. Many of them will however have a default not-so-alwyas-efficient implementation in a abstract base class.
    Many of the list-algorithms dump sequential lists in an array, execute the algorithm, and dump the finished list back into a sequential list.
    I believe that there are several of them where one of the "dumps" can be avoided.
    And even if other algorithms would effectively just be moved around, it wouldn't neccesarily be in the name of performance (some of them cannot really be done better), but in the name of consistency\convenience.
    Regarding convenience, I'm getting the message that some may think it more convenient to have these "extra" methods grouped in a utility class. That can be arranged.
    But when it comes to consistency with method names (which conacerns usability as well), I felt it is something else entirely.
    For example take the two methods fill and replaceAll in the Collections class. They both set specific elements (or all of them) to some value. So they're both related to the set method, but use method names that are very distinguished. For me it make sense to have a method called setAll(...), and overload it. And since the List interface has a set method, I would very much like to group all these related methods together.
    Can you follow my idea?
    And well, the Collections class would become smaller. If you ask me, it's rather bloated right now, and supports a huge mixed bag of related and unrelated utitlity methods. If we should take this to the extreme, then The Collections class and the Arrays class should be merged.
    No, right? That would be hell : )
    2,
    At a first glance, your route might do the trick. But there's several things here that aren't right
    a)
    In order to delete an object, you need to know where it is. The only remove method supported by PriorityQueue actually does a linear search. Increase and decrease operations are supposed to be log(n). Doing a linear search would ruin that.
    You need a method something like removeAt( int i), where i would be the index in the backing array (assuming you're using an array). The elemeny itself would need to know that int, meaning that it needs an internal int field, even though this field only is required due to the internal workings of PriorityQueue. Every time you want to insert some element, you need to add a field, that really has nothing to with that element from an object-oriented view.
    b)
    Even if you had such a remove method, using it to increase\decrease key would use up to twice the operations neccesary.
    Increasing a key, for example, only requires you to float the element up the heap. You don't need to remove it first, which would require an additional log(n) operations.
    3.
    I've read the link before, and I agree with them. But I feel that there are other ways to avoid an insane nr of interfaces. I also think I know why I arrive at other design choices.
    The Collection interface as it is now, is smart because it can covers a wide range of collection types with add and remove methods. This is useful because you can exchange elements between collections without knowing the type of the collection.
    The drawback is of course that not all collection are, e.g modifiable.
    What I think the problem is, is that the Collection interface is trying to be two things at once.
    On one side, it wants to be the base interface. But on the other side, it wants to cast a wide net over all the collection types.
    So what I've done is make a Collection interface that is infact a true base interface, only supporting methods that all collection types have in common.
    Then I have a separate interface that tries to support methods for exchanging elements between collections of unknown type.
    There isn't neccesarily any performance benefit (actually, it may even introduces some overhead), but in certainly is easier to grasp, for me at least, since it is more logically grouped.
    I know, that I'm basically challenging the design choices of Java programmers that have much more experience than me. Hell, they probably already even have considered and rejected what I'm considering now. In that case, I defend myself by mentioning that it isn't described as a possiblity in the FAQ : )
    4.
    This point is actually related to point 3., becausue if I want the Collection interface to only support common methods, then I can't have an Iterator with a remove method.
    But okay....I need to support it somehow. No way around it .
    5. 6. & 7.
    The message I'm getting here, is that if I implement these changes to LinkedList and ArrayList, then they aren't really LinkedList and ArrayList anymore.
    And finally, why do that, when I'm going to do a class that (hopefully) can simulate both anyway?
    I hadn't thought of the names as being the problem.
    My line of thought was, that okay, you have this arraylist that performs lousy insertion and removal, and so you avoid it.
    But occasionally, you need it (don't ask me how often this type of situation arises. Rarely?), and so you would appreciate it if performed "ok". It would still be linear, but would often perform much better (in extreme cases it would be in constant time).
    But these improvements would almost certainly change the way one would use LinkedList and ArrayList, and I guess that requires different names for them.
    Great input. That I wouldn't have thought of. Thanks.
    There is however some comments I should comment:
    "And what happens if something is suibsequently inserted or removed between that element and the one you want?"
    Then it would perform just like one would expect from a LinkedList. However if that index were closer to the last indexed position, it would be faster. As it is now, LinkedList only chooses either the first index or the last to start the traversal from.
    If you're working with a small number of elements, then this is definitely not worth it.
    "It sounds to me like this (the hybrid list) is what you really want and indeed all you really need."
    You may be right. I felt that since the hybrid list would use twice as much memory, it would not always be the best choice.
    I going to think about that one. Thanks.

  • How can you create an instance of a class using ClassLoader given only

    the class name as a String. I have the code below in the try block.
    Class myTest = this.getClass().getClassLoader().loadClass("Testclass");
    Object obj = myTest.newInstance();
    String className = obj.getClass().getName();I don't want to typecast the class like
    Testclass obj = (TestClass) myTest.newInstance();I want to be able to create the classs at runtime and then get the methods in the class and execute those methods. Can it be done without having to code the typecasting in before compile time?

    I read on the web of people creating objects from interfacesDoesn't sound like the thing to do... Theoretically you could create dummy classes on the fly that implement some interface, but that's not very useful.
    Sounds like you are trying to load classes and execute them via interfaces. Like this:
         Class clazz = Class.forName("java.util.LinkedList");
         Collection c = (Collection) clazz.newInstance();
         c.add("hello");
         c.add("world");
         System.out.println(Arrays.toString(c.toArray()));LinkedList is the class, Collection is the interface which LinkedList implements. You can then call the methods declared in the interface. The interface gets "compiled in" into the program and the classes that implement it get loaded whenever and from wherever you load them.
    You could also use reflection to call methods without an interface, but that is type-unsafe, inelegant, hackish, and just plain ugly.

  • Linked List trouble

    //I need to add a header node into this Linked list class and
    // i dont understand it. can anyone give me a few pointers.
    // This is the orginal code. What im trying to figure out is below.
    public abstract class LinkedList implements ListInterface
    protected class ListNode
    // Used to hold references tolist nodes for the linked list implementation
    protected Listable info; // the info in a list node
    protected ListNode next; // a link to the next node on the list
    protected ListNode list; // reference to the first node on the list
    protected int numItems; // Number of elements in the list
    protected ListNode currentPos; // Current position for iteration
    public LinkedList()
    // Creates an empty list object.
    numItems = 0;
    list = null;
    currentPos = null;
    public boolean isFull()
    // Determines whether this list is full.
    return false;
    public int lengthIs()
    // Determines the number of elements on this list.
    return numItems;
    public abstract boolean isThere (Listable item);
    // Determines if element matching item is on this list.
    public Listable retrieve (Listable item)
    // Returns a copy of the list element with the same key as item.
    ListNode location = list;
    boolean found = false;
    while (!found)
    if (item.compareTo(location.info) == 0) // if they match
    found = true;
    else
    location = location.next;
    return location.info.copy();
    public abstract void insert (Listable item);
    // Adds a copy of item to this list.
    public void delete (Listable item)
    // Deletes the element of this list whose key matches item�s key.
    ListNode location = list;
    // Locate node to be deleted.
    if (item.compareTo(location.info) == 0)
    list = list.next; // Delete first node.
    else
    while (item.compareTo(location.next.info) != 0)
    location = location.next;
    // Delete node at location.next.
    location.next = location.next.next;
    numItems--;
    public void reset()
    // Initializes current position for an iteration through this list.
    currentPos = list;
    public Listable getNextItem ()
    // Returns copy of the next element in list.
    Listable nextItemInfo = currentPos.info.copy();
    if (currentPos.next == null)
    currentPos = list;
    else
    currentPos = currentPos.next;
    return nextItemInfo;
    //now heres the part i dont get i need to make list point to a new
    // node say HeaderNode. Now wouldnt just...
    public LinkedList()
    // Creates an empty list object.
    numItems = 0;
    list.next = HeaderNode; //....this line do the trick???
    currentPos = null;
    I know that i cant use any insert methods to put it in, so what else could i possibly do?

    bump

  • When to use collection?

    Sorry to post such question in this forum , but i would like to recieve some interesting about this .
    I know the basics of collection but i dnt know when to use which one?
    I am totally confused that all are working for the same thing with little difference .
    Please suggest me some tutorial if do u have .
    Thanks in advance .
    Hope u will realize my problem.

    I am totally confused that all are working for the same thing with little difference .Ahh - but those little differences can be important.
    Basic rules
    1 - First decide if you need a List, Map or Set.
    2 - If it is List, probably use ArrayList
    3 - If it is a Map, probably use HashMap
    4 - For a Set, probably use HashSet.
    That covers 90% of the base cases. Most of the time you just need those base classes.
    As always there are the exceptions
    - If you are constantly reading/adding/removing from the ends of the list, and not accessing the middle, consider using LinkedList implementation.
    - If you want your Map to be ordered by key (like a dictionary for example), then TreeMap
    - If you want your Map to retain the order they were inserted, then LinkedHashMap
    Yes the differences are subtle between versions, but those subtleties can be important.
    However in most cases, you can just use the stock standard base class.

  • List interface

    I'm trying to improve the Genericity of my code by setting the return type of methods that return classes that implement the List interface to List. In other words, rather than force the class user to work with, let's say, an ArrayList returned by one of my methods, I'd like the user to be able to change the actual List class used if need be. Here's an example of how I'm currently creating a list:
    public List <String> getNames() {
    ArrayList <String> names = new ArrayList <String> ();
    // add elements to list here
    return names;
    I've looked in the Collections class for an appropriate method that will return a concrete List class but all the methods return immutable Lists. I'm looking for a similar method that returns a mutable List because I need to add elements to the List in the method. Any ideas?

    I'm a little confused by your response jverd. Not
    that I don't understand what you're saying, but
    rather, why you are saying it. If I return a
    concrete List class such as ArrayList, then how am I
    hiding the implementation details from the caller?
    If the caller knows that he must cast the returned
    List to an ArrayList then he obviously knows the
    "implementation details" because otherwise he
    wouldn't know the concrete type to cast to. At any
    rate, I appreciate the response.You don't want to ensure the user's flexibility, but YOUR flexibilty. Maybe on some point you decide that for some reason (mabye performance) you want a linkedList implementation rather than an arrayList. You can do that without breaking existing code, because you declared your method signature as general as possible.
    Imagine you are a package developer. You have shipped your first version, and some hundred customers are using your code. If you want to redesign your package and you break any method signature, ALL your customers have to recompile their code.
    To avoid that, you force them to operate on a very abstract level. If they still want to use the subtype - well, they can use reflection and casting, but they do it on their own risk.
    Writing against interfaces gives you the chance to make slight changes to the code without breaking existing implementations.

  • Help - can't print linked list object

    Hi all,
    I've written a program that creates an Airplane object. I've added the Airplane object to a linked list. I am trying to test by printing the linked list..but I get the addresses of the airplane object instead of the integer variables that the Airplane object contains. How can I fix this? Here's my output showing what I am talking about:
    Airplane type: 2
    Airplane arrival time: 600
    Airplane cleaning time: 45
    Airplane take-off time: 645
    [Airplane@665753]
    Airplane type: 3
    Airplane arrival time: 1100
    Airplane cleaning time: 60
    Airplane take-off time: 1160
    [Airplane@665753, Airplane@ef22f8]
    Airplane type: 1
    Airplane arrival time: 900
    Airplane cleaning time: 30
    Airplane take-off time: 930
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70]
    Airplane type: 1
    Airplane arrival time: 1100
    Airplane cleaning time: 30
    Airplane take-off time: 1130
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85]
    Airplane type: 3
    Airplane arrival time: 1000
    Airplane cleaning time: 60
    Airplane take-off time: 1060
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80]
    Airplane type: 2
    Airplane arrival time: 900
    Airplane cleaning time: 45
    Airplane take-off time: 945
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80, Airplane@10d81b]
    Airplane type: 2
    Airplane arrival time: 900
    Airplane cleaning time: 45
    Airplane take-off time: 945
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80, Airplane@10d81b, Airplane@dbe178]
    Airplane type: 3
    Airplane arrival time: 1000
    Airplane cleaning time: 60
    Airplane take-off time: 1060
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80, Airplane@10d81b, Airplane@dbe178, Airplane@af9e22]
    Airplane type: 1
    Airplane arrival time: 900
    Airplane cleaning time: 30
    Airplane take-off time: 930
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80, Airplane@10d81b, Airplane@dbe178, Airplane@af9e22, Airplane@b6ece5]
    Airplane type: 1
    Airplane arrival time: 700
    Airplane cleaning time: 30
    Airplane take-off time: 730
    [Airplane@665753, Airplane@ef22f8, Airplane@e0cf70, Airplane@52fe85, Airplane@c40c80, Airplane@10d81b, Airplane@dbe178, Airplane@af9e22, Airplane@b6ece5, Airplane@7ace8d]
    Airplane@665753
    import java.io.*;
    import java.util.*;
    public class AirPortSimulator {
         public static void main(String[] args) {
              LinkedList<Airplane> myEventList = new LinkedList();
                   //for loop to test random number generator for airplane type
              for( int i = 0; i < 10; i++){
                   int parOne = myNumber();
                   System.out.println("Airplane type: " + parOne);
                   int parTwo = myTime();
                   System.out.println("Airplane arrival time: " + parTwo);
                   int parThree = 0;
                   switch(parOne){
                   case 1: parThree = 30;break;
                   case 2: parThree = 45;break;
                   case 3: parThree = 60;break;
                   System.out.println("Airplane cleaning time: " + parThree);
                   int parFour=0;
                   switch(parOne){
                   case 1:     parFour = parTwo + 30;break;
                   case 2: parFour = parTwo + 45;break;
                   case 3: parFour = parTwo + 60;break;
                   System.out.println("Airplane take-off time: " + parFour);
                   System.out.println();
                   Airplane myAirplane = new Airplane(parOne, parTwo, parThree, parFour);
                   myEventList.addLast(myAirplane);
                   System.out.println(myEventList);
                   System.out.println();
         public static int myTime(){
              Random generator = new Random();
              int number = generator.nextInt(16)+1;
              number = number * 100;
              if (number < 600){
                   number = number + 600;
              return number;
         public static int myNumber(){
              Random generator = new Random();
              return generator.nextInt(3)+1;
    }

    I've written a method before that prints all the
    elements of a linked list..but that method onlyheld
    one integer or string...it was a "while (head !=
    null) loop that traversed the list and printed
    "head.info"
    But i'm confused with an object that has 4integers
    inside it...You don't have to write any kind of loop. The
    LinkedList implementation of toString does that for
    you. All you have to do is write a toString for
    Airplane that prints whatever you feel is important
    for a single Airplane object.
    But note that since the list uses commas to separate
    entries, your toString method will be clearer if you
    can write it in such a way that it doesn't use
    commas, or so that you can see where the output
    begins and ends. For example, maybe you can wrap the
    output with curly brackets.Thanks, I just had to understand what the toString method was and then how to override it. This works well:
    Thank you for pointing me in the right direction.
    aiki985
    public String toString(){
                  return "{" + airplaneType + ", " + arrivalTime + ", " +
                                  waitingTime + ", " + departureTime + "}";
              } // end toString method

  • Do my runtime make sense?

    HI..me again
    I just finished my code for runtime. And i am getting the runtime of the ArrayList implementation lower then the LinkedList Implementation. Does that make sense?
    Shouldnt the ArrayList runtime be higher ? at least thats what I am told by all my friends
    Note*= my assingnment was to create an Array and a linked list implementation of an unordered set. The interface had the following methods:
    public interface MySet {
        boolean isIn(Value v);
        void add(Value v);
        void remove(Value v);
        MySet union(MySet s);
        MySet intersect(MySet s);
        MySet difference(MySet s);
        int size();
        void printSet();
    }thanks for any reply:)
    Note*:new to programming
    Edited by: haraminoI on Mar 28, 2009 10:10 AM
    Edited by: haraminoI on Mar 28, 2009 10:12 AM
    Edited by: haraminoI on Mar 28, 2009 10:12 AM
    Edited by: haraminoI on Mar 28, 2009 10:13 AM
    Edited by: haraminoI on Mar 28, 2009 10:20 AM

    Which methods run faster for ArrayList?
    Which methods run faster for LinkedList?
    How large are the sets that you are using to do your tests? A larger set will show the differences better than a smaller set will.
    Try adding 1000 numbers to each set (add 1, 2, 3, ...,1000, in order). Which set could add them faster? [If it one isn't particularly faster or slower, try 10000 numbers or 50000 numbers.]
    Then try to remove the number '1' from each set. Which set could remove it faster?
    Then try to remove '500' from each set. Which set could remove it faster?
    Then try to remove '1000' [or other end number] from each set. Which set could remove it faster?
    Try calculating "size()" for each set. Which set gives you the answer faster (assuming you haven't kept a 'size' variable in your LinkedList, and that you calculate the size() by iterating through the list)?
    If you want to test with random numbers, you should add the same numbers to both lists in the same order. You might also want to keep track of what number is first, some numbers known to be in the middle, and some numbers at the end, so you can test how fast removal of the first element is. The "set" may be unordered, but the list will still be holding the items in the order that you added them.
    You should see that some operations are faster using ArrayList, and some are faster using LinkedList. Your exact implementations may cause some difference, but if the implementations are reasonable, there are certain operations that should be faster with ArrayList and certain that should be faster with LinkedList.

  • Generics with multiple interfaces

    I'm trying to figure out why the following is not valid:
    public class MediaService<L extends Deque<MediaFile> & List<MediaFile>> {
            L x = new LinkedList<MediaFile>();
    }Gives:
    Type mismatch: cannot convert from LinkedList<MediaFile> to LSeeing as LinkedList implements both these interfaces, I would expect this to be legal. What else is the use of the & operator in Generics?

    lhunath wrote:
    Basically:
    public static <T extends Deque<MediaFile> & List<MediaFile>> T newMediaList() {
    return new LinkedList<MediaFile>();
    It is possible to do this using covariant return types and a generic abstract factory, like this:
    import java.util.Deque;
    import java.util.LinkedList;
    import java.util.List;
    public class GT20 {
       public static void main(String[] args) {
          DequeListFactory<String, ?> factory = new LinkedListFactory<String>();
          Deque<String> d = factory.create();
          List<String> l = factory.create();
       private interface DequeListFactory<T, L extends Deque<T> & List<T>> {
          L create();
       private static class LinkedListFactory<T> implements DequeListFactory<T, LinkedList<T>> {
          @Override
          public LinkedList<T> create() {
             return new LinkedList<T>();
    }However, I would seriously question the use of such a factory. If you really have a need for a union of interfaces (I would suggest a design that requires/allows users to use your objects as Lists and Deques, something is seriously wrong), I would create such a union and use that in your contract. Java doesn't allow anonymous unions as you're trying to do, and using generics is just a hack. Here's what I might consider:
    import java.util.Deque;
    import java.util.LinkedList;
    import java.util.List;
    public class GT21 {
       private interface ListDeque<T> extends List<T>, Deque<T> {}
       private interface MyInterface<T> {
          ListDeque<T> getListDeque();
       private static class MyClass<T> implements MyInterface<T>{
          @Override
          public ListDeque<T> getListDeque() {
             return new MyLinkedList<T>();
       private static class MyLinkedList<T> extends LinkedList<T>
          implements ListDeque<T> {
    }

  • Hashtable on disc

    I've been looking crazy over the internet and in the forums, but haven't found any Hashtable implementation that stores on disc. Anyone know any good library for that?
    Gil

    Thanks all for your efforts.
    As you have pinpointed it's not easy to do a hashtable on disc (why I hoped and prayed there was already something
    out there so I didn't had to do it myself). But it is possible to do it myself I guess.
    As to having multiple persistent hash's sharing a file...
    that may be more difficult then it appears as hashes don't
    have a fixed size so the second hash can't just be appended to the first in the file Not hard. I already have a class "PortionedFile" that gives me instances of "FilePortion". It is virtual files that
    actually resides in only 1 physical file. It has some basic "memory handling". When a hash talbe grows, it requires
    the file to grow (eg double size), and the PortionedFile finds new space (which might be caused be ealrier remove
    portions) for the new file size and copies the old content to the new filespace and connects the virtual FilePortion
    to that new area. Very simple algorithm but efficient and not too spacewasting (and discspace is not that much of a
    problem anyway).
    Probably more like a couple thousand.
    I'm sure you know a file isn't like memory.
    You have to implement all allocation and deallocation mechanisms.
    When you remove an entry that's stored in the middle of the file
    what do you do with the "hole"? Re-use it?
    What will your strategy be to keep the file from becoming too fragmented?
    How will you recover from errors like the app crashing halfway through a write?I have a memory handler for disc, which will be useful when allocating space for data (including variable size keys
    and entries) in a similar way as memory allocation for primary memory is done (alloc in C, new in Java).
    BUT! Does anyone know of a good "allocation and deallocation mechanisms" for disc? Would guess a existing solution
    would not be too bad to use even if mine will "work".
    closed-address hashing where each bin
    (element in the internal array) is null or contains a pointer to a linked
    list. Therefore to save this beasty you need to have a persistant
    linkedlist implementation as well as a persistance mechanism for arrays.The hashtable implementation I was thinking of would use "closed-address hashing", Which includes "pointers" to the
    list for that "hash-bin". I actually don't know if this will cause more disc-reads then "open-adress hashing". The
    advantage as I can see with "closed-address hashing" is that the list for the "hash-bin" can be some kind of structure with all variable length keys and data for that list, so they all can be read in 1 single read. If more data is added to a list, the whole list will be rewritten to disc.
    Trust me, I had to implement an on-disk balanced tree maps (AVL/RedBlack). It was no picnic.I know this sad truth.
    I didn't understand how the ASN1 would be of any help and what matfud meant by "As for the disk format you
    may wish to use somthing similar to ASN1"
    Thanks again
    Gil

  • LinkedList Queue Implementation

    Hey guys/gals,
    Just messing around here with a LinkedList Queue implementation. Look at the code. Theres the main class with the main method. Theres the Node class that holds info for my nodes. Theres the Queue class that sets up the Queue with a linkedlist. In my main method im having problems with accessing the 4th node. Its created and put into the queue(linkedList) but whenever it is processed with the toString() method the LinkedList is giving indexOutofBounds index 1 size 1. Not sure why. Any help is appreciated thank you in advance. Code is below.
    import java.util.*;
    public class DijAlg {
            static int source = 0;
            static Queue Queue = new Queue();
            static int NUMBEROFNODES = 4;
        public static void main(String args[]){
        Node NodeA = new Node(), NodeB = new Node(), NodeC = new Node(), NodeD = new Node();
        Node[] Nodes = {NodeA, NodeB, NodeC, NodeD};
        for (int i = 0; i< NUMBEROFNODES; i++){
         for (int v = 0; v< NUMBEROFNODES; v++){
             Nodes.dist[v] = 10000;
    Nodes[i].previous[v] = 99;
    Nodes[i].dist[source] = 0; // Distance from source to source
    Queue.enqueue(NodeA);
    Queue.enqueue(NodeB);
    Queue.enqueue(NodeC);
    Queue.enqueue(NodeD);
    int i = 0;
    while (!Queue.isEmpty()){
    System.out.println("Node " + i);
    System.out.println(((Node)Queue.peek()).toString());
    Queue.dequeue();
    i++;
    static class Node {
    int [] dist;
    int [] previous;
    Node(){
    dist = new int [NUMBEROFNODES];
    previous = new int [NUMBEROFNODES];
    public String toString(){
    String myString = "Dist ";
    for(int i = 0; i < NUMBEROFNODES ; i++){
    myString = myString.concat(String.valueOf(dist[i]) + ", ");
    myString.concat("Prev ");
    for(int i = 0; i < NUMBEROFNODES; i++){
    myString = myString.concat(String.valueOf(previous[i]) + ", ");
    return myString;
    class Queue {
         LinkedList list;
         // Queue constructor
         Queue()
              // Create a new LinkedList.
              list = new LinkedList();
         boolean isEmpty()
         // Post: Returns true if the queue is empty. Otherwise, false.
              return (list.size() == 0);
         void enqueue(Object item)
         // Post: An item is added to the back of the queue.
              // Append the item to the end of our linked list.
              list.add(item);
         Object dequeue()
         // Pre: this.isEmpty() == false
         // Post: The item at the front of the queue is returned and
         // deleted from the queue. Returns null if precondition
         // not met.
              // Store a reference to the item at the front of the queue
              // so that it does not get garbage collected when we
              // remove it from the list.
              // Note: list.get(...) returns null if item not found at
              // specified index. See postcondition.
              Object item = list.get(1);
              // Remove the item from the list.
              // My implementation of the linked list is based on the
              // J2SE API reference. In both, elements start at 1,
              // unlike arrays which start at 0.
              list.remove(1);
              // Return the item
              return item;
         Object peek()
         // Pre: this.isEmpty() == false
         // Post: The item at the front of the queue is returned and
         // deleted from the queue. Returns null if precondition
         // not met.
              // This method is very similar to dequeue().
              // See Queue.dequeue() for comments.
              return list.get(1);
    Edited by: venture on Dec 17, 2008 4:51 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    Thanks for the help Encephalopathic. I came to the same conclusion but it just didn't add up when I looked through the code. The problem was that whoever wrote the code for the queue class(I borrowed the code) had used get(1) instead of getFirst(), and remove(1) instead of removeFirst(). So it was totally skipping the first index A.K.A ----> 0. New code below. Also added a name field that helped me to debug, Node "A" was not being printed which told me it was skipping its index.
    import java.util.*;
    public class DijAlg {
            static int source = 0;
            static Queue Queue = new Queue();
            static int NUMBEROFNODES = 4;
        public static void main(String args[]){
        Node NodeA = new Node("A"), NodeB = new Node("B"), NodeC = new Node("C"), NodeD = new Node("D");
        Node[] Nodes = {NodeA, NodeB, NodeC, NodeD};
        for (int i = 0; i< NUMBEROFNODES; i++){
         for (int v = 0; v< NUMBEROFNODES; v++){
             Nodes.dist[v] = 10000;
    Nodes[i].previous[v] = 99;
    Nodes[i].dist[source] = 0; // Distance from source to source
    Queue.enqueue(NodeA);
    Queue.enqueue(NodeB);
    Queue.enqueue(NodeC);
    Queue.enqueue(NodeD);
    int i = 0;
    while (!Queue.isEmpty()){
    System.out.println(((Node)Queue.peek()).toString());
    Queue.dequeue();
    i++;
    static class Node {
    int [] dist;
    int [] previous;
    String name;
    Node(String theName){
    dist = new int [NUMBEROFNODES];
    previous = new int [NUMBEROFNODES];
    name = theName;
    public String toString(){
    String myString = name;
    myString = myString.concat(" Dist ");
    for(int i = 0; i < NUMBEROFNODES ; i++){
    myString = myString.concat(String.valueOf(dist[i]) + ", ");
    myString = myString.concat("Prev ");
    for(int i = 0; i < NUMBEROFNODES; i++){
    myString = myString.concat(String.valueOf(previous[i]) + ", ");
    return myString;
    class Queue {
         LinkedList list;
         // Queue constructor
         Queue()
              // Create a new LinkedList.
              list = new LinkedList();
         boolean isEmpty()
         // Post: Returns true if the queue is empty. Otherwise, false.
              return (list.size() == 0);
         void enqueue(Object item)
         // Post: An item is added to the back of the queue.
              // Append the item to the end of our linked list.
              list.add(item);
         Object dequeue()
         // Pre: this.isEmpty() == false
         // Post: The item at the front of the queue is returned and
         // deleted from the queue. Returns null if precondition
         // not met.
              // Store a reference to the item at the front of the queue
              // so that it does not get garbage collected when we
              // remove it from the list.
              // Note: list.get(...) returns null if item not found at
              // specified index. See postcondition.
              Object item = list.getFirst();
              // Remove the item from the list.
              // My implementation of the linked list is based on the
              // J2SE API reference. In both, elements start at 1,
              // unlike arrays which start at 0.
              list.removeFirst();
              // Return the item
              return item;
         Object peek()
         // Pre: this.isEmpty() == false
         // Post: The item at the front of the queue is returned and
         // deleted from the queue. Returns null if precondition
         // not met.
              // This method is very similar to dequeue().
              // See Queue.dequeue() for comments.
              return list.getFirst();
    Here is the output
    run:
    A Dist 0, 10000, 10000, 10000, Prev 99, 99, 99, 99,
    B Dist 0, 10000, 10000, 10000, Prev 99, 99, 99, 99,
    C Dist 0, 10000, 10000, 10000, Prev 99, 99, 99, 99,
    D Dist 0, 10000, 10000, 10000, Prev 99, 99, 99, 99,
    BUILD SUCCESSFUL (total time: 2 seconds)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Performance with LinkedList in java

    Hello All,
    Please suggest me any solution to further improve the performance with List.
    The problem description is as follows:
    I have a huge number of objects, lets say 10,000 , and need to store the objects in such a collection so that if i want to store an object at some particular index i , I get the best performance.
    I suppose as I need indexed based access, using List makes the best sense as Lists are ordered.
    Using LinkedList over ArrayList gives the better performance in the aforementioned context.
    Is there are way I can further improve the performance of LinkedList while solving this particular problem
    OR
    Is there any other index based collection using that i get better performance than LinkedList?
    Thanks in advance

    The trouble with a LinkedList as implemented in the Java libraries is that if you want to insert at index 100, it has no option but to step through the first 100 links of the list to find the insert point. Likewise is you retrieve by index. The strength of the linked list approach is lost if you work by index and the List interface gives no other way to insert in the middle of the list. The natural interface for a linked list would include an extended Iterator with methods for insert and replace. Of course LinkedLists are fine when you insert first or last.
    My guess would be that if your habitual insertion point was half way or more through the list then ArrayList would serve you better especially if you leave ample room for growth. Moving array elements up is probably not much more expensive, per element, than walking the linked list. Maybe 150% or thereabouts.
    Much depends on how you retrieve, and how volatile the list is. Certainly if you are a read-mostly situation and cannot use an iterator then a LinkedList won't suit.

  • Need to find the source code for java.util.LinkedList

    Hello all,
    I'm new to the forums and I actually need the LinkedList source file as well as all the source files for all Java packages and libraries. Please post a link here if you can, or email me at [email protected]
    Thanks again!
    copter_man

    But those must be platform dependant, not really that
    interesting to look at. I have never felt any need to
    look at those at least.Wake up and smell the coffee, abbie! I read the source code all the time and constantly tell my students to do that, too.
    1. Java source code is not platform dependent. The original poster wanted to look at linked list code, how could that be platform dependent?
    2. It is the implementation of the SDK APIs, so by definition it is implementation dependent code, liable to change in a later version. So don't assume anything beyond what is claimed in the API documentation. However, sometimes the documentation is incomplete or ambiguous to you, and reading the source can provide some insight, however implementation dependent. (Light a candle or curse the darkness.)
    3. Why read source code? It's a good way to learn how to program. You see something in the API and ask: how'd they do that? Or you realize you want to do something broadly similar, but you can't reuse the source code.
    For example, Images are not Serializable, but suppose you want a small image that is part of an object to be serialized with the rest of the object without too much fuss (ie, without using javax.imageio). You notice ImageIcon is serializable, so you use it. (An ImageIcon has-an Image.) Then you wonder: how'd they do that? You read the source and then you know.
    You live, you learn,
    Nax

  • The problem in the thread pool implemented by myself

    Hello, I need to a thread pool in J2ME CDC 1.0 + FP 1.0, so I implemented a simple one by myself that also meets my own requirement.
    Here is the main idea:
    The thread pool creates a fixed number of threads in advance. When a task comes, it is put in the waiting list. All threads tries to get the tasks from the waiting list. If no task exists, the threads wait until someone wakes them up.
    Here are the requirements from myself:
    1. when a task has finished its work in one execution, it is put in the waiting list for the next run.
    2. the task can control the delay between when the task owner tries to put it in the waiting list and when the task is actually put in the waiting list. I need this function because sometimes I don't want the tasks to run too often and want to save some CPU usage.
    In my program, I creates two thread pools. In one pool, every task don't use the delay, and the thread pool works very well. The other pool has the tasks that use the delay, and sometimes, as I can see from the printed information, there are many tasks in the waiting list but 0 or 1 thread executes tasks. It seems that the waiting threads cannot wake up when new tasks comes.
    I suspect the code in addTask(), but cannot find the reason why it fails. Could anyone please help me find out the bug in my code? I put the code of thread pool below
    Thank you in advance
    Zheng Da
    ThreadPool.java
    package j2me.concurrent;
    import java.util.LinkedList;
    import java.util.Timer;
    import java.util.TimerTask;
    import alvis.general.Util;
    public class ThreadPool {
         private int maxQueueSize;
         private boolean running = true;
         private Thread[] threads;
         private LinkedList tasks = new LinkedList();
         private Timer timer = new Timer(true);
         private AtomicInteger usingThreads = new AtomicInteger(0);
         private synchronized boolean isRunning() {
              return running;
         private synchronized void stopRunning() {
              running = false;
         private synchronized PoolTask getTask() {
              while (tasks.isEmpty() && isRunning()) {
                   try {
                        this.wait();
                   } catch (InterruptedException e) {
                        e.printStackTrace();
              if (tasks.isEmpty())
                   return null;
              // Util.log.info(Thread.currentThread().getName() +
              // " gets a task, left tasks: " + tasks.size());
              return (PoolTask) tasks.removeFirst();
         private synchronized void addTaskNoDelay(PoolTask task) {
              tasks.addLast(task);
              notifyAll();
         private synchronized void addTask(final PoolTask task) {
              long delay = task.delay();
              if (delay == 0) {
                   addTaskNoDelay(task);
              } else {
                   timer.schedule(new TimerTask() {
                        public void run() {
                             addTaskNoDelay(task);
                   }, delay);
         private synchronized int numTasks() {
              return tasks.size();
         private class PoolThread extends Thread {
              public void run() {
                   Util.poolThreads.inc();
                   while (isRunning()) {
                        PoolTask task = getTask();
                        if (task == null) {
                             Util.poolThreads.dec();
                             return;
                        usingThreads.inc();
                        long currentTime = System.currentTimeMillis();
                        task.run();
                        long elapsedTime = System.currentTimeMillis() - currentTime;
                        if (elapsedTime > 100)
                             System.err.println(task.toString() + " takes " + ((double) elapsedTime)/1000 + "s");
                        usingThreads.dec();
                        if (!task.finish()) {
                             addTask(task);
                   Util.poolThreads.dec();
         public ThreadPool(int size, int taskQueueSize) {
              maxQueueSize = taskQueueSize;
              threads = new Thread[size];
              for (int i = 0; i < threads.length; i++) {
                   threads[i] = new PoolThread();
                   threads.start();
         public synchronized boolean executor(PoolTask task) {
              if (!isRunning()) {
                   return false;
              Util.log.info("Thread Pool gets " + task + ", there are "
                        + numTasks() + " waiting tasks");
              if (numTasks() >= maxQueueSize) {
                   return false;
              addTask(task);
              return true;
         public synchronized void destroy() {
              stopRunning();
              timer.cancel();
              // TODO: I am not sure it can wake up all threads and destroy them.
              this.notifyAll();
         public synchronized void printSnapshot() {
              System.err.println("using threads: " + usingThreads + ", remaining tasks: " + tasks.size());
    PoolTask.javapackage j2me.concurrent;
    public interface PoolTask extends Runnable {
         * It shows if the task has already finished.
         * If it isn't, the task will be put in the thread pool for the next execution.
         * @return
         boolean finish();
         * It shows the delay in milliseconds that the task is put in the thread pool.
         * @return
         long delay();

    are receiving/sends tasks packets time consuming operation in your case or not? if it is not you do not need to use thread pools at all. you can create a queue like in your code through the linked list and dispatch this queue periodically with minimum monitor usage. try this.
    import java.util.LinkedList;
    public class PacketDispatcher extends Thread {
        LinkedList list = new LinkedList();
        public PacketDispatcher (String name) {
            super(name);
        public void putTask(Task task) {
            synchronized (list) {
                list
                        .add(task);
                list.notify();
        public void run() {
            while (true/* your condition */) {
                Task task = null;
                synchronized (list) {
                    while (list.isEmpty())
                        try {
                            list.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                    task = (Task)list
                            .poll();
                if (task == null) {
                    try {
                        Thread
                                .sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    continue;
                task
                        .run();
                if (!task.isFinished()) {
                    putTask(task);
                Thread
                        .yield();
        public static void main(String[] args) {
            // just for test
            try {
                Thread.sleep (10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            PacketDispatcher dispatcher = new PacketDispatcher("Packet Dispatcher");
            Task task = new Task();
            dispatcher.putTask(task);
            dispatcher.start();
            try {
                Thread.sleep (10000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            Task task2 = new Task();
            dispatcher.putTask(task2);
    class Task {
        long result = 0;
        public boolean isFinished () {
            if (getResult() >= 10000000) {
                return true;
            return false;
        public void run() {
            for (int i = 0; i < 1000; i++) {
                result += i;
        public long getResult () {
            return result;       
    }

Maybe you are looking for

  • Need some help on data encryption in Forms 6i with Oracle Database.

    Hi, Here is my requirement: I have a username and a password field, and i can add new users to it and ofcourse set a password for it.This password will be visible as asteriks on the forms but i want it to entered in the encrypted format in the databa

  • "The home folder could not be created because the network name cannot be found" error in AD users and computers

    Our home folders are stored on a non-windows NAS device and with Windows XP and 2003 we've always got the above error when creating or modifying users home folders, even when the shares were al ready created and being used. However this was never rea

  • Why wont the SSD from my 2011 MBP work right away in my 2012 MBP?

    I have a 2011 MBP running a Samsung SSD 470 without a problem. I swapped the SSD into my new 2012 MBP which is, apart from the yearly updates (2.3 i5 to 2.5 i5 processor and RAM speed increase from 1333 to 1600) exactly the same computer. I expected

  • Error to start SQL developer in RHEL 5

    Getting an error when try to run sqldeveloper in Linux platform type the full pathname of a j2se installation (Or Ctrl-C to quit). the path will be stired in ~/.sqldeveloper/jdk Please help if anyone have idea to solve this problem. Thanks, Shailesh

  • MSI H87I How to Stream DTS Audio

    How to Stream DTS, DTS HD MA from my HTPC to my AV Reciever? I have no video card installed on the mother board. Current set-up is connected via HDMI cable from stock HDMI port of the mother board to HDMI input of AVR. HTPC Specs:  MoBo  - MSI H87I