Java Programming Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

What is Multicast setup RECEIVING

1. //Import some needed classes import sun.net.*; import java.net.*; 2. //Which port should we listen to int port = 5000; //Which address String group = "225.4.5.6"; 3. //Create the socket and bind it to port 'port' MulticastSocket s = new MulticastSocket(port); 4. //Join the multicast group s.joinGroup(InetAddress.getByName(group)); //Now the socket is set up and we are ready to receive packets 5. //Create a DatagramPacket and do a receive byte buf[] = byte[1024]; DatagramPacket pack = new DatagramPacket(buf, buf.length); s.receive(pack); 6. //Finally, let's do something useful with data we just received, like print it J System.out.println("Received data from: " + pack.getAddress().toString() + ":" + pack.getPort() + " with length: " + pack.getLength()); System.out.write(pack.getData(),0,pack.getLength()); System.out.println(); 7. //And when we have finished receiving data leave the multicast group and close the socket s.leaveGroup(InetAddress.getByName(group)); s.close();

What is Multicast setup SENDING

1. //Import some needed classes import sun.net.*; import java.net.*; 2. //Which port should we send to int port = 5000; //Which address String group = "225.4.5.6"; //Which ttl int ttl = 1; 3. //Create the socket but we don't bind it as we are only going to send data MulticastSocket s = new MulticastSocket(); 4. //Note that we don't have to join the multicast group id we are only sending and not receiving 5. //Fill the buffer with some data byte buf[] = byte[10]; for (int i=0; i<buf.length; i++) buf[i] = (byte)i; 6. //Create a DatagramPacket DatagramPacket pack = new DatagramPacket(buf, buf.length, InetAddress.getByName(group), port); 7. //Do a send. Note that send takes a byte for the ttl and not an int s.send(pack,(byte)ttl); 8. //And when we have finished sending data close the socket s.close();

What are the main components that sends a cookie to a client.?

1. Cookie aCookie = new Cookie("Visitor", "yes"); 2. aCookie.setMaxAge(60*60*24*365); // 1 year 3. response.addCookie(aCookie);

What are the components for Serialization?

1. IS-HAS implements Serializable 2. writeToFile(Animal an)throws FileNotFoundException, IOException 3.ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream("Animal.bin")); 4.out.writeObject(an);

What are the components for De-serialization?

1. IS-HAS implements Serializable 2.readFile() throws IOException, ClassNotFoundException 3.ObjectInputStream in = new ObjectInputStream(new FileInputStream("Animal.bin")); 4.Animal name = (Animal) in.readObject();

What is the role of Marshal in RMI?

1. Is the process of encoding the parameters before sending 2. During communication between two machines through RMI, parameters are packed into a message and then sent over the network. 3.In case of primitive data type while packing the message all the parameter is put together and header is attached to it while in case if the parameter is object they are been serialized. 4.Marshalling can we done by both stub and skeleton because both use request and reply methods. 5.translation of structured data items and primitive values into an external data representation.

Disadvantages of EJB?

1. It requires application server. 2. It is complex to understand and develop an EJB application. 3. It requires only client side application written in Java and not compatible for clients written in other languages.

Key components of Multicast:

1. MulticastSocket 2.DatagramPacket 3. InetAddress.getByName() 4. send() 5. leaveGroup() 6. Close()

What are the advantages of Multithreading?

1. Servers can handle multiple clients simultaneously 2. Makes application more responsive to user input. 3. Threads are independent. If an exception occurs in one thread, it doesn't affect the others. 4. Takes advantage of available multiple processors by executing the threads on different processors in parallel

What are the main components for JavaFX?

1. Stage(primary stage) 2.CheckBox anchovies = new CheckBox("Anchovies"); anchovies.setOnAction(this::processCheckBoxAction); 3.GridPane root = new GridPane(); 4.Scene scene1 = new Scene(root, 400, 300); 5.primaryStage.setTitle("Pizza Cost"); 6.primaryStage.setScene(scene); 7.primaryStage.show();

What are the advantages of Multicasting?

1. decrease of the network by sending all information as a unicast. 2. resource discovery 3. support for datacasting applications 4. flexibility in joining and leaving a group 5.Multicast reduces the CPU load on client computers by identifying and discarding the data packets.

Difference between RMI and EJB?

1.RMI is not a server-side component. It is not required to be deployed on the server. EJB is a server-side component, it is required to be deployed on the server. 2. In RMI, middleware services such as security, transaction management, object pooling etc. need to be done by the java programmer. In EJB, middleware services are provided by EJB Container automatically. 3.RMI is built on the top of socket programming. EJB technology is built on the top of RMI.

What are the disadvantages of Multithreading?

A major disadvantage of multithreaded programming is that it involves significant overhead, owing to the cost of thread creation, context switching and synchronization.

Which of the following is advantage of using JDBC connection pool? A. Better performance B. Less network overhead C. Using less memory D. Better communication

A. Better performance

Which of the following is advantage of using JDBC connection pool? A. Better performance B. Less network overhead C. Using less memory D. Better communication

A. Better performance

Which one of the following is incorrect about Servlet? A. Security - not reliable B. Full functionality of Java class library is available C. Platform independent D. Performance is better

A. Security - not reliable

Blocking a thread, in other words means invoking: A. wait() method or sleep() method B. sleep() method or block() method C. join() method or sleep() method or wait() method D. block() method or join() method or wait() method

A. wait() method or sleep() method

Arc Components

Arc(centerX, centerY, radiusX, radiusY, startAngle, arcLength) OPEN CHORD ROUND

JSP can't be used to: A. Access java beans B. Access remote server C. Access EJB D. Create dynamic web pages

B. Access remote server

A JavaBeans class has the following characteristics except: A. Has getter and setter methods B. Has constructor that can take arguments C. Implementing serializable is not mandatory D. Can be transported outside of Java's memory

B. Has constructor that can take arguments

The following specifies the advantages of: It is light weight It supports pluggable look and feel It enables GUI program to add various components A. AWT B. SWING C. Both A & B D. None of the above

B. SWING

You have a Swing label that tends to have more horizontal space than it needs to display its text. What code would you use to make the text within a label (Jlabel) be centered? A. new JLabel(labelText, JLabel.CENTER); B. label.setHorizontalAlignment(JLabel.CENTER); C. All of the above D. None of the above

C. All of the above

JDBC is: A. A class B. A driver C. An API D. A method

C. An API

RMI consists of all of the following except A. A registry object B. Every remote object must have a name registered in the registry C. Every remote object's address must be registered in the registry D. Every remote object's URL must be registered in the registry

C. Every remote object's address must be registered in the registry

Following are some of the subclasses of javax.swing.JComponent except: A. JTextComponent B. JSlider C. JCompoment D. JToolTip

C. JCompoment

Which of the following step establishes a connection with a database? A. Import packages containing the JDBC classes needed for database programming B. Register the JDBC driver, so that you can open a communications channel with the database C. Open a connection using the DriverManager.getConnection () method D. Execute a query using an object of type Statement.

C. Open a connection using the DriverManager.getConnection () method

A Servlet can't be used to A. Present records from excel B. Present records from database C. Present records from web page D. Present records from Java API

C. Present records from web page

EJB performs the following except: A. Security B. Object pooling C. Resource management D. Transaction management

C. Resource management

What are the components to check if a client has a cookie sent by the server?

Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) for(int i=0; i<cookies.length; i++) { Cookie c = cookies[i]; if ((c.getName().equals("Visitor")) && (c.getValue().equals("yes"))) break; } }

A byte stream created after serialization on Unix platform can be de-serialized on: A. Unix B. Windows C. Mac D. All of the above

D. All of the above

A byte stream created after serialization on Unix platform can be deserialized on: A. Unix B. Windows C. Mac D. All of the above

D. All of the above

JSP pages are written as text files that combine A. HTML code B. XML elements C. Embedded JSP action commands D. All of the above

D. All of the above

All of the following are steps to join a multicast group except: A. Establishing connection to the host B. Creating a Multicast Socket on the host C. Invoking to join the Group to communicate. D. None of the Above

D. None of the Above

Deploying EJB on client and servers ensures smooth communication between the two.

F

If you decide to use JSP, you should keep it separate from Servlets because the combination of the two doesn't work.

F

Like several other systems that tracks sessions, Cookies are not necessarily a session tracking system that Java uses.

F

Serialization of small packets on info doesn't require converting the state of the object into byte stream.

F

Synchronization can't be controlled at method level or block level.

F

When two Java threads have same priority, JVM will run the thread that was created first.

F

Image Class

Image img = new Image("gull.jpg"); ImageView imgView = new ImageView(img); StackPane pane = new StackPane(imgView); Scene scene = new Scene(pane, 500, 350); primaryStage.setTitle("Image Display"); primaryStage.setScene(scene); primaryStage.show();

Context switching

It refers to the process of storing and restoring of CPU state so that Thread execution can be resumed from the same point at a later point of time. Context switching is a type of process switching where we switch one process with another process.

A cookie must have a name, but other information are optional such as a comment, path and domain qualifiers, a maximum age, and a version number.

T

A layout manager can be explicitly set for each container.

T

Client program in real time takes some time to obtain any result, while waiting it can free up the CPU usage through a process called polling.

T

EJB application is separated from presentation and persistent layer.

T

If you decide to use JSP, you should keep it separate from Servlets because the combination of the two creates considerable conflict.

T

Multicasting can't be implemented for applets.

T

RMI doesn't require explicit connection between client and server for data communication.

T

The SetLayout() method is basically used to specify a container's layout.

T

To start a new thread defined by implementing Runnable interface we run this: new Thread(new MyThread()).start();

T

When a client invokes a remote method, it calls a proxy not the original method.

T

When serializing, it is also required that, all the fields of a class ought to be serialized.

T

When you decide to implement the Runnable interface to create a thread, you must override the run() method provided by Runnable interface.

T

Daemon Thread

is an infrastructure thread, e.g., the garbage collector thread and the GUI's event dispatcher thread

Synchronization is built around an internal entity known as the lock or monitor.

public class Lock { private boolean isLocked = false; public synchronized void lock() throws InterruptedException { while(isLocked) { wait(); } isLocked = true; } public synchronized void unlock() { isLocked = false; notify(); } }


Ensembles d'études connexes

Courts & Criminal Procedures (CH.3)

View Set

pharm 1 final drug cards and key terms

View Set

Alle Französisch-Vokabulartest seit 1. Lehrjahr

View Set

CCNA 2: Part 2 - Switching, Routing, and Wireless Essentials

View Set

Chapter 40, Chapter 38, Chapter 37 Final

View Set