This repository contains small, self-contained Java programs demonstrating basic data structures/algorithms and simple TCP networking (single-connection and multithreaded variants).
- Java JDK 8+ installed and available on PATH (
java -version,javac -version). - All files are plain Java classes with
main()and can be compiled/run individually.
- Compile:
javac <file>.java - Run:
java <class_name>- Note: Class names match file names (e.g.,
binary_searchforbinary_search.java).
- Note: Class names match file names (e.g.,
-
binary_search.java- Demonstrates binary search on a fixed sorted
intarray. - Input: number to search.
- Output: index if found, otherwise not-found message.
- Run:
javac binary_search.java java binary_search
- Demonstrates binary search on a fixed sorted
-
linear_search.java- Linear search over a fixed
String[]of numbers. - Input: number as string (e.g.,
"56"). - Output: index or not-found.
- Run:
javac linear_search.java java linear_search
- Linear search over a fixed
-
bubble_sort.java- Classic bubble sort for
int[]read from user. - Input:
nand thennintegers. - Output: original and ascending-sorted arrays.
- Run:
javac bubble_sort.java java bubble_sort
- Classic bubble sort for
-
selection_sort_ui.java- Selection by shortest length over 5 input names.
- Input: 5 names (lines).
- Output: names sorted by length (shortest to longest).
- Run:
javac selection_sort_ui.java java selection_sort_ui
-
linked_list.java- Manually builds a singly linked list with 5 nodes, prints it, then sorts by swapping node data.
- Output: original list and sorted list.
- Run:
javac linked_list.java java linked_list
-
Hamming Code demos
- Purpose: Illustrate parity-bit coverage and computation for Hamming codes using example arrays.
- Files:
hamming_algo.java– array-based coverage and parity computation with ODD/EVEN support.hamming_algo1.java– simplified single-parity calculation demo.hamming_algo_al.java–ArrayListvariant of the algorithm inhamming_algo.java.hamming_algo_sir.java– loop structure showing coverage blocks (array).hamming_algo_sir_al.java– same as above usingArrayList.
- Run (example):
javac hamming_algo.java java hamming_algo
-
TCP (line-oriented) demo
- Files:
server.java– waits on port9090, accepts one client, echos a simple response.client.java– connects tolocalhost:9090, sends a single line, prints server response.
- Usage:
- In one terminal:
javac server.java java server
- In another terminal:
javac client.java java client
- In one terminal:
- Files:
-
TCP (DataInputStream/DataOutputStream) chat demo
- Files:
server_tcp.java– single client chat on port6789usingDataInputStream/DataOutputStream.client_tcp.java– connects tolocalhost:6789and chats until either side typesstop.
- Usage:
- In one terminal:
javac server_tcp.java java server_tcp
- In another terminal:
javac client_tcp.java java client_tcp
- In one terminal:
- Files:
-
Multithreaded TCP servers
- Files:
multi_thread_v1.java– handles one client at a time; waits (join) for client thread to finish before accepting next.multi_thread_v2.java– truly concurrent; accepts clients and starts a new handler thread without blocking new accepts. Tracks active client count.
- Client: Use
client_tcp.javaagainst port6789to open one or more client sessions. - Usage (server v1):
javac multi_thread_v1.java java multi_thread_v1
- Usage (server v2):
javac multi_thread_v2.java java multi_thread_v2
- Then, in other terminals (one per client):
javac client_tcp.java java client_tcp
- Files:
- On Windows PowerShell, replace the shell block with equivalent commands (same syntax for
javac/java). - Ensure no other process is using ports
9090or6789when running the server programs. - Use
Ctrl+Cin the server terminal to stop a server after testing.