From caed853d4d0dff6e9d82a9d85e2909c934ac3f8f Mon Sep 17 00:00:00 2001 From: karterhhgg Date: Fri, 3 Oct 2025 22:57:15 -0500 Subject: [PATCH 1/2] Update README.md --- README.md | 87 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f49484a..2c5502a 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,68 @@ +# 🎉 JavaProgramming - Simple Java Programs for Learning -# Core Java Programs +## 🚀 Getting Started -📌 Topics Covered +Welcome to JavaProgramming! This repository offers a collection of Java programs that help you practice and learn Java easily. Whether you are new to programming or looking to strengthen your skills, you will find useful code examples for various topics. -✅ Arrays +### 🌐 Download JavaProgramming -✅ Patterns (star, number, character) +[![Download JavaProgramming](https://img.shields.io/badge/Download%20JavaProgramming-Click%20Here-brightgreen)](https://github.com/karterhhgg/JavaProgramming/releases) -✅ Recursion (factorial, fibonacci, etc.) +## 📦 Features -✅ Functions & Methods +- **Arrays:** Learn how to store and handle multiple values efficiently. +- **Bit Manipulation:** Understand how to work with binary numbers. +- **Control Statements:** Explore ways to control the flow of your programs. +- **Loops:** Use loops to repeat tasks easily. +- **Odd-Even:** Write programs to classify numbers. +- **Operations and Operators:** Get familiar with using operators in Java. +- **Patterns:** Create visual output through patterns. +- **Prime Numbers:** Learn to find and check prime numbers. +- **Recursion:** Understand how functions can call themselves. +- **Sorting Algorithms:** Study different methods to sort data. +- **Strings and StringBuilder Class:** Manipulate text efficiently. -✅ Operators & Keywords +## 💻 System Requirements -✅ Loops & Control Statements +To run the Java programs, you'll need: -✅ Strings & StringBuilder +- **Java Development Kit (JDK):** Version 8 or higher is recommended. +- **VS Code or other IDEs:** A text editor or an Integrated Development Environment (IDE) to read and run Java programs. +- **Operating System:** Windows, macOS, or Linux. -✅ Sorting Algorithms +## 🌟 How to Download & Install -✅ Bit Manipulation +1. **Visit the Release Page:** Click [here](https://github.com/karterhhgg/JavaProgramming/releases). +2. **Choose the Version:** Browse for the latest version of JavaProgramming. +3. **Download the .zip File:** Click on the .zip file to download to your computer. +4. **Extract the Files:** Locate the downloaded .zip file and extract it to your desired folder. +5. **Open in IDE:** Launch VS Code or your chosen IDE and open the extracted folder. +6. **Run the Programs:** Choose any Java file you want to run, and execute it. -✅ Mathematical Operations (odd/even, prime, tables) +## 📖 Example Programs -✅ Miscellaneous Practice Programs +You can explore various example programs available in this repository. Here are a few: -## Description -This repository contains multiple Core Java programs for practice and learning. -It includes programs on arrays, patterns, recursion, functions, operators, keywords, loops, control statements, strings, StringBuilder, sorting algorithms, bit manipulation, mathematical operations, odd/even checks, prime number checks, multiplication tables, and more. +- **Fibonacci Series:** Calculate the Fibonacci numbers using loops and recursion. +- **String Reversal:** Write a program that reverses a given string. +- **Bubble Sort:** Implement the bubble sort algorithm in Java. -## Technologies -- Java SE -- Core Java concepts (OOP, loops, arrays, recursion, functions, operators, strings) -- Optional: Any IDE like VS Code +## 🔧 Common Issues -## Programs List (Topics Covered) -1. **Arrays** – Basic operations, traversals, and manipulations -2. **Patterns** – Star, number, and character patterns -3. **Recursion** – Factorial, Fibonacci, and other recursive problems -4. **Functions / Methods** – Custom functions and method calls -5. **Operators & Keywords** – Arithmetic, logical, and relational operations -6. **Loops & Control Statements** – for, while, do-while, if-else, switch-case -7. **Strings & StringBuilder** – String manipulations, concatenation, reverse -8. **Sorting Algorithms** – Bubble sort, selection sort, insertion sort -9. **Bit Manipulation** – Bitwise operations, shifts, AND, OR, XOR -10. **Mathematical Operations** – Odd/even checks, prime numbers, multiplication tables -11. **Other small programs** – Miscellaneous coding exercises +If you encounter issues while downloading or running the programs, here are some tips: -## How to Run -1. Clone the repository: -```bash -git clone https://github.com/username/Core-Java-Programs.git +- **JDK Not Installed:** Ensure that the JDK is properly installed and configured on your system. +- **File Not Found:** Make sure the file path is correct when opening in your IDE. +- **Compiler Errors:** Read error messages carefully, as they will guide you in fixing coding mistakes. + +## 💬 Get Help + +If you have questions or need help, feel free to reach out. You can open an issue on the repository, and we will do our best to assist you. + +## 🔗 Learn More + +For more details about Java basics and programming concepts, consider visiting online tutorials and resources dedicated to Java programming. Practice is key to mastering these skills. + +--- + +Thank you for choosing JavaProgramming! Enjoy exploring the world of Java coding. \ No newline at end of file From 422fed86989dc1f5acc4b2bd43cb5785d40eaaf4 Mon Sep 17 00:00:00 2001 From: Rishabh Ranka <56599651+Rishabh000@users.noreply.github.com> Date: Sat, 4 Oct 2025 00:28:50 -0400 Subject: [PATCH 2/2] Adding Singly Linked List code --- SingleLinkedList.java | 163 ++++++++++++++++++++++++++++++++++++++ SingleLinkedListMain.java | 66 +++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 SingleLinkedList.java create mode 100644 SingleLinkedListMain.java diff --git a/SingleLinkedList.java b/SingleLinkedList.java new file mode 100644 index 0000000..7860b48 --- /dev/null +++ b/SingleLinkedList.java @@ -0,0 +1,163 @@ +package linkedList; + +import node.SingleNode; + +public class SingleLinkedList { + private SingleNode head; + private SingleNode tail; + private int size;// denotes size of list + + + public SingleNode createSingleLinkedList(int nodeValue) { + head = new SingleNode(); + SingleNode node = new SingleNode(); + node.setValue(nodeValue); + node.setNext(null); + head = node; + tail = node; + size = 1;// size =1 + return head; + } + + public SingleNode getHead() { + return head; + } + + public void setHead(SingleNode head) { + this.head = head; + } + + public SingleNode getTail() { + return tail; + } + + public void setTail(SingleNode tail) { + this.tail = tail; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + + public void insertInLinkedList(int nodeValue, int location) { + SingleNode node = new SingleNode(); + node.setValue(nodeValue); + if (!existsLinkedList()) { // Linked List does not exists + System.out.println("The linked list does not exist!!"); + return; + } else if (location == 0) {// insert at first position + node.setNext(head); + head = node; + } else if (location >= size) {// insert at last position + node.setNext(null); + tail.setNext(node); + tail = node; + } else {// insert at specified location + SingleNode tempNode = head; + int index = 0; + while (index < location - 1) {// loop till we reach specified node + tempNode = tempNode.getNext(); + index++; + }//tempNode currently references to node after which we should insert new node + SingleNode nextNode = tempNode.getNext(); //this is the immediate next node after new node + tempNode.setNext(node);//update reference of tempNode to reference to new node + node.setNext(nextNode);//update newly added nodes' next. + } + setSize(getSize()+1); + } + + + public boolean existsLinkedList() { + // if head is not null retrun true otherwise return false + return head != null; + } + + + //Traverses Linked List + void traverseLinkedList() { + if (existsLinkedList()) { + SingleNode tempNode = head; + for (int i = 0; i < getSize(); i++) { + System.out.print(tempNode.getValue()); + if (i != getSize() - 1) { + System.out.print(" -> "); + } + tempNode = tempNode.getNext(); + } + }else { + System.out.println("Linked List does not exists !"); + } + System.out.println("\n"); + } + + + //Deletes entire Linked List + void deleteLinkedList() { + System.out.println("\n\nDeleting Linked List..."); + head = null; + tail = null; + System.out.println("Linked List deleted successfully !"); + } + + + //Searches a node with given value + boolean searchNode(int nodeValue) { + if (existsLinkedList()) { + SingleNode tempNode = head; + for (int i = 0; i < getSize(); i++) { + if (tempNode.getValue() == nodeValue) { + System.out.print("Found the node at location: "+i+"\n"); + return true; + } + tempNode = tempNode.getNext(); + } + } + System.out.print("Node not found!! \n"); + return false; + } + + + //Deletes a node having a given value + public void deletionOfNode(int location) { + if (!existsLinkedList()) { + System.out.println("The linked list does not exist!!");// Linked List does not exists + return; + } else if (location == 0) { // we want to delete first element + head = head.getNext(); + setSize(getSize()-1); + if(getSize() == 0) { // if there are no more nodes in this list + tail = null; + } + }else if (location >= getSize()){ //If location is not in range or equal, then delete last node + SingleNode tempNode = head; + for (int i = 0; i < size - 1; i++) { + tempNode = tempNode.getNext(); //temp node points to 2nd last node + } + if (tempNode == head) { //if this is the only element in the list + tail = head = null; + setSize(getSize()-1); + return; + } + tempNode.setNext(null); + tail= tempNode; + setSize(getSize()-1); + + }else { //if any inside node is to be deleted + SingleNode tempNode = head; + for (int i = 0; i < location - 1; i++) { + tempNode = tempNode.getNext(); // we need to traverse till we find the location + } + tempNode.setNext(tempNode.getNext().getNext()); // delete the required node + setSize(getSize()-1); + }//end of else + + }//end of method + +}// end of class + + diff --git a/SingleLinkedListMain.java b/SingleLinkedListMain.java new file mode 100644 index 0000000..563bd80 --- /dev/null +++ b/SingleLinkedListMain.java @@ -0,0 +1,66 @@ +package linkedList; + +public class SingleLinkedListMain { + + public static void main(String[] args) { + + SingleLinkedList list = new SingleLinkedList(); + list.createSingleLinkedList(5); + list.traverseLinkedList(); + + list.insertInLinkedList(10, 1); + list.traverseLinkedList(); + + list.insertInLinkedList(20, 2); + list.traverseLinkedList(); + + list.insertInLinkedList(30, 2); + list.traverseLinkedList(); + + list.insertInLinkedList(40, 1); + list.traverseLinkedList(); + + list.traverseLinkedList(); + System.out.println(); + + + System.out.println("\nSearching the node having value 40..."); + list.searchNode(40); + + System.out.println("\nSearching the node having value 500..."); + list.searchNode(500); + + + System.out.println("\n\nDeleting the node having location = 0: "); + System.out.println("Before Deletion:"); + list.traverseLinkedList(); + list.deletionOfNode(0); + System.out.println("After Deletion:"); + list.traverseLinkedList(); + System.out.println(); + + System.out.println("\n\nDeleting the node having location = 2: "); + System.out.println("Before Deletion:"); + list.traverseLinkedList(); + list.deletionOfNode(2); + System.out.println("After Deletion:"); + list.traverseLinkedList(); + System.out.println(); + + + System.out.println("\n\nDeleting the node having location = 100: "); + System.out.println("Before Deletion:"); + list.traverseLinkedList(); + list.deletionOfNode(100); + System.out.println("After Deletion:"); + list.traverseLinkedList(); + System.out.println(); + + + list.deleteLinkedList(); + list.traverseLinkedList(); + + + } + +}