Objektorienterad programmering i Java Provmoment: Ladokkod: Tentamen ges för: Tentamen NOJ011-20132-A51H3- Systemarkitektprogrammet 7,5 högskolepoäng Tentamensdatum: 2014-01-08 Tid: 09:00 14:00 Hjälpmedel: Inga hjälpmedel Totalt antal poäng på tentamen: För att få respektive betyg krävs: G=25 VG=38 50 poäng Allmänna anvisningar: Tentan har en teoretisk och en praktisk del. Fyll i ditt namn, personnummer och dina svar på svarsblanketten på nästa sida. Kontot för den praktiska delen lämnas ut efter att svarsblanketten lämnats in till en tentamensvakt. Notera att frågor där alternativen inleds med alternativen inleds med kan 1 till alla alternative vara korrekta. endast har ett korrekt alternativ. Om Spara alla filer på F: om inte annat specifikt anges. Stäng ner samtliga applikationer och logga ut (via ikon) när du är klar med tentamen. Vid olösliga problem med datorkonto, ta ett nytt och lämna in även detta i tentamensmappen. Den praktiska delen rättas endast om minst 50% av svaren på den teoretiska delen är korrekta. Rättningstiden är som längst tre veckor Viktigt! Glöm inte att skriva namn på alla blad du lämnar in. Lycka till! Ansvarig lärare: Rikard König Karl Jansson Telefonnummer: 033 435 5945 033 435 4399
Namn: (Ifylles av student) Personnummer: (Ifylles av student) Svarsblankett 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 A B C D E
Theory 1. contains predefined classes and interfaces for developing Java programs. a. Java language specification b. Java API c. Java JDK d. Java IDE 2. Which of the following statements are true? a. Multiple constructors can be defined in a class. b. Constructors do not have a return type, not even void. c. Constructors must have the same name as the class itself. d. Constructors are invoked using the new operator when an object is created. 3. Which of the following alternatives is not a GRASP pattern a. Low coupling b. High Cohesion c. Indirection d. Adapter 4. Which of the following statements are true? a. Information Expert regards which classes that should exist. b. Pure fabrication regards which classes that are allowed in an application. c. Creator regards how an object should be created. d. GRASP stands for General Relation Assignment Specification Pattern 5. Which of the following statements are true? a. A method can be overloaded in the same class. b. A method can be overridden in the same class. c. If a method overloads another method, these two methods must have the same signature. d. If a method overrides another method, these two methods must have the same signature. e. A method in a subclass can overload a method in the superclass.
6. Which component cannot be added to a container? a. JPanel b. JButton c. JFrame d. JComponent 7. Which of the following statements are true? a. You may create a Graphics object using new Graphics(). b. Whenever a GUI component is displayed, its Graphics object is automatically created. c. The paintcomponent method is automatically invoked by the JVM. You should never invoke it directly. d. Invoking repaint() causes paintcomponent to be invoked by the JVM. 8. An instance of describes the errors caused by your program and external circumstances. These errors can be caught and handled by your program. a. RuntimeException b. Exception c. Error d. Throwable e. NumberFormatException 9. Which of the following statements regarding abstract methods are true? a. Abstract classes have constructors. b. A class that contains abstract methods must be abstract. c. It is possible to declare an abstract class that contains no abstract methods. d. An abstract method cannot be contained in a nonabstract class. e. A data field can be declared abstract. 10. Which of the following statements registers a panel object p as a listener for a button variable jbt? a. addactionlistener(p); b. jbt.addactionlistener(p); c. jbt.addactioneventlistener(p); d. jbt.addeventlistener(p);
11. Which of the following statements are true? a. Inner classes can make programs simple and concise. b. An inner class can be declared public or private subject to the same visibility rules applied to a member of the class. c. An inner class can be declared static. A static inner class can be accessed using the outer class name. A static inner class cannot access nonstatic members of the outer class. d. An inner class supports the work of its containing outer class and is compiled into a class named OuterClassName$InnerClassName.class. 12. Which of the following is true? a. Any applet must be an instance of java.awt.applet. b. You must always provide a no-arg constructor for an applet. c. You must always provide a main method for an applet. d. You must always override the init method in an applet. 13. Which of the following statements are true? a. You can create a URL object for any public accessible resource on the Internet. b. You can create a URL object for a local file. c. A URL object may be created using the new URL(urlString) constructor. d. A URL object may be returned using the getsource method on a meta object (instance of java.lang.class). 14. Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat? a. DataOutputStream outfile = new DataOutputStream(new File("out.dat")); b. DataOutputStream outfile = new DataOutputStream(new FileOutputStream("out.dat")); c. DataOutputStream outfile = new DataOutputStream(FileOutputStream("out.dat")); d. DataOutputStream outfile = new DataOutputStream("out.dat"); 15. Which of the following statements is correct? a. Generics can help detect type errors at compile time, thus make programs more robust. b. Generics can make programs easy to read. c. Generics can avoid cumbersome castings. d. Generics can make programs run faster.
16. You can use the method to force one thread to wait for another thread to finish. a. sleep(long milliseconds) b. yield() c. stop() d. suspend() e. join() 17. The server listens for a connection request from a client using the following statement: a. Socket s = new Socket(ServerName, port); b. Socket s = serversocket.accept() c. Socket s = serversocket.getsocket() d. Socket s = new Socket(ServerName); 18. RMI is about. a. passing primitive data between a server and a client b. passing objects between a server and a client c. accessing remote objects and invoking methods from remote objects. d. java.lang.cloneable 19. Which of the following statements are true? a. You may load multiple JDBC drivers in a program. b. You may create multiple connections to a database. c. You may create multiple statements from one connection. d. You can send queries and update statements through a Statement object. 20. To execute a SELECT statement "select * from Address" on a Statement object stmt, use a. stmt.execute("select * from Address"); b. stmt.executequery("select * from Address"); c. stmt.executeupdate("select * from Address"); d. stmt.query("select * from Address");
Praktiska uppgifter 21. GUI- och objektorienteringsuppgift Uppgiften består i att utveckla en enkel miniräknare som uppfyller följande specifikationer: Kravlista: - Räknesätt som skall stödjas är addition, subtraktion, multiplikation och division, det skall vara möjligt att kombinera dessa fritt i en och samma uträkning. - Det skall vara enkelt att utöka räknarens räknesätt med hjälp av arv och polymorphism. - Siffror och räknesätt skall kunna matas in med hjälp av GUI-knappar med logiska symboler på. - När en uträkning byggs upp skall den visas i en oediterbar textruta. - Resultat av en uträkning fås genom en dedikerad knapp (=) och skall visas i en oediterbar textruta. Det är tillåtet att använda färdiga komponenter (knappar, textrutor etc.) för GUI-delarna. 15p 22. Nätverks- och trådningsuppgift Uppgiften består I att utveckla en enkel chat-server och chat-klient som uppfyller följande specifikationer: Generella krav: - Nätverkskommunikation skall hanteras med hjälp av sockets. - Server och klienter behöver bara ha stöd för att fungera på en och samma maskin (localhost), men det skall fortfarande vara enkelt att utöka programmet till att fungera mellan olika datorer. Kravlista Server: - Servern skall kunna hantera upp till 100 klienter på samma gång. - Servern skall acceptera nya klienter i en egen tråd. - Servern skall ta emot textmeddelanden ifrån klienter i separata trådar. - Servern skall sända ut meddelanden som den tar emot till alla uppkopplade klienter. Kravlista Klient: - Klienten skall automatiskt koppla upp emot servern när den startas (localhost) - Klienten kan vara konsolbaserad eller ha ett enkelt GUI (välj det som känns lättast) - Klienten skall kunna skicka textmeddelanden till servern. - Klienten skall kunna ta emot och visa textmeddelanden ifrån servern. Förutom dessa krav antas det att ni använder goda objektorienterade metoder för att bygga upp er kod. 15p