chiwormjava
v2.0.2
Published
A simple CLI tool to **view and copy Java data structure code** (like LinkedList, Stack, etc.) directly in your browser.
Readme
🚀 Java Code Watch
A simple CLI tool to view and copy Java data structure code (like LinkedList, Stack, etc.) directly in your browser.
📦 Installation
Option 1: Use without installing (recommended)
npx javacodewatchOption 2: Install locally
npm install chiwormjavaRun:
npx javacodewatchOption 3: Install globally (optional)
npm install -g chiwormjavaRun:
javacodewatch🧠 What it does
- Opens a local server
- Launches your browser
- Shows Java code snippets
- Click → View code
- Click → Copy code
📸 Features
- 📚 Java DSA snippets (LinkedList, etc.)
- 🖱️ One-click code view
- 📋 Copy to clipboard
- 🌙 Clean dark UI
▶️ Usage
After running the command:
javacodewatch👉 Your browser will open automatically:
http://localhost:3000Armstrong
Name: <input type="text" name="name" value="<?php echo $editData['name'] ?? ''; ?>"><br><br>
Email: <input type="text" name="email" value="<?php echo $editData['email'] ?? ''; ?>"><br><br>
<?php if($editData){ ?>
<input type="submit" name="update" value="Update">
<?php } else { ?>
<input type="submit" name="add" value="Add">
<?php } ?>$img = imagecreatetruecolor(500, 350);
$white = imagecolorallocate($img, 255, 255, 255); $black = imagecolorallocate($img, 0, 0, 0); $red = imagecolorallocate($img, 255, 0, 0); $blue = imagecolorallocate($img, 0, 0, 255); $green = imagecolorallocate($img, 0, 255, 0); $yellow= imagecolorallocate($img, 255, 255, 0);
imagefill($img, 0, 0, $white);
imagerectangle($img, 20, 20, 120, 100, $black); imagefilledrectangle($img, 140, 20, 240, 100, $green);
imageellipse($img, 350, 70, 80, 80, $red); imagefilledellipse($img, 450, 70, 80, 80, $yellow);
imageline($img, 20, 150, 200, 250, $blue);
$points = [300,150, 350,250, 250,250]; imagepolygon($img, $points, 3, $black);
$points2 = [400,150, 450,250, 350,250]; imagefilledpolygon($img, $points2, 3, $red);
imagearc($img, 100, 300, 100, 50, 0, 180, $blue);
imagestring($img, 5, 180, 300, "Shapes Demo", $black);
header("Content-Type: image/png"); imagepng($img); imagedestroy($img);
1. Right Triangle
Pattern:
*
* *
* * *
* * * *
* * * * *Code:
<?php
for($i = 1; $i <= 5; $i++){
for($j = 1; $j <= $i; $j++){
echo "* ";
}
echo "<br>";
}
?>2. Inverted Triangle
Pattern:
* * * * *
* * * *
* * *
* *
*Code:
<?php
for($i = 5; $i >= 1; $i--){
for($j = 1; $j <= $i; $j++){
echo "* ";
}
echo "<br>";
}
?>3. Full Pyramid
Pattern:
*
***
*****
*******
*********Code:
<?php
for($i = 1; $i <= 5; $i++){
for($j = 1; $j <= 5 - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
echo "*";
}
echo "<br>";
}
?>⭐ 4. Diamond Pattern
Pattern:
*
***
*****
***
*Code:
<?php
// upper
for($i = 1; $i <= 3; $i++){
for($j = 1; $j <= 3 - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
echo "*";
}
echo "<br>";
}
// lower
for($i = 2; $i >= 1; $i--){
for($j = 1; $j <= 3 - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
echo "*";
}
echo "<br>";
}
?>5. Number Triangle
Pattern:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5Code:
<?php
for($i = 1; $i <= 5; $i++){
for($j = 1; $j <= $i; $j++){
echo $j . " ";
}
echo "<br>";
}
?>6. Floyd’s Triangle
Pattern:
1
2 3
4 5 6
7 8 9 10Code:
<?php
$num = 1;
for($i = 1; $i <= 4; $i++){
for($j = 1; $j <= $i; $j++){
echo $num . " ";
$num++;
}
echo "<br>";
}
?>7. Alphabet Pattern
Pattern:
A
A B
A B C
A B C DCode:
<?php
for($i = 65; $i <= 68; $i++){
for($j = 65; $j <= $i; $j++){
echo chr($j) . " ";
}
echo "<br>";
}
?>8. Hollow Square
Pattern:
* * * * *
* *
* *
* *
* * * * *Code:
<?php
$n = 5;
for($i = 1; $i <= $n; $i++){
for($j = 1; $j <= $n; $j++){
if($i == 1 || $i == $n || $j == 1 || $j == $n){
echo "* ";
} else {
echo " ";
}
}
echo "<br>";
}
?>9. Left-Aligned Triangle
Pattern:
*
* *
* * *
* * * *
* * * * *Code:
<?php
for($i = 1; $i <= 5; $i++){
for($j = 1; $j <= 5 - $i; $j++){
echo " ";
}
for($k = 1; $k <= $i; $k++){
echo "* ";
}
echo "<br>";
}
?>10. Hollow Pyramid
Pattern:
*
* *
* *
* *
*********Code:
<?php
$n = 5;
for($i = 1; $i <= $n; $i++){
for($j = 1; $j <= $n - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
if($k == 1 || $k == (2*$i - 1) || $i == $n){
echo "*";
} else {
echo " ";
}
}
echo "<br>";
}
?>⭐ 11. Hollow Diamond
Pattern:
*
* *
* *
* *
*Code:
<?php
$n = 3;
// upper
for($i = 1; $i <= $n; $i++){
for($j = 1; $j <= $n - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
if($k == 1 || $k == (2*$i - 1)){
echo "*";
} else {
echo " ";
}
}
echo "<br>";
}
// lower
for($i = $n - 1; $i >= 1; $i--){
for($j = 1; $j <= $n - $i; $j++){
echo " ";
}
for($k = 1; $k <= (2*$i - 1); $k++){
if($k == 1 || $k == (2*$i - 1)){
echo "*";
} else {
echo " ";
}
}
echo "<br>";
}
?>12. Palindrome Number Pattern
Pattern:
1
121
12321
1234321Code:
<?php
for($i = 1; $i <= 4; $i++){
for($j = 1; $j <= $i; $j++){
echo $j;
}
for($j = $i - 1; $j >= 1; $j--){
echo $j;
}
echo "<br>";
}
?>13. Pascal’s Triangle
Pattern:
1
1 1
1 2 1
1 3 3 1Code:
<?php
$n = 5;
for($i = 0; $i < $n; $i++){
$num = 1;
for($j = 0; $j <= $i; $j++){
echo $num . " ";
$num = $num * ($i - $j) / ($j + 1);
}
echo "<br>";
}
?>14. Butterfly Pattern
Pattern:
* *
** **
*** ***
********
*** ***
** **
* *Code:
<?php
$n = 4;
// upper
for($i = 1; $i <= $n; $i++){
for($j = 1; $j <= $i; $j++){
echo "*";
}
for($j = 1; $j <= 2*($n-$i); $j++){
echo " ";
}
for($j = 1; $j <= $i; $j++){
echo "*";
}
echo "<br>";
}
// lower
for($i = $n; $i >= 1; $i--){
for($j = 1; $j <= $i; $j++){
echo "*";
}
for($j = 1; $j <= 2*($n-$i); $j++){
echo " ";
}
for($j = 1; $j <= $i; $j++){
echo "*";
}
echo "<br>";
}
?>15. Reverse Alphabet Pattern
Pattern:
E
D E
C D E
B C D E
A B C D ECode:
<?php
for($i = 69; $i >= 65; $i--){
for($j = $i; $j <= 69; $j++){
echo chr($j) . " ";
}
echo "<br>";
}
?>1. Current Date & Time (Using date())
<?php
date_default_timezone_set("Asia/Kolkata");
echo "Current Date: " . date("Y-m-d") . "<br>";
echo "Current Time: " . date("H:i:s") . "<br>";
echo "Full Format: " . date("d-m-Y H:i:s");
?>Common Formats
Y→ year (2026)m→ monthd→ dayH→ hour (24 format)i→ minutess→ seconds
2. Using time() (Timestamp)
<?php
date_default_timezone_set("Asia/Kolkata");
$current = time();
echo "Timestamp: " . $current . "<br>";
echo "Readable Date: " . date("d-m-Y H:i:s", $current);
?>3. Using new DateTime() (IMPORTANT)
This is the modern and most important method.
<?php
date_default_timezone_set("Asia/Kolkata");
$date = new DateTime();
echo $date->format("d-m-Y H:i:s");
?>4. Custom Date
<?php
$date = new DateTime("2026-04-02");
echo $date->format("d-m-Y");
?>5. Add / Modify Date
<?php
$date = new DateTime();
$date->modify("+5 days");
echo "After 5 days: " . $date->format("d-m-Y") . "<br>";
$date->modify("+1 month");
echo "After 1 month: " . $date->format("d-m-Y");
?>6. Date Difference (Age Calculator Logic)
<?php
date_default_timezone_set("Asia/Kolkata");
$birth = new DateTime("2006-01-03");
$current = new DateTime();
$diff = $current->diff($birth);
echo "Age: " . $diff->y . " Years ";
echo $diff->m . " Months ";
echo $diff->d . " Days";
?>7. Compare Two Dates
<?php
$d1 = new DateTime("2026-04-01");
$d2 = new DateTime("2026-04-10");
if($d1 < $d2){
echo "d1 is earlier";
} else {
echo "d2 is earlier";
}
?>Important Exam Points
- Always use:
date_default_timezone_set("Asia/Kolkata");1. HTML Form + Display Name using PHP
<!-- form.php -->
<form method="post">
Enter Name: <input type="text" name="username">
<input type="submit" value="Submit">
</form>
<?php
if(isset($_POST['username'])){
echo "Hello " . $_POST['username'];
}
?>2. Number Programs
(a) Prime Number
<?php
$num = 7;
$flag = 1;
for($i=2; $i<$num; $i++){
if($num % $i == 0){
$flag = 0;
break;
}
}
if($flag == 1)
echo "Prime";
else
echo "Not Prime";
?>(b) Odd or Even
<?php
$num = 10;
if($num % 2 == 0)
echo "Even";
else
echo "Odd";
?>(c) Greatest of Three Numbers
<?php
$a = 10; $b = 25; $c = 15;
if($a >= $b && $a >= $c)
echo "Greatest: $a";
elseif($b >= $a && $b >= $c)
echo "Greatest: $b";
else
echo "Greatest: $c";
?>3. Loop Programs
(a) Reverse 10 to 1
<?php
for($i=10; $i>=1; $i--){
echo $i . " ";
}
?>(b) 1-2-3-...-10 (no extra hyphen)
<?php
for($i=1; $i<=10; $i++){
if($i < 10)
echo $i . "-";
else
echo $i;
}
?>(c) Floyd Triangle
<?php
$n = 5;
$num = 1;
for($i=1; $i<=$n; $i++){
for($j=1; $j<=$i; $j++){
echo $num . " ";
$num++;
}
echo "<br>";
}
?>4. Continue + Arithmetic Operations
(a) Skip User Number
<?php
$skip = 5;
for($i=1; $i<=10; $i++){
if($i == $skip)
continue;
echo $i . " ";
}
?>(b) Arithmetic using Select Box
<form method="post">
Num1: <input type="number" name="a"><br>
Num2: <input type="number" name="b"><br>
<select name="op">
<option value="add">Add</option>
<option value="sub">Subtract</option>
<option value="mul">Multiply</option>
<option value="div">Divide</option>
</select>
<input type="submit">
</form>
<?php
if(isset($_POST['op'])){
$a = $_POST['a'];
$b = $_POST['b'];
if($_POST['op']=="add") echo $a+$b;
elseif($_POST['op']=="sub") echo $a-$b;
elseif($_POST['op']=="mul") echo $a*$b;
elseif($_POST['op']=="div") echo $a/$b;
}
?>5. Table + Armstrong
(a) Multiplication Table
<?php
$num = 5;
for($i=1; $i<=10; $i++){
echo "$num x $i = " . ($num*$i) . "<br>";
}
?>(b) Armstrong Number
<?php
$num = 153;
$sum = 0;
$temp = $num;
while($temp > 0){
$rem = $temp % 10;
$sum += $rem * $rem * $rem;
$temp = (int)($temp/10);
}
if($sum == $num)
echo "Armstrong";
else
echo "Not Armstrong";
?>6. Array + Table
(a) Fruit Table
<?php
$fruits = ["Apple", "Banana", "Mango"];
echo "<table border=1>";
foreach($fruits as $f){
echo "<tr><td>$f</td></tr>";
}
echo "</table>";
?>(b) Sum of Array
<?php
$arr = [1,2,3,4,5];
$sum = 0;
foreach($arr as $v){
$sum += $v;
}
echo "Sum = $sum";
?>7 & 8. Matrix + Palindrome
(a) Multiply Number with Matrix
<?php
$matrix = [
[1,2],
[3,4]
];
$num = 2;
for($i=0; $i<2; $i++){
for($j=0; $j<2; $j++){
echo $matrix[$i][$j] * $num . " ";
}
echo "<br>";
}
?>(b) Palindrome String
<?php
$str = "malayalam";
if($str == strrev($str))
echo "Palindrome";
else
echo "Not Palindrome";
?>9. Registration Form + Display Data
<form method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
<input type="submit">
</form>
<?php
if(isset($_POST['name'])){
echo "Name: " . $_POST['name'] . "<br>";
echo "Email: " . $_POST['email'];
}
?>10. Login (Username + Password Check)
<form method="post">
Username: <input type="text" name="user"><br>
Password: <input type="password" name="pass"><br>
<input type="submit">
</form>
<?php
if(isset($_POST['user'])){
if($_POST['user']=="admin" && $_POST['pass']=="godsgift"){
echo "Welcome Admin";
} else {
echo "Invalid Login";
header("refresh:2; url=");
}
}
?>