import java.io.*;
import java.net.*;
import java.util.*;
/**
* This program makes a socket connection to the atomic clock in Boulder,
* Colorado, and prints the time that the server sends.
*/
public class Time_Server_Socket_Test_Java {
public static void main(String[] args) {
try {
Socket s = new Socket("time-A.timefreq.bldrdoc.gov", 13);
try {
InputStream inStream = s.getInputStream();
Scanner in = new Scanner(inStream);
while (in.hasNextLine()) {
String line = in.nextLine();
System.out.println(line);
}
} finally {
s.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Read time from internet time server - working java code
Read time from internet time server - working java code
iterate through map hashmap linkedhashmap in java
How to iterate through Map.. MashMap, LinkedHashMap ... in Java
Method 1 : If you're only interested in the keys, you can iterate through the keySet() of the map:
Method 1 : If you're only interested in the keys, you can iterate through the keySet() of the map:
Mapmap = ...;
for (String key : map.keySet()) {
// ...
}
Method 2 :java escape text in regular expression
Java's a built-in way to escape arbitrary text so that it can be included in a regular expression-
For example, users enter "$5", we can match that exactly rather than a "5" after the end of input.
Just do this : to escape text in regex
For example, users enter "$5", we can match that exactly rather than a "5" after the end of input.
Just do this : to escape text in regex
Pattern.quote("$5");
use of @override annotation in java - why ?
The @override annotation is most useful as a compile-time reminder that the intention of the method is to override a parent method. See this example:
import java.util.HashSet;
import java.util.Set;
/**
* Override_Annotation_Usage_Example, from Effective Java
*/
Subscribe to:
Posts
(
Atom
)