Help with exam question

Please can someone help with this exam question I have. I have no idea about it I have been looking through loads of website and class documentation but I still have no answer.
Please can someone explain this to me thanks
Consider the following code:
Import java.util.hashmap;
Import java.util.map;
Public myClass {
     Private Map <Integer, Object> myMap = New HashMap <Integer, Object> ();
     Public void addStuff(int id, Object Stuff) {
               myMap.add(new Integer(id), stuff);
     Public Map getMyMap() {
               Return myMap;
Why is myMap declared as a Map and not a HashMap?

It's called programming against the interface.
The code using myMap doesn't need to know that it's a HashMap, but only needs to know that it's a Map (Map is an interface that HashMap implements, so every HashMap is-a Map).
Since that knowledge is not required it's better not to give it away.
If at some point we decide that HashMap is not the best choice here we can easily change it to any other Map implementation (such as TreeMap for example) and only need to change that one line.

Similar Messages

  • HT5699 Help with car questions

    Wont let me buy things because security question for cars how lame is that!!!

    Help with security question about cars

  • Please help with  exam 1Z0-211( General Ledger)

    I am taking exam 1Z0-211 ( General Ledger) soon i really need help with some practice questions . If someone has some practices questions and answers please send them to my e-mail; Thanks in advance!
    E-mail: [email protected]

    From your crash report >   OS Version:      Mac OS X 10.7.2 (11C74)     <   outdated version of Lion
    Install this combo update >  OS X Lion Update 10.7.5 (Client Combo)
    Then restart your Mac, then try Safari.

  • Help with SCJP Question

    Hi,
    I don't understand the answer to the question below. Why doesn't it print "pre " first since this is the first line of main?
    I'm not sure I understand the order of the rest either. I've read the chapter that goes with this but still can't understand it.
    Hope someone can help.
    Thanks
    Question:
    Given:
    class Bird {
    { System.out.print("b1 "); }
    public Bird() { System.out.print("b2 "); }
    class Raptor extends Bird {
    static { System.out.print("r1 "); }
    public Raptor() { System.out.print("r2 "); }
    { System.out.print("r3 "); }
    static { System.out.print("r4 "); }
    class Hawk extends Raptor {
    public static void main(String[] args) {
    System.out.print("pre ");
    new Hawk();
    System.out.println("hawk ");
    What is the result?
    A. pre b1 b2 r3 r2 hawk
    B. pre b2 b1 r2 r3 hawk
    C. pre b2 b1 r2 r3 hawk r1 r4
    D. r1 r4 pre b1 b2 r3 r2 hawk
    E. r1 r4 pre b2 b1 r2 r3 hawk
    F. pre r1 r4 b1 b2 r3 r2 hawk
    G. pre r1 r4 b2 b1 r2 r3 hawk
    H. The order of output cannot be predicted.
    D is correct. Static init blocks are executed at class loading time, instance init blocks run
    right after the call to super() in a constructor. When multiple init blocks of a single type
    occur in a class, they run in order, from the top down.

    The static initializer blocks in the Raptor class are executed when the Raptor class is loaded. This is not the same time as an instance of a Raptor (or derived class) object is created, but at class-load time. This happens before the main method is executed, because in order to execute main, the VM first had to load the Hawk class. To load the Hawk class, it had to load the Raptor class (since Hawk extends Raptor). It also had to load the Bird class, but that class has no static initializers, so that didn't affect anything output.

  • Help with array question

    hi,
    i need some help with this piece of code. wat would it output to the screen?
    int [] theArray = { 1,2,3,4,5};
    for (int i = 1; i < 5; i++)
    System.out.print(theArray * i + "; ");
    would it output 1 * 1;
    2 * 2;...
    thanx
    devin

    Ok...
    1] Your index into the array is off by 1 - remember that array indexing starts from 0.
    2] You cannot multiply an array object. The contents? fine , go ahead but NOT the array
    so your output should be something like:
    operator * cannot be applied to int[] :d
    try
    int[] theArray = {0,1,2,3,4,5};
    for(int i = 1;i<6;i++)
         System.out.print(theArray*i+";");
    giving you an output of 1;4;9;16;n...
    if you were looking for the output stated change
    System.out.print(theArray*i+";");
    to
    System.out.print(theArray[i]+"*"+i+";");done...

  • Please help with slicing question

    I'm new to FW and to slicing. I have tried to get all of the info from tutorials and the help that I could.I'm still confused.I'm trying to produce a multi page website mockup with FW using export to CSS and Images.
    I've submitted two other posts with 0 replies. I guess my questions were too broad? I've done some trial and error and tried testing with a simplified version of the multi page website mockup I'm trying to produce. See the simplified file here:
    http://www.openrangeimaging.com/test-posts/slicetest01.png
    The top area would be the header. The lower bar will have some nav tabs. The circle is to be a logo that if clicked on will take the user to the home page.. Below the nav bar is to be two columns with content.
    I have tried different ways of slicing this but cannot get the file to export correctly as CSS and Images. I also can't seem to include the logo as a slice with a link without getting the "overlap" problem. I have been beating myself against this for some time and have not had any success. Any help or advice on where to get help or any reply at all will be most appreciated. Thanks!

    Great, my entire message was wiped out. Here it is again:
    My comments are inline.
    On 2010-10-14, at 2:16 AM, markf12 wrote:
    Jim, thank you for your very helpful reply!
    Honestly I wouldn't even try to directly export this design from FW to a CSS based layout. I think I'd move a lot faster by exporting the graphics from FW and building the design in DW.<<
    This is what I needed to know. Being new to FW I was mistakenly assuming that I could use the Images and CSS to export a clicklable mockup that would also form the html/css basis of the 15 page site I'm designing. I thought that this was possible if only I could figure out how. I expected some pretty involved work in Dreamweaver would be needed. I now understand that for what I'm doing using the HTML and Images is what should be used. Then I develop the site in Dreamweaver using perhaps some images exported from the FW mockup, but not any html or css. Thank you for clearing that up for me! I knew i had some fundamental/core misunderstanding. The export to Images and CSS is only for very simple design.
    JB - It IS possible, but you have to design the site based on certain practices. Overlapping slices is one thing to avoid.
    . If you're new to Fireworks, you really want to keep things simple as  you learn the process. Regardless, a solid knowledge of HTML and CSS is  very important.<<
    Yes I'd like to keep it simple but this is a bit of trial by fire (pun intended) on a project. I have gotten books and other tutorial type stuff on html and css. I would not call my knowledge of it solid as I am new to it. i think I get the gist of it and am determined to become proficient. The only real way to do that is to actually create something/gotta start somewhere so.......
    JB - getting the "gist" isn't enough. If you do not have a solid grounding in HTML and CSS, you will likely run into trouble even IF you successfully export the design, because you will need to to edit and tweak the code once you're in DW. I'd recommend building your first sites "the old fashioned way" first, before trying to automate the process.
    David Hogue has created a great series of CSS export videos on the Fireworks Dev Center. I strongly recommend watching them. Likewise Michel Bozgounov has written an excellent article on setting up a Fireworks document for CSS export:<<
    I had viewed a number of  Dave H's tutorials. I somehow overlooked the ones that you provided a link to. I'm going to watch them straight away. I had read the Article by Michel B. also excellent. I have also read your excellent tutorials and watched your lynda.com video training. I've gained allot from all of this.
    Thanks again for your help!
    JB - You're very welcome. Good luck.

  • I need help with some questions

    I seen where it said if something happens to your computer that you will loose the music you bought and downloaded . Will you also loose the information about your itunes gift card ?How do you run a diagnostic before you buy ? Is there a phone number to contat someone in this case , or could it be sent to my E-Mail address ? Also I would like to thank the people that helped me with my first question .

    It has always been very basic to always maintain a backup copy of your computer, so if somethign happens to your computer, you lose nothing, as you have a backup copy.
    "Will you also loose the information about your itunes gift card ?"
    When you redeem a gift card the balance is on your account.  It is accessible from anycomputer with itune, when you sign into your account.  This would not be affected by lodd of your computer.  Again, you should ALWAYS have a backup copy of your computer.
    "How do you run a diagnostic before you buy ? "
    Runa diagnostic of what before you buy what?
    "Is there a phone number to contat someone in this case , or could it be sent to my E-Mail address ?"
    Again,  in what case?  Could what be sent to your e-mail?

  • Plz help with 2 question's!!

    I am trying to fix a nano for a friend, she said that she has updated itunes and it shows her songs and acted as if they all d/l to ipod fine but they do not show up on ipod. I hooked it up to my comp. with my updated itunes, it shows up in itunes and on my computer as a removable disc AND when I go to my comp. and explore that drive, the songs are there and work. In itunes it does show that disc space has been used on the ipod but nothing else shows up. I've tried the good ole restore that I've never gotten to work on any ipod. I tried doing the udater and after waiting 3 hrs.(gotta love dial-up)it said that there was some error and couldn't update. What next? B/U her songs and restore? The second ques. is on my own nano, I've tried to do the updater for it and itunes acts like it is d/l but the progress bar never moves. What's that all about and do I really need the updater? Thanks in advance!!

    1. How are you getting the songs onto the iPod? Are you dragging them to the iPod like it is in Enable Disk Mode (dragging songs to it like a HDD), or are you putting them on through iTunes? Is Enable Disk Mode turned on?
    Check this out:
    My Computer Recognizes iPod as a Different Drive
    As for your second question, well, can't answer that one. Sorry!
    I hope this helps!

  • Help with wireless question

    ok, so ive just gotten back from university, and im looking into buyin a wireless router so that i can connect to the internet with my macbook. i was wondering what the best router would be considering i have a home PC that is connected to the internet with a broadband modem. im not looking for anything fancy, just something that will connect me to the internet (with a decent connection speed, and wont lose connection if i move around my house). because i am a university student, im lookin for somethin that isnt too expensive (but i will dish out the money if i have to). thanks in advance!!
    MacBook   Mac OS X (10.4.9)  

    Personally I would purchase (and have) the Airport Extreme Base Station (the new one.) But if that's too expensive you might look for someone on eBay selling a used older version AEBS. As for new I have had good luck with the D-Link DI-524 four port wireless router. Seems to work well with the Mac. However, don't expect any support from D-Link. However, the manuals are decent and what applies to Windows is pretty much the same for OS X.
    Why reward points?(Quoted from Discussions Terms of Use.)
    The reward system helps to increase community participation. When a community member gives you (or another member) a reward for providing helpful advice or a solution to their question, your accumulated points will increase your status level within the community.
    Members may reward you with 5 points if they deem that your reply is helpful and 10 points if you post a solution to their issue. Likewise, when you mark a reply as Helpful or Solved in your own created topic, you will be awarding the respondent with the same point values.

  • Help with simple question.......

    This is a simple question but i can't seem to figure it out.
    For example i am using this code...
    feel free to run this code...
    When you run this you see the scrollbars with the Swing look (Bars look so nice)...
    I am using this same type of code in my other project with JBuilder 7 and I am getting the plain look of the scrollbars.
    Any suggestions will be greatly appreciated..
    =======================================================
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.*;
    import java.awt.event.*;
    public class SimpleTableDemo extends JFrame {
    private boolean DEBUG = true;
    public SimpleTableDemo() {
    super("SimpleTableDemo");
    Object[][] data = {
    {"Mary", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Mark", "Andrews",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Angela", "Lih",
    "Teaching high school", new Integer(4), new Boolean(false)}
    String[] columnNames = {"First Name",
    "Last Name",
    "Sport",
    "# of Years",
    "Vegetarian"};
    final JTable table = new JTable(data, columnNames);
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    if (DEBUG) {
    table.addMouseListener(new MouseAdapter() {
    public void mouseClicked(MouseEvent e) {
    printDebugData(table);
    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);
    //Add the scroll pane to this window.
    getContentPane().add(scrollPane, BorderLayout.CENTER);
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    private void printDebugData(JTable table) {
    int numRows = table.getRowCount();
    int numCols = table.getColumnCount();
    javax.swing.table.TableModel model = table.getModel();
    System.out.println("Value of data: ");
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + model.getValueAt(i, j));
    System.out.println();
    System.out.println("--------------------------");
    public static void main(String[] args) {
    SimpleTableDemo frame = new SimpleTableDemo();
    frame.pack();
    frame.setVisible(true);

    any help will get DUKE $$$$$$$$$$$$$$$$

  • Help with maintenance question

    This might be a dumb question, I don't know. I have always been a pc user until just recently when I purchased my first macbook pro. My question is about routine maintenance. With my old dell I would have to delete temporary files, defrag the hard drive, check for spyware, etc. every so often. Do I have to do any type of maintenance for my mac? If you respond please respond in detail because I am completely unfamiliar with macs up to this point. Any help would be appreciated.
    thanks

    I wouldn't worry about it too much at the beginning. Just take the time to get used to the mac. It used to be the case that you were advised to run "cron jobs" or get a utility to run them (these are unix jobs that are traditionally scheduled to run at night) but my understanding is that Leopard (OSX 10.5) does them as necessary.
    Macs have always been light in terms of maintenance. The only other thing that you could do is to go to the disk utility (applications/uitilities). Select your hard drive on the left and the first aid tab and click "repair permissions". This will check system file permissions and can be a useful thing to do after a system update. To be honest, I wouldn't even worry about that for a few months either or until after the 10.5.2 update when it comes out.
    Honestly can't think of anything else. No spyware that I'm aware of, but be careful on the web obviously.
    Just enjoy the machine.
    Best of luck.
    PS - No defragmenting needed. There are circumstances in which it can help, but sometimes it can actually hurt - the mac manages its' own fragmentation.
    PPS - Run software update regularly.
    PPPS - Get an external drive and keep a backuop.

  • Blackberry Virgin - Please help with these questions

    Hi there
    I have just received my Blackberry 8900 and have a few questions if anyone can help:
    - Is there any way of having a clock display whilst the phone is on "sleep" mode. I use my phone to keep track of time alot so is there anyway of having the clock permanently displayed when phone is not in use?
    - I cant seem to be able to send a contact by SMS which seems a bit strange. Usually with my old phones I have been able to click on the Contact and access a "Send contact  by text" option.
    - The track ball I find a bit uncomfortable to use especially when having to click it, are there other navigation type pads on other phones rather than track ball?
    - I am  not currently connected to internet and wont be until next week when my new billing system starts. Can I use IM without internet access?
    Thats it for starters! Thanks in advance for your help

    Please help me!! Nobody can help you unless you have shown the willingness to learn and are seeking help only where you are stuck.
    My assignment is due in 2 days That doesn't matter to people over here.
    hese are practice questions and not part of the actual assignment so dont hesitate to provide the answer!!Doesnt matter again. what you have posted here is a problem text without any effort on your part to understand it or implement it. That is an assignment to us and we did our Java assignments for our course work long time ago.
    Bottom line - learn Java. If your course is not helping you with that, find a different course.

  • Help with FLASHING QUESTION mark when starting the mac

    Hi All,
    My mac just froze,i had to do force shut down,when i restarted it i had the flashing question mark.Did all the instruction that are given in the site:restarting with the installation CD and then using the *disc utility*-BUT i could not find the hard drive that i need to do the "repair disc " on.So i did what the document said and i reset the PRAM-still my hard drive does not show up in the disc utility.I also tried to reset the SMC but again -same result.
    please please try and help me,is my HD doomed? is there anything else i should try?

    I have the exact same problem.
    Today, when I turned my macbook on, it was so slow, that I decided to restart it. When I turned it on again, I got the folder with a questionmark in it on the display. Tried to put the installer CD in, but it couldn't find the HDD. Ran the Disk Utility, which said: "Invalid node structure" and "Invalid record count".
    I think the HDD is "destroyed", because it makes strange sounds. But how? And why?
    The Macbook isn't even a year old.
    Any help?

  • Please help with basic questions

    I hardly ever use flash, as i'm always ending up kicking
    stuff out of sheer frustration. Just like with Quark Xpress, in
    Flash there seem to be several 'layers' between what my intuition
    tells me should work, and the actual execution of the things i want
    to achieve. But nevermind, I'm just severely annoyed.
    I got 10 buttons, with a graphic as bottomlayer, and a number
    (1-10). Isn't it possible to turn the first button into a symbol,
    and then make copies where i just have to change the number? For
    now it doesn't matter if i copy/paste them or drag them from the
    library, when i copy the button and try to change the number in the
    copy, then the number in the 'original' changes as well.
    Do i really have to 'make' each button from scratch?
    This might seem like a very basic question, but i'm really
    bangin my head into the wall here. And theres tons og issues like
    that in Flash - for me at least - like if i say 'paste in place',
    things get pasted some random place on the canvas (anywhere but in
    place). If i convert to symbol, the referencepoint (or the point
    which it's supposed to rotate around) seems randomly choosen as
    well - at least it's never where i told it to be in the appropriate
    dialog.
    HELP! :-(

    Go to the library and there should be an arrow in the corner
    that gives you options. One option is "duplicate symbol." Duplicate
    your button and give it a new name, then make the changes.

  • NEED HELP WITH A QUESTION ABOUT PURCHASING A NEW IPOD AFTER GIVING MY OLD

    IPOD TO MY SON. IT WAS FILLED WITH 3600 SONGS AND I STILL HAVE THOSE SONGS IN MY ITUNES LIBRARY. MY QUESTION IS CAN I BUY A NEW IPOD AND LOAD IT ON COMPUTER USING MY ITUNES LIBRARY--I MEAN WILL ITUNES AND MY COMPUTER RECOGNIZE THE NEW ONE. IF NOT, WHAT CAN I DO? JEFF

    You should be fine, just make sure the new one has the current firmware, dock it to the computer, & away you go.
    Please kill the "caps lock" key when posting, it's considered to be shouting & it's rude. Thanks.

Maybe you are looking for