Java Complex Flashcards

1
Q

What does the word static do.

A
Call a static method using a class name
Math.min(88,86);
Call a non-static method using a reference variable name
Song t2 = new Song(); 
t2.play();
Static doesn't need a NEW object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Syntax for wrapping a primitive

A
wrapping a value
int i = 288;
Integer iWrap = new Integer(i);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Syntax for unwrapping a syntax

A

unwrapping a value

int unWrapped = iWrap.intValue();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

List of wrappers

A
Boolean 
Character 
Byte 
Short 
Integer
Long 
Float 
Double
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Format of a fomat modifier(%)

A

%[argument number][flags][width][.precision]type

ex.format(“%,6.1f”, 42.000)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Types of Format modifiers

A

%d decimal
%f floating point
%x hexadecimal
%c character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Types of date format modifiers.

A
The complete date and time %tc String.format(“%tc”, new Date());
Sun Nov 28 14:52:41 MST 2004

Just the time %tr
String.format(“%tr”, new Date());
03:01:47 PM

Day of the week, month and day %tA %tB %td
Date today = new Date();
String.format(“%tA, %tB %td”,today,today,today)
Sunday, November 28

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

WHat does a try/catch do and syntax.

A

Tells compiler that something may go wrong please prepare for it.

try {
// do risky thing
} catch(Exception ex) { // try to recover
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Syntax for creating a new socket.

A

Socket chatSocket = new Socket(“196.164.1.103”, 5000)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

To read data from a socket.

A
1. Make a Socket connection to the server
Socket chatSocket = new Socket(“127.0.0.1”, 5000);
2. Make an InputStreamReader chained to the Socket’s low-level (connection) input stream
InputStreamReader stream = new InputStreamReader(chatSocket.getInputStream());
3. Make a BufferedReader and read!
BufferedReader reader = new BufferedReader(stream); String message = reader.readLine();
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

To write data to a Socket

A
1. Make a Socket connection to the server
Socket chatSocket = new Socket(“127.0.0.1”, 5000);
2.Make a PrintWriter chained to the Socket’s low-level (connection) output stream
PrintWriter writer = new PrintWriter(chatSocket.getOutputStream());
3.Write (print) something
writer.println(“message to send”); writer.print(“another message”);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly