├── Advance Java Codes ├── CountingSort.java ├── LinkedList.java ├── MergeSort.java ├── ReadMe.md └── Stack_With_Array.java ├── Java Codes for Beginner ├── Add Two Numbers.java ├── Array.java ├── CallingMethodConatenation.java ├── Float To Integer .java ├── Methods.java ├── Scope.java ├── StringConatenation.java └── TypesAndVariable.java ├── README.md └── _config.yml /Advance Java Codes/CountingSort.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class CountingSort { 5 | 6 | public static void main(String[] args) { 7 | // TODO Auto-generated method stub 8 | Scanner input = new Scanner(System.in); 9 | 10 | String[] array = input.nextLine().split(" "); 11 | int[] sequence = new int[array.length]; 12 | for(int i =0; i < array.length ;i++) { 13 | sequence[i] = Integer.parseInt(array[i]); 14 | } 15 | 16 | int larger = input.nextInt(); 17 | int lower = input.nextInt(); 18 | 19 | countingNegativo(sequence, larger, lower); 20 | 21 | } 22 | 23 | 24 | public static void countingNegativo(int[] array, int larger, int lower) { 25 | int[] counting = new int[(larger - lower) + 1]; 26 | int distancia = lower * -1; 27 | 28 | for(int j = 0; j < array.length; j++) { 29 | counting[array[j] + distancia]++; 30 | } 31 | 32 | for(int k = 1; k < counting.length; k++) { 33 | counting[k] += counting[k-1]; 34 | } 35 | 36 | int[] resultado = new int[array.length]; 37 | for(int i = array.length-1; i > -1; i--) { 38 | resultado[counting[array[i] + distancia] -1] = array[i]; 39 | counting[array[i] +distancia]--; 40 | } 41 | System.out.println(Arrays.toString(resultado)); 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /Advance Java Codes/LinkedList.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class LinkedList { 4 | 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | Queue queue = new Queue(); 8 | Scanner input = new Scanner(System.in); 9 | String operations = input.nextLine(); 10 | 11 | 12 | 13 | while(!(operations.equals("end"))) { 14 | if(operations.equals("print")) { 15 | System.out.println(queue.print()); 16 | } else if(operations.equals("remove")) { 17 | queue.remove(); 18 | } else if(operations.equals("element")) { 19 | System.out.println(queue.element()); 20 | } else { 21 | String[] entrada = operations.split(" "); 22 | if(entrada[0].equals("add")) { 23 | queue.add(Integer.parseInt(entrada[1])); 24 | } else { 25 | System.out.println(queue.search(Integer.parseInt(entrada[1]))); 26 | } 27 | } 28 | operations = input.nextLine(); 29 | } 30 | 31 | } 32 | } 33 | 34 | class Queue{ 35 | Node head; 36 | int size; 37 | 38 | public Queue() { 39 | this.head = null; 40 | this.size = 0; 41 | } 42 | 43 | public boolean isEmpty() { 44 | if(head == null) { 45 | return true; 46 | } 47 | return false; 48 | } 49 | public void add(int v) { 50 | if(isEmpty()) { 51 | Node newNode = new Node(v); 52 | head = newNode; 53 | size++; 54 | } else { 55 | add(head, v); 56 | } 57 | } 58 | 59 | private void add(Node node, int v) { 60 | // TODO Auto-generated method stub 61 | Node aux = new Node(v); 62 | if(node.next == null) { 63 | node.next = aux; 64 | aux.prev = node; 65 | size++; 66 | } else { 67 | add(node.next, v); 68 | } 69 | } 70 | 71 | public void remove() { 72 | if(isEmpty()) { 73 | System.out.println("empty"); 74 | } else { 75 | if(head.next == null) { 76 | head = null; 77 | size = 0; 78 | } else { 79 | Node aux = this.head.next; 80 | this.head.next = null; 81 | this.head.prev = null; 82 | this.head = aux; 83 | size--; 84 | } 85 | 86 | } 87 | } 88 | 89 | public String print() { 90 | if(isEmpty()) { 91 | return "empty"; 92 | } else { 93 | return print(head).trim(); 94 | } 95 | } 96 | 97 | private String print(Node node) { 98 | // TODO Auto-generated method stub 99 | if(node == null) { 100 | return ""; 101 | } 102 | return node.toString() + " " + print(node.next); 103 | } 104 | 105 | public String element() { 106 | return head.toString(); 107 | } 108 | 109 | public int search(int v) { 110 | int search = search(head, v); 111 | if(search > size) { 112 | return -1; 113 | } 114 | return search; 115 | } 116 | 117 | private int search(Node node, int v) { 118 | // TODO Auto-generated method stub 119 | if(node == null) { 120 | return 1; 121 | } 122 | if(node.getValor() == v) { 123 | return 0; 124 | } 125 | return 1 + search(node.next, v); 126 | 127 | 128 | } 129 | 130 | } 131 | 132 | 133 | class Node{ 134 | 135 | Node next; 136 | Node prev; 137 | int val; 138 | 139 | public Node(int v) { 140 | this.val = v; 141 | this.next = null; 142 | this.prev = null; 143 | } 144 | 145 | public String toString() { 146 | return "" + val; 147 | } 148 | public int getValor() { 149 | return this.val; 150 | } 151 | } -------------------------------------------------------------------------------- /Advance Java Codes/MergeSort.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class MergeSort { 4 | 5 | public static void mergeSort(int[] array, int start, int end) { 6 | 7 | if( start < end) { 8 | 9 | 10 | int half = (start + end)/2; 11 | mergeSort(array, start, half); 12 | mergeSort(array, half+1, end); 13 | merge(array, start, half, end); 14 | } 15 | } 16 | 17 | 18 | 19 | 20 | public static void merge(int[] array, int start, int half, int end) { 21 | int[] aux = new int[array.length]; 22 | 23 | for(int q = start; q <= end; q++) { 24 | aux[q] = array[q]; 25 | } 26 | 27 | int i = start; 28 | int j = half + 1; 29 | int k = start; 30 | 31 | while(i <= half && j <= end) { 32 | if(aux[i] < aux[j]) { 33 | array[k] = aux[i]; 34 | i++; 35 | } else { 36 | array[k] = aux[j]; 37 | j++; 38 | } 39 | k++; 40 | } 41 | 42 | while(i <= half) { 43 | array[k] = aux[i]; 44 | i++; 45 | k++; 46 | } 47 | while( j <= end) { 48 | array[k] = array[j]; 49 | j++; 50 | k++; 51 | } 52 | 53 | } 54 | 55 | public static void main(String[] args) { 56 | int[] array = {50, 40, 35, 30, 20,10}; 57 | mergeSort(array, 0, array.length-1); 58 | System.out.println(Arrays.toString(array)); 59 | } 60 | 61 | } -------------------------------------------------------------------------------- /Advance Java Codes/ReadMe.md: -------------------------------------------------------------------------------- 1 | # Java Basic Codes for Beginner | Learn Java Programming with examples. 2 | Hello there! 3 | This codes would help you learn Advance Java. I am going to share Advance Java codes on various topics of Java including 4 | tutorials, advanced Java concepts and Java programming examples. This free Java codes 5 | contains the links of all the tutorials in a systematic order starting from beginner’s level to the advanced 6 | topics. Whether you are a college student looking for learn Java programming or a company employee learning advanced 7 | Java topics for building an application in Java, this Java tutorial would definitely be useful for you. Let’s start learning. 8 | 9 | ## Improving this document 10 | This contribution guideline is subject to the conditions that are described here. If you have suggestions for improvement, open an issue or create a pull request! 11 | 12 | ### Big Thanks | Top Contributors - 13 | Gabriel de Carvalho Fonseca 14 | -------------------------------------------------------------------------------- /Advance Java Codes/Stack_With_Array.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class Stack_With_Array { 4 | private static int[] stack; 5 | private static int head; 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner reading = new Scanner(System.in); 10 | 11 | int size = Integer.parseInt(reading.nextLine()); 12 | criaPilha(size); 13 | String operations; 14 | operations = reading.nextLine(); 15 | 16 | while(!(operations.equals("end"))) { 17 | if(operations.equals("peek")) { 18 | System.out.println(peek()); 19 | } else if( operations.equals("pop")) { 20 | pop(); 21 | } else if(operations.equals("print")) { 22 | System.out.print(print()); 23 | } else { 24 | String[] entrada = operations.split(" "); 25 | push(Integer.parseInt(entrada[1])); 26 | } 27 | operations = reading.nextLine(); 28 | } 29 | } 30 | 31 | public static void criaPilha(int tamanho) { 32 | stack = new int[tamanho]; 33 | head = -1; 34 | } 35 | 36 | public static boolean isEmpty() { 37 | return head == -1; 38 | } 39 | 40 | public static boolean isFull() { 41 | return head == (stack.length-1); 42 | } 43 | 44 | public static String print() { 45 | if(isEmpty()) { 46 | return "empty\n" ; 47 | } 48 | String content = ""; 49 | for(int i = 0; i <= head; i++) { 50 | content += stack[i] + " "; 51 | } 52 | return content.trim() + "\n"; 53 | } 54 | 55 | public static String peek() { 56 | if(isEmpty()) { 57 | return "empty"; 58 | } 59 | String exit = ""; 60 | exit += stack[head]; 61 | return exit; 62 | } 63 | 64 | public static void push(int n) { 65 | if(isFull()) { 66 | System.out.println("full"); 67 | } else { 68 | head++; 69 | stack[head] = n; 70 | } 71 | } 72 | 73 | public static void pop() { 74 | if(isEmpty()) { 75 | System.out.println("empty"); 76 | } else { 77 | head--; 78 | } 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Java Codes for Beginner/Add Two Numbers.java: -------------------------------------------------------------------------------- 1 | public class add{ 2 | 3 | public static void main(String[] args) { 4 | 5 | int first = 10; 6 | int second = 20; 7 | 8 | int sum = first + second; 9 | 10 | System.out.println("The sum is: " + sum); 11 | } 12 | } -------------------------------------------------------------------------------- /Java Codes for Beginner/Array.java: -------------------------------------------------------------------------------- 1 | class App { 2 | public static void main(String[] args) { 3 | 4 | int value = 7; 5 | 6 | int[] values; 7 | values = new int[3]; 8 | 9 | System.out.println(values[0]); 10 | 11 | values[0] = 10; 12 | values[1] = 20; 13 | values[2] = 30; 14 | 15 | System.out.println(values[0]); 16 | System.out.println(values[1]); 17 | System.out.println(values[2]); 18 | 19 | for(int i=0; i < values.length; i++) { 20 | System.out.println(values[i]); 21 | } 22 | 23 | int[] numbers = {5, 6, 7}; 24 | 25 | for(int i=0; i < numbers.length; i++) { 26 | System.out.println(numbers[i]); 27 | } 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Java Codes for Beginner/CallingMethodConatenation.java: -------------------------------------------------------------------------------- 1 | //This program will call Methods in different ways 2 | //Date - 16 Sep 2018 3 | //Author - @swetabhsuman8 4 | //CallingMethodConatenation 5 | 6 | public class CallingMethodConatenation { 7 | public static void main (String[] args) { 8 | //This is method 9 | sayHelloUser("Swetabh"); 10 | sayCity("Roorkee, UK"); 11 | 12 | int DOB = returnDOB (); 13 | System.out.print(". Come soon, we will celebrate your birthday on March - " +DOB); 14 | } 15 | //This method returns an int type with the DOB (Date of Birth) 16 | static int returnDOB() { 17 | return 13; 18 | } 19 | //This method will say Hello User or whatver name is passed when called 20 | static void sayHelloUser(String name) { 21 | System.out.println("Howdy, " +name); 22 | 23 | } 24 | //This Method will say city name of the user. 25 | static void sayCity(String city){ 26 | System.out.print("How are you doing Nowadays in " +city); //here I added different String - city 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Java Codes for Beginner/Float To Integer .java: -------------------------------------------------------------------------------- 1 | public class change { 2 | public static void main (String[] args) { 3 | double myvar=2.4; 4 | int myvar2=8; 5 | 6 | 7 | myvar2 = myvar; 8 | System.out.println(myvar); 9 | } 10 | } -------------------------------------------------------------------------------- /Java Codes for Beginner/Methods.java: -------------------------------------------------------------------------------- 1 | public class Methods { 2 | public static void main (String [] args) { 3 | sayHelloWorld(); 4 | } 5 | 6 | static void sayHelloWorld () { 7 | System.out.println("Hello, world!"); 8 | } 9 | } -------------------------------------------------------------------------------- /Java Codes for Beginner/Scope.java: -------------------------------------------------------------------------------- 1 | /*This program will show scopes in Java 2 | Date - 16 Sep 2018 3 | Author - @swetabhsuman8 4 | ScopeInJava*/ 5 | public class Scope { 6 | //because x is declared outside of any method, it is in Scope to all methods 7 | //any method can access x 8 | static int x; //declaring the variable x 9 | public static void main (String[] args) { 10 | x = 5; //assigning a value to x 11 | System.out.println(x); 12 | 13 | //Calling doSomething() 14 | doSomething(); 15 | 16 | System.out.println(x); 17 | } 18 | static void doSomething() { 19 | x = 10; 20 | } 21 | static void doSomethingLocally() { 22 | /*because is declared to this method, it is local to this method. It means no other methods has access 23 | to y*/ 24 | int y = 100; //decalring and init the variable y 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Java Codes for Beginner/StringConatenation.java: -------------------------------------------------------------------------------- 1 | public class StringConatenation { 2 | public static void main (String [] args) { 3 | String hello = "Hello, how are you "; 4 | String name = "Swetabh"; 5 | System.out.println (hello + name); //String Conatension 6 | } 7 | } -------------------------------------------------------------------------------- /Java Codes for Beginner/TypesAndVariable.java: -------------------------------------------------------------------------------- 1 | public class TypesAndVariable { 2 | public static void main (String[] args) { 3 | int MyVariable; // Declaring a varibale called MyVariable that store type int, integers 4 | MyVariable = 5; //This is MyVariable 5 | 6 | System.out.println(MyVariable); 7 | 8 | MyVariable = 10; //Here we changed MyVariable. So it means we can only store one integer 9 | 10 | System.out.println(MyVariable); 11 | 12 | MyVariable = MyVariable + 2; //Now we are adding +2 in Changed variable 13 | 14 | System.out.println(MyVariable); 15 | } 16 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Basic Codes for Beginner | Learn Java Programming with examples. 2 | Hello there! 3 | These codes will help you learn Java. I am going to share beginner's codes on various topics of Java including 4 | tutorials on core java and advanced Java concepts and Java programming examples. This free Java codes 5 | contains the links of all the tutorials in a systematic order starting from beginner’s level to the advanced 6 | topics. Whether you are a college student looking for learn Java programming or a company employee learning advanced 7 | Java topics for building an application in Java, this Java tutorial would definitely be useful for you. Let’s start learning. 8 | 9 | ## Improving this document 10 | This contribution guideline is subject to the conditions that are described here. If you have suggestions for improvement, open an issue or create a pull request! 11 | 12 | ### Big Thanks | Top Contributors - 13 | Gabriel de Carvalho Fonseca 14 | 15 | 16 | 17 | ## Donate GitCodeSwetabh! 18 | Your support will help me to write more codes for free software and tools. 19 | 20 | 21 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-hacker --------------------------------------------------------------------------------