Cheatsheet: Data Structures
    Array / List
    Map / Dict
    Struct / Data Class
    Other Data Structures
    Collection Conversions
Cheatsheet: Control Flow
Cheatsheet: Class

Polyglot CheatSheet - Network

Updated: 2022-08-06

HTTP Server


Introduced in Java 18 (JEP 408: Simple Web Server).

$ jwebserver

# Specify port 9000
$ jwebserver -p 9000


Start HTTP server

Python 3.x:

$ python -m http.server
Serving HTTP on port 8000 ...

Python 2.x:

$ python -mSimpleHTTPServer 8080

Read Web Pages


final URL url = new URL("" + ticker);
final BufferedReader reader = new BufferedReader( new InputStreamReader(url.openStream()));


Download pages from wikipedia

import urllib.request
opener = urllib.request.build_opener()
opener.addheaders =[('User-agent','Mozilla/5.0')]
infile ='')
page =



In, Java programs can use TCP or UDP to communicate over the Internet. The URL, URLConnection, Socket, and ServerSocket classes all use TCP to communicate over the network. The DatagramPacket, DatagramSocket, and MulticastSocket classes are for use with UDP. vs is blocking:

Two hosts are considered equivalent if both host names can be resolved into the same IP addresses; else if either host name can't be resolved, the host names must be equal without regard to case; or both host names equal to null. Since hosts comparison requires name resolution, this operation is a blocking operation.