diff --git a/.gitignore b/.gitignore index 43e3b04..f35ca9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,14 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + ### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr out/ !**/src/main/**/out/ !**/src/test/**/out/ @@ -26,7 +36,4 @@ bin/ .vscode/ ### Mac OS ### -.DS_Store - -# IntelliJ Idea -/.idea/ +.DS_Store \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..f3ed1d9 --- /dev/null +++ b/build.gradle @@ -0,0 +1,18 @@ +plugins { + id 'java' +} + +group = 'Java' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() +} + +dependencies { + // Apache POI + implementation 'org.apache.poi:poi:5.2.5' + implementation 'org.apache.poi:poi-ooxml:5.4.0' +} + +test {} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..a4b76b9 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9355b41 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..f5feea6 --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9d21a21 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/src/main/java/javaConcepts/Main.java b/src/main/java/javaConcepts/Main.java new file mode 100644 index 0000000..f076eb6 --- /dev/null +++ b/src/main/java/javaConcepts/Main.java @@ -0,0 +1,275 @@ +package javaConcepts; + + +import javaConcepts.conditionals.IfElse; +import javaConcepts.dataTypes.*; +import javaConcepts.enumWorks.Day; +import javaConcepts.enumWorks.Status; +import javaConcepts.fileAndDirectory.CheckExistence; +import javaConcepts.fileAndDirectory.CreateDirectories; +import javaConcepts.oop.OverLoading_0001; +import javaConcepts.randomPractice.*; +import javaConcepts.typeJuggling.PrimitiveJuggling_01; +import javaConcepts.typeJuggling.Random_0001; + +import java.util.*; +import java.util.stream.Stream; + +public class Main { + public static void main(String[] args) { + + // Primitive data types + + PrimitiveData primitiveData = new PrimitiveData(); + System.out.println("The byte value is: " + primitiveData.getByteValue()); + System.out.println("The short value is: " + primitiveData.getShortValue()); + System.out.println("The int value is: " + primitiveData.getIntValue()); + System.out.println("The long value is: " + primitiveData.getLongValue()); + System.out.println("The float value is: " + primitiveData.getFloatValue()); + System.out.println("The double value is: " + primitiveData.getDoubleValue()); + System.out.println("The char value is: " + primitiveData.getCharValue()); + System.out.println("The boolean value is: " + primitiveData.isBooleanValue()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Non-Primitive data types + + NonPrimitiveData nonPrimitiveData = new NonPrimitiveData(); + System.out.println("The String value is: " + nonPrimitiveData.getStringValue()); + System.out.println("The Integer value is: " + nonPrimitiveData.getIntegerValue()); + System.out.println("The Double value is: " + nonPrimitiveData.getDoubleValue()); + System.out.println("The Boolean value is: " + nonPrimitiveData.getBooleanValue()); + System.out.println("The intArray value is: " + Arrays.toString(nonPrimitiveData.getIntArray())); + System.out.println("The ArrayList value is: " + nonPrimitiveData.getArrayList()); + System.out.println("The HashSet value is: " + nonPrimitiveData.getHashSet()); + System.out.println("The ArrayListGeneric value is: " + nonPrimitiveData.getArrayListGeneric()); + System.out.println("The LinkedList value is: " + nonPrimitiveData.getLinkedList()); + System.out.println("The HashMapGeneric value is: " + nonPrimitiveData.getHashMapGeneric()); + System.out.println("The HashMap value is: " + nonPrimitiveData.getHashMap()); + nonPrimitiveData.is829InTheList(); + System.out.println("The Set of predefined Integer is: " + nonPrimitiveData.getSetOfPreDefinedIntegers()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // If/Else + + IfElse ifElse = new IfElse(); + ifElse.checkDataType(nonPrimitiveData.getStringValue()); + System.out.println("Current Data Type: " + ifElse.getCurrentDataType()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Generic + + GenericData_01> genericData_01 = new GenericData_01<>(new ArrayList<>(5)); + + genericData_01.getGData().add(1); + genericData_01.getGData().add(2); + genericData_01.getGData().add(3); + genericData_01.getGData().add(4); + genericData_01.getGData().add(5); + + List dataList = genericData_01.getGData(); + System.out.println("Data in the list: " + dataList); + System.out.println(dataList.getClass()); // Checks the data type + + dataList.add(6); + genericData_01.setGData(dataList); + + System.out.println("Modified data in the list: " + genericData_01.getGData()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + Array_1D array1D = new Array_1D(); + array1D.getIntegerArray_01(1, 2, 3, 4, 5); + array1D.getIntegerArray_02(); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + Array_2D array2D = new Array_2D(); + array2D.getIntegerArray_03(); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + List_01 list01 = new List_01(); + list01.getUnSpecificList_01(); + list01.getIntList_01(5, 547, 8, 563, 4, 4658, 3, 51, 78); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + Stack_01 stack01 = new Stack_01(); + stack01.pushToStack(); + stack01.peekFromStack(); + stack01.popFromStack(); + stack01.isStackEmpty(); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + PrimitiveJuggling_01 typeJugglingSet01 = new PrimitiveJuggling_01(); + + System.out.println("The byte is: " + typeJugglingSet01.getByte_01()); + System.out.println("The short is: " + typeJugglingSet01.getShort_01()); + System.out.println("The int is: " + typeJugglingSet01.getInt_01()); + System.out.println("The long is: " + typeJugglingSet01.getLong_01()); + System.out.println("The float is: " + typeJugglingSet01.getFloat_01()); + System.out.println("The double is: " + typeJugglingSet01.getDouble_01()); + + System.out.println("The byte to short is: " + typeJugglingSet01.getByteToShort()); + System.out.println("The short to int is: " + typeJugglingSet01.getShortToInt()); + System.out.println("The int to long is: " + typeJugglingSet01.getIntToLng()); + System.out.println("The long to float is: " + typeJugglingSet01.getLongToFlt()); + System.out.println("The float to double is: " + typeJugglingSet01.getFloatToDbl()); + + System.out.println("The double to int is:" + typeJugglingSet01.dblToInt()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Set_01 + + Set_01 set_01 = new Set_01(); + set_01.setSetWithNoDefaults(); + + System.out.println("The set with default values-01 is: " + set_01.getSetWithDefaultValues_01()); + System.out.println("The sorted set with default values-01 is: " + set_01.getSortedSetWithDefaultValues_01()); + + set_01.setSetWithDefaultValues_01(500); + System.out.println("New setWithDefaultValues_01 is: " + set_01.getSetWithDefaultValues_01()); + + set_01.setSetWithDefaultValues_02(500); + System.out.println("New setWithDefaultValues_02 is: " + set_01.getSetWithDefaultValues_01()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Map_01 + + Map numbers = new HashMap<>(Map.of( + 1, "One", + 2, "Two", + 3, "Three", + 4, "Four", + 5, "Five" + )); + + Map_01 map_01_01 = new Map_01(numbers); + + map_01_01.addEntry(6, "Six"); + map_01_01.addEntry(0, "Zero"); + System.out.println("Current map_01_01 is: "+map_01_01.getNumberMap_0001()); + System.out.println("Current values are: "+map_01_01.getValuesAsString()); + map_01_01.searchAValue("Three"); + + + + + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + Concatinations concatinations = new Concatinations(); + + System.out.println("An integer + a string results in: " + concatinations.concatIntegerAndString()); + System.out.println("An integer + a double results in: " + concatinations.concatIntegerAndDouble()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + CallAMethodInAnother callAMethodInAnother = new CallAMethodInAnother(); + + System.out.println("A method called via parameter of another method: " + callAMethodInAnother.callAMethod(callAMethodInAnother.methodToCall())); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Enum + + Day friday = Day.FRIDAY; + System.out.println("Today is: " + friday); + + Status notFound = Status.NOT_FOUND; + System.out.println("The " + notFound.getStatusCode() + " message is " + notFound.getMessage()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Types juggling + + Random_0001 random0001 = new Random_0001(); + + System.out.println("int to long: " + random0001.intToLng(12)); + System.out.println("int to Integer: " + random0001.intToInteger(random0001.getNum_02())); + System.out.println("String to int: " + random0001.strToInt(random0001.getText_03())); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // CreateDirectories + CreateDirectories createDirectories = new CreateDirectories("D:/Enter/LnD/Development/Git/Java/src/main/java/javaConcepts/fileAndDirectory/createdDirectories/dir"); + + createDirectories.createADirectory(); + createDirectories.createMultipleDirectories(); + + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // CheckExistence (Directories) + + CheckExistence checkExistence = new CheckExistence("D:/Enter/LnD/Development/Git/Java/src/main/java/javaConcepts/fileAndDirectory/createdDirectories/"); + + checkExistence.checkSingleDirectory("dir"); + System.out.println("Current directory is: "+ checkExistence.getPath().toString()); + checkExistence.checkMultipleDirectories(); + + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Delete Directories + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Array_2D_0001 + + Array_2D_0001 array_2D_0001 = new Array_2D_0001(); + + array_2D_0001.getArray(); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // ArraySum_0001 + + int[] anIntArray = {1,2,3,4}; + + ArraySum_0001 arraySum_0001_01 = new ArraySum_0001(anIntArray); + System.out.println("The total of arraySum_0001_01 is: "+ arraySum_0001_01.getSum()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // ListAverage_0001 + + List dblValues_01 = new ArrayList<>(List.of(1.57, 2.78, 3.15, 4.64)); + + ListAverage_0001 listAverage_0001_01 = new ListAverage_0001(dblValues_01); + System.out.println("The average of dblValues_01 is: "+listAverage_0001_01.getAverage()); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // WordFrequency_0001 + + String sentence = "Java is fun, Java is powerful, Java is versatile."; + + WordFrequency_0001 wordFrequency_0001_01 = new WordFrequency_0001(); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // Fibonacci_Series + + + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + // OverLoading_0001 + OverLoading_0001 overLoadingTest0001 = new OverLoading_0001(); + overLoadingTest0001.displayParam("Hello"); + + System.out.println("X---------------------X---------------------X---------------------X---------------------X"); + + + + } +} diff --git a/src/main/java/javaConcepts/conditionals/IfElse.java b/src/main/java/javaConcepts/conditionals/IfElse.java new file mode 100644 index 0000000..51a5ae9 --- /dev/null +++ b/src/main/java/javaConcepts/conditionals/IfElse.java @@ -0,0 +1,45 @@ +package javaConcepts.conditionals; + + +import javaConcepts.dataTypes.NonPrimitiveData; +import javaConcepts.dataTypes.PrimitiveData; + +public class IfElse { + private PrimitiveData primitives; + private NonPrimitiveData nonPrimitives; + private String currentDataType; + + public IfElse() { + this.primitives = new PrimitiveData(); + this.nonPrimitives = new NonPrimitiveData(); + this.currentDataType = ""; + } + + public void checkDataType(Object value) { + if (value instanceof Byte) { + this.currentDataType = "Byte"; + } else if (value instanceof Short) { + this.currentDataType = "Short"; + } else if (value instanceof Integer) { + this.currentDataType = "Integer"; + } else if (value instanceof Long) { + this.currentDataType = "Long"; + } else if (value instanceof Float) { + this.currentDataType = "Float"; + } else if (value instanceof Double) { + this.currentDataType = "Double"; + } else if (value instanceof Character) { + this.currentDataType = "Character"; + } else if (value instanceof Boolean) { + this.currentDataType = "Boolean"; + } else if (value instanceof String) { + this.currentDataType = "String"; + } else { + throw new RuntimeException("Not a valid data type"); + } + } + + public String getCurrentDataType() { + return this.currentDataType; + } +} diff --git a/src/main/java/javaConcepts/conditionals/SwitchCase.java b/src/main/java/javaConcepts/conditionals/SwitchCase.java new file mode 100644 index 0000000..d068706 --- /dev/null +++ b/src/main/java/javaConcepts/conditionals/SwitchCase.java @@ -0,0 +1,4 @@ +package javaConcepts.conditionals; + +public class SwitchCase { +} diff --git a/src/main/java/javaConcepts/dataTypes/Array_1D.java b/src/main/java/javaConcepts/dataTypes/Array_1D.java new file mode 100644 index 0000000..30d38ee --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Array_1D.java @@ -0,0 +1,28 @@ +package javaConcepts.dataTypes; + +import java.util.Arrays; + +public class Array_1D { + private Integer[] integerArray_01 = new Integer[5]; + private Integer[] integerArray_02 = {6, 7, 8, 9, 10}; + + public Integer[] getIntegerArray_01(Integer... myIntegers) { + // Set values to integerArray_01 + try { + for (int i = 0; i < myIntegers.length; i++) { + integerArray_01[i] = myIntegers[i]; + } + } catch (ArrayIndexOutOfBoundsException e) { + System.out.println("The Array_1D "+e.getMessage()); + } + + // Display & return the integerArray_01 + System.out.println("The IntegerArray_01 is: " + Arrays.toString(integerArray_01)); + return integerArray_01; + } + + public Integer[] getIntegerArray_02() { + System.out.println("The IntegerArray_02 is: " + Arrays.toString(integerArray_02)); + return integerArray_02; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/Array_2D.java b/src/main/java/javaConcepts/dataTypes/Array_2D.java new file mode 100644 index 0000000..ca7049e --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Array_2D.java @@ -0,0 +1,25 @@ +package javaConcepts.dataTypes; + +import java.util.Arrays; + +public class Array_2D { + private Integer[][] integerArray_03 = { + {1, 2, 3, 4, 5}, + {6, 7, 8, 9, 10}, + {11, 12, 13, 14, 15} + }; + + public Integer[][] getIntegerArray_03() { + for(int i = 0; i< integerArray_03.length; i++) { + Integer[] integerArray_03_01 = integerArray_03[i]; + System.out.println("The current sub array is: "+ Arrays.deepToString(integerArray_03_01)); + + for(int j = 0; j < integerArray_03_01.length; j++) { + Integer currentValue = integerArray_03_01[j]; + System.out.println("The current value in the sub array is: "+currentValue); + } + } + + return integerArray_03; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/Array_2D_0001.java b/src/main/java/javaConcepts/dataTypes/Array_2D_0001.java new file mode 100644 index 0000000..4eea410 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Array_2D_0001.java @@ -0,0 +1,32 @@ +package javaConcepts.dataTypes; + +import java.util.Arrays; + +public class Array_2D_0001 { + private String[] fruits; + private String[] vegetables; + private String[] meats; + + public Array_2D_0001() { + this.fruits = new String[]{"Apple", "Orange", "Banana", "Grape", "Watermelon"}; + this.vegetables = new String[]{"Potato", "Onion", "Carrot", "Tomato"}; + this.meats = new String[]{"Beef", "Mutton", "Chicken", "Fish"}; + } + + public String[][] get2DArray() { + return new String[][]{this.fruits, this.vegetables, this.meats}; + } + + public String[] getArray() { + for (String[] arr1 : this.get2DArray()) { + System.out.println("Current Array is: " + Arrays.toString(arr1)); + + for (String arr2 : arr1) { + System.out.println("Current String is: " + arr2); + } + +// return arr1; + } + return null; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/GenericData_01.java b/src/main/java/javaConcepts/dataTypes/GenericData_01.java new file mode 100644 index 0000000..2370fc4 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/GenericData_01.java @@ -0,0 +1,20 @@ +package javaConcepts.dataTypes; + +public class GenericData_01 { + private T gData; + + // Constructor + public GenericData_01(T gData) { + this.gData = gData; + } + + // Setter + public void setGData(T gData) { + this.gData = gData; + } + + // Getter + public T getGData() { + return this.gData; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/GenericData_02.java b/src/main/java/javaConcepts/dataTypes/GenericData_02.java new file mode 100644 index 0000000..f9e4308 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/GenericData_02.java @@ -0,0 +1,17 @@ +package javaConcepts.dataTypes; + +public class GenericData_02 { + private T gData; + + public GenericData_02(T gData) { + this.gData = gData; + } + + public void setData(T data) { + this.gData = data; + } + + public T getGData() { + return this.gData; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/List_01.java b/src/main/java/javaConcepts/dataTypes/List_01.java new file mode 100644 index 0000000..05ca113 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/List_01.java @@ -0,0 +1,31 @@ +package javaConcepts.dataTypes; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class List_01 { + private List unSpecificList_01 = new ArrayList<>(); + private List intList_01 = new ArrayList<>(); + + public List getUnSpecificList_01() { + unSpecificList_01.add('c'); + unSpecificList_01.add("abcd"); + unSpecificList_01.add(11); + unSpecificList_01.add(111.19); + unSpecificList_01.add(true); + unSpecificList_01.add(false); + unSpecificList_01.add(Arrays.toString(new int[] {11, 5, 78, 80})); + + System.out.println("The IntList is: "+ unSpecificList_01); + return unSpecificList_01; + } + + public List getIntList_01(Integer... myIntegers) { + for(int myInt:myIntegers) { + intList_01.add(myInt); + } + System.out.println("The current integer list is: "+ intList_01); + return intList_01; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/Map_01.java b/src/main/java/javaConcepts/dataTypes/Map_01.java new file mode 100644 index 0000000..c0c177a --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Map_01.java @@ -0,0 +1,42 @@ +package javaConcepts.dataTypes; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +public class Map_01 { + private final Map numberMap_0001; + + public Map_01(Map initialMap) { + this.numberMap_0001 = new HashMap<>(initialMap); + } + + public Map getNumberMap_0001() { + return Map.copyOf(this.numberMap_0001); + } + + public void addEntry(Integer key, String value) { + this.numberMap_0001.put(key, value); + } + + public String getValuesAsString() { + if (this.getNumberMap_0001().isEmpty()) { + return ""; + } + return this.getNumberMap_0001().values() + .stream() + .collect(Collectors.joining(", ")); + } + + public Boolean searchAValue(String value) { + for(Map.Entry entry:this.getNumberMap_0001().entrySet()) { + if(entry.getValue().equals(value)) { + System.out.println("The value is found at index: "+entry.getKey()); + return true; + } else { + System.out.println("The value is not found"); + } + } + return false; + } +} \ No newline at end of file diff --git a/src/main/java/javaConcepts/dataTypes/NonPrimitiveData.java b/src/main/java/javaConcepts/dataTypes/NonPrimitiveData.java new file mode 100644 index 0000000..d520125 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/NonPrimitiveData.java @@ -0,0 +1,118 @@ +package javaConcepts.dataTypes; + +import java.util.*; + +public class NonPrimitiveData { + private String stringValue; + private Integer integerValue; + private Double doubleValue; + private Boolean booleanValue; + private int[] intArray; + private ArrayList arrayList; + private Set hashSet; + private List arrayListGeneric; + private LinkedList linkedList; + private Map hashMapGeneric = new HashMap<>(); + private HashMap hashMap = new HashMap<>(); + private List listOfPreDefinedIntegers = new ArrayList<>(Arrays.asList(11, 15, 18, 880, 721, 572, 97, 83, 111)); + private Set setOfPreDefinedIntegers = new HashSet<>(Arrays.asList(5153, 165, 1635, 15, 1351, 631, 51, 351, 531, 58, 4658, 9784, 87)); + + + + + public NonPrimitiveData() { + this.stringValue = "Hello, World!"; + + this.integerValue = 999999999; + + this.doubleValue = 999999999.9999999; + + this.booleanValue = false; + + this.intArray = new int[]{1, 2, 3, 4, 5}; + + this.arrayList = new ArrayList<>(Arrays.asList("Apple", "Banana", "Cherry")); + + this.hashSet = new HashSet<>(Arrays.asList("One", "Two", "Three")); + + this.arrayListGeneric = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5)); + + this.linkedList = new LinkedList<>(Arrays.asList("Linked", "List", "Example")); + + this.hashMapGeneric.put(1, "Four"); + this.hashMapGeneric.put(2, "Five"); + this.hashMapGeneric.put(3, "Six"); + + this.hashMap.put("One", 1); + this.hashMap.put("Two", 2); + this.hashMap.put("Three", 3); + + this.listOfPreDefinedIntegers.add(521); + this.listOfPreDefinedIntegers.add(628); + this.listOfPreDefinedIntegers.add(58); + this.listOfPreDefinedIntegers.add(92); + + this.setOfPreDefinedIntegers.add(511); + this.setOfPreDefinedIntegers.add(83); + } + + + + + public String getStringValue() { + return this.stringValue; + } + + public Integer getIntegerValue() { + return this.integerValue; + } + + public Double getDoubleValue() { + return this.doubleValue; + } + + public Boolean getBooleanValue() { + return this.booleanValue; + } + + public int[] getIntArray() { + return this.intArray; + } + + public ArrayList getArrayList() { + return this.arrayList; + } + + public Set getHashSet() { + return this.hashSet; + } + + public List getArrayListGeneric() { + return this.arrayListGeneric; + } + + public LinkedList getLinkedList() { + return this.linkedList; + } + + public Map getHashMapGeneric() { + return this.hashMapGeneric; + } + + public HashMap getHashMap() { + return this.hashMap; + } + + public Boolean is829InTheList() { + if (this.listOfPreDefinedIntegers.contains(829)) { + System.out.println("The ListOfPreDefinedIntegers has the value 829."); + return true; + } + System.out.println("The ListOfPreDefinedIntegers does not have the value 829"); + return false; + } + + public Set getSetOfPreDefinedIntegers() { + return this.setOfPreDefinedIntegers; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/PrimitiveData.java b/src/main/java/javaConcepts/dataTypes/PrimitiveData.java new file mode 100644 index 0000000..91481e6 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/PrimitiveData.java @@ -0,0 +1,55 @@ +package javaConcepts.dataTypes; + +public class PrimitiveData { + private byte byteValue; + private short shortValue; + private int intValue; + private long longValue; + private float floatValue; + private double doubleValue; + private char charValue; + private boolean booleanValue; + + public PrimitiveData() { + this.byteValue = 100; + this.shortValue = 10000; + this.intValue = 100000; + this.longValue = 10000000000L; + this.floatValue = 20.5f; + this.doubleValue = 123.456; + this.charValue = 'A'; + this.booleanValue = true; + } + + public byte getByteValue() { + return byteValue; + } + + public short getShortValue() { + return shortValue; + } + + public int getIntValue() { + return intValue; + } + + public long getLongValue() { + return longValue; + } + + public float getFloatValue() { + return floatValue; + } + + public double getDoubleValue() { + return doubleValue; + } + + public char getCharValue() { + return charValue; + } + + public boolean isBooleanValue() { + return booleanValue; + } +} diff --git a/src/main/java/javaConcepts/dataTypes/Set_01.java b/src/main/java/javaConcepts/dataTypes/Set_01.java new file mode 100644 index 0000000..c37cee2 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Set_01.java @@ -0,0 +1,58 @@ +package javaConcepts.dataTypes; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Set_01 { + private Set setWithDefaultValues_01; + private Set setWithNoDefaults; + private Set setWithDefaultValues_02; + + public Set_01() { + this.setWithDefaultValues_01 = new HashSet<>(Arrays.asList(5, 9, 97, 6, 3, 1, 4, 6, 3, 5, 8, 7, 4, 6, 9, 8, 5, 8, 4)); + this.setWithNoDefaults = new HashSet<>(); + this.setWithDefaultValues_02 = new HashSet<>(Set.of(1,2,3,4)); + } + + public Set_01 setSetWithNoDefaults() { + for (int i = 0; i < 15; i++) { + this.setWithNoDefaults.add(i); + } + return this; + } + + public Set setSetWithDefaultValues_01(Integer number) { + this.setWithDefaultValues_01.add(number); + return this.setWithDefaultValues_01; + } + + public Set setSetWithDefaultValues_02(Integer number) { + this.setWithDefaultValues_01.add(number); + return this.setWithDefaultValues_01; + } + + public Set getSetWithDefaultValues_01() { + return this.setWithDefaultValues_01; + } + + public Set getSetWithNoDefaults() { + return this.setWithNoDefaults; + } + + public Set getSetWithDefaultValues_02() { + return this.setWithDefaultValues_02; + } + + public Set getSortedSetWithDefaultValues_01() { + Stream newSet = this.setWithDefaultValues_01.stream().sorted(); + return newSet.collect(Collectors.toSet()); + } + + public Set getSortedSetWithDefaultValues_02() { + Stream aStream = this.setWithDefaultValues_02.stream(); + return aStream.collect(Collectors.toSet()); + } +} diff --git a/src/main/java/javaConcepts/dataTypes/Stack_01.java b/src/main/java/javaConcepts/dataTypes/Stack_01.java new file mode 100644 index 0000000..0d54891 --- /dev/null +++ b/src/main/java/javaConcepts/dataTypes/Stack_01.java @@ -0,0 +1,33 @@ +package javaConcepts.dataTypes; + +import java.util.Stack; + +public class Stack_01 { + private Stack unspecificStack_01 = new Stack(); + private Stack intStack_01 = new Stack<>(); + + public void pushToStack() { + for (int i = 0; i < 5; i++) { + unspecificStack_01.push(i + 1); + } + + System.out.println("The stack is now: " + unspecificStack_01); + } + + public void peekFromStack() { + Object latestObject = unspecificStack_01.peek(); + System.out.println("It peeked "+ latestObject+ " & the stack is now "+unspecificStack_01); + System.out.println("The stack is now: "+ unspecificStack_01); + } + + public void popFromStack() { + unspecificStack_01.pop(); + System.out.println("The stack is now: "+ unspecificStack_01); + } + + public Boolean isStackEmpty() { + Boolean isEmpty = unspecificStack_01.empty(); + System.out.println("Is the stack empty? "+isEmpty); + return unspecificStack_01.empty(); + } +} diff --git a/src/main/java/javaConcepts/enumWorks/Day.java b/src/main/java/javaConcepts/enumWorks/Day.java new file mode 100644 index 0000000..220114a --- /dev/null +++ b/src/main/java/javaConcepts/enumWorks/Day.java @@ -0,0 +1,5 @@ +package javaConcepts.enumWorks; + +public enum Day { + SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; +} diff --git a/src/main/java/javaConcepts/enumWorks/Status.java b/src/main/java/javaConcepts/enumWorks/Status.java new file mode 100644 index 0000000..a76c7ee --- /dev/null +++ b/src/main/java/javaConcepts/enumWorks/Status.java @@ -0,0 +1,23 @@ +package javaConcepts.enumWorks; + +public enum Status { + SUCCESS(200, "Success"), + NOT_FOUND(404, "Not Found"), + INTERNAL_ERROR(500, "Internal Server Error"); + + private final int statusCode; + private final String message; + + Status(int statusCode, String message) { + this.statusCode = statusCode; + this.message = message; + } + + public int getStatusCode() { + return this.statusCode; + } + + public String getMessage() { + return this.message; + } +} diff --git a/src/main/java/javaConcepts/fileAndDirectory/CheckExistence.java b/src/main/java/javaConcepts/fileAndDirectory/CheckExistence.java new file mode 100644 index 0000000..a86d020 --- /dev/null +++ b/src/main/java/javaConcepts/fileAndDirectory/CheckExistence.java @@ -0,0 +1,52 @@ +package javaConcepts.fileAndDirectory; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; + +public class CheckExistence { + private String pathString; + private Path path; + + public CheckExistence(String pathString) { + this.pathString = pathString; + this.path = Path.of(pathString); + } + + public String getPathString() { + return this.pathString; + } + + public Path getPath() { + return this.path; + } + + public void checkSingleDirectory(String dir) { + this.path = Path.of(this.getPathString() + dir); + + if (Files.exists(this.getPath())) { + System.out.println("Directory " + path + " exists."); + } else { + System.out.println("Directory " + path + " does not exist."); + } + + this.path = Path.of(this.getPathString().replace(dir, "")); + } + + public void checkMultipleDirectories() { + try { + DirectoryStream parentDirectory = Files.newDirectoryStream(this.getPath()); + + for (Path path : parentDirectory) { + if (Files.exists(path)) { + System.out.println("The directory " + path + " exists."); + } else { + System.out.println("The directory " + path + " does not exist."); + } + } + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } + } +} diff --git a/src/main/java/javaConcepts/fileAndDirectory/CreateDirectories.java b/src/main/java/javaConcepts/fileAndDirectory/CreateDirectories.java new file mode 100644 index 0000000..7eaba92 --- /dev/null +++ b/src/main/java/javaConcepts/fileAndDirectory/CreateDirectories.java @@ -0,0 +1,48 @@ +package javaConcepts.fileAndDirectory; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class CreateDirectories { + private String pathString; + private Path path; + + public CreateDirectories(String pathString) { + this.pathString = pathString; + this.path = Path.of(pathString); + } + + public Path getPath() { + return this.path; + } + + public void createADirectory() { + if (!Files.exists(this.getPath())) { + try { + Files.createDirectories(this.getPath()); + System.out.println("The directory is created!"); + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } + } else { + System.out.println("Directory "+this.getPath()+" already exists."); + } + } + + public void createMultipleDirectories() { + for(int i = 0; i < 10; i++) { + this.path = Path.of(this.pathString+i); + if(Files.notExists(this.getPath())) { + try { + Files.createDirectories(this.getPath()); + System.out.println("The directory is created!"); + } catch (IOException e) { + throw new RuntimeException(e.getMessage()); + } + } else { + System.out.println("Directory "+this.getPath()+" already exists."); + } + } + } +} diff --git a/src/main/java/javaConcepts/fileAndDirectory/DeleteDirAndFiles.java b/src/main/java/javaConcepts/fileAndDirectory/DeleteDirAndFiles.java new file mode 100644 index 0000000..22c5c7f --- /dev/null +++ b/src/main/java/javaConcepts/fileAndDirectory/DeleteDirAndFiles.java @@ -0,0 +1,34 @@ +package javaConcepts.fileAndDirectory; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +public class DeleteDirAndFiles { + private String pathString; + private Path path; + + public DeleteDirAndFiles(String pathString) { + this.pathString = pathString; + this.path = Path.of(pathString); + } + + public String getPathString() { + return this.pathString; + } + + public Path getPath() { + return this.path; + } + + public void deleteADir() { + if (Files.exists(this.getPath()) && Files.isDirectory(this.getPath())) { + try { + Files.delete(this.getPath()); + System.out.println("The directory is deleted!"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } +} diff --git a/src/main/java/javaConcepts/oop/AbstructClass_001.java b/src/main/java/javaConcepts/oop/AbstructClass_001.java new file mode 100644 index 0000000..c2b5ed3 --- /dev/null +++ b/src/main/java/javaConcepts/oop/AbstructClass_001.java @@ -0,0 +1,23 @@ +package javaConcepts.oop; + +public abstract class AbstructClass_001 { + private String myStringInAbstructClass_001; + private Integer myIntegerInAbstructClass_001; + + public AbstructClass_001(String str, Integer integer) { + this.myStringInAbstructClass_001 = str; + this.myIntegerInAbstructClass_001 = integer; + } + + public String getMyStringInAbstructClass_001() { + return myStringInAbstructClass_001; + } + + public abstract void setMyStringInAbstructClass_001(String myStringInAbstructClass_001); + + public Integer getMyIntegerInAbstructClass_001() { + return myIntegerInAbstructClass_001; + } + + public abstract void setMyIntegerInAbstructClass_001(Integer myIntegerInAbstructClass_001); +} diff --git a/src/main/java/javaConcepts/oop/Interface_001.java b/src/main/java/javaConcepts/oop/Interface_001.java new file mode 100644 index 0000000..1049ba8 --- /dev/null +++ b/src/main/java/javaConcepts/oop/Interface_001.java @@ -0,0 +1,15 @@ +package javaConcepts.oop; + +public interface Interface_001 { + String myStringInInterface_001 = "A String"; + Integer myIntegerInInterface_001 = 22; + Long myLongInInterface_001 = 111L; + + default String getMyStringInInterface_001() { + return myStringInInterface_001; + }; + + Integer getMyIntegerInInterface_001(); + + Long setMyLongInInterface_001(Long newLong); +} diff --git a/src/main/java/javaConcepts/oop/NormalClass_001.java b/src/main/java/javaConcepts/oop/NormalClass_001.java new file mode 100644 index 0000000..5400679 --- /dev/null +++ b/src/main/java/javaConcepts/oop/NormalClass_001.java @@ -0,0 +1,49 @@ +package javaConcepts.oop; + +public class NormalClass_001 extends AbstructClass_001 implements Interface_001 { + public NormalClass_001(String str, Integer integer) { + super(str, integer); + } + + @Override + public String getMyStringInInterface_001() { + System.out.println(myStringInInterface_001); + return Interface_001.super.getMyStringInInterface_001(); + } + + @Override + public Integer getMyIntegerInInterface_001() { + return myIntegerInInterface_001; + } + + @Override + public Long setMyLongInInterface_001(Long newLong) { +// return myLongInInterface_001 = newLong; + return newLong; + } + + @Override + public void setMyStringInAbstructClass_001(String myStringInAbstructClass_001) { + + } + + @Override + public void setMyIntegerInAbstructClass_001(Integer myIntegerInAbstructClass_001) { + + } + + public String returnHello() { + return "Hello!"; + } + + public String retrunHello(String hello) { + return hello; + } + + public String retrunHello(int times) { + for(int i = 0; i < times; i++) { + return "Hello!"; + } + return null; + } +} diff --git a/src/main/java/javaConcepts/oop/OverLoading_0001.java b/src/main/java/javaConcepts/oop/OverLoading_0001.java new file mode 100644 index 0000000..b5d51a9 --- /dev/null +++ b/src/main/java/javaConcepts/oop/OverLoading_0001.java @@ -0,0 +1,13 @@ +package javaConcepts.oop; + +public class OverLoading_0001 { + + public void displayParam(Integer aNum) { + System.out.println("The argument is: " + aNum); + } + + public void displayParam(String aStr) { + System.out.println("The argument is: " + aStr); + } + +} diff --git a/src/main/java/javaConcepts/randomPractice/ArraySum_0001.java b/src/main/java/javaConcepts/randomPractice/ArraySum_0001.java new file mode 100644 index 0000000..f8714e4 --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/ArraySum_0001.java @@ -0,0 +1,22 @@ +// Problem: Given an array of integers, calculate the sum of all its elements. + +package javaConcepts.randomPractice; + +public class ArraySum_0001 { + private int[] intArray; + + public ArraySum_0001(int[] intArray) { + this.intArray = intArray; + } + + public int getSum() { + int total = 0; + + for(int i:this.intArray) { + total +=i; + System.out.println("Current total is: "+total); + } + + return total; + } +} diff --git a/src/main/java/javaConcepts/randomPractice/CallAMethodInAnother.java b/src/main/java/javaConcepts/randomPractice/CallAMethodInAnother.java new file mode 100644 index 0000000..2b1d57a --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/CallAMethodInAnother.java @@ -0,0 +1,13 @@ +package javaConcepts.randomPractice; + +public class CallAMethodInAnother { + public CallAMethodInAnother() {} + + public String methodToCall() { + return "This is a method called in another method"; + } + + public String callAMethod(String method) { + return method; + } +} diff --git a/src/main/java/javaConcepts/randomPractice/Concatinations.java b/src/main/java/javaConcepts/randomPractice/Concatinations.java new file mode 100644 index 0000000..247bf15 --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/Concatinations.java @@ -0,0 +1,21 @@ +package javaConcepts.randomPractice; + +public class Concatinations { + private Integer integer_0001; + private Double double_0001; + private String string_0001; + + public Concatinations() { + this.integer_0001 = 100; + this.double_0001 = 100.10; + this.string_0001 = "Rajib"; + } + + public String concatIntegerAndString() { + return this.integer_0001+this.string_0001; + } + + public double concatIntegerAndDouble() { + return this.integer_0001+this.double_0001; + } +} diff --git a/src/main/java/javaConcepts/randomPractice/Fibonacci_Series.java b/src/main/java/javaConcepts/randomPractice/Fibonacci_Series.java new file mode 100644 index 0000000..0f78ca7 --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/Fibonacci_Series.java @@ -0,0 +1,16 @@ +package javaConcepts.randomPractice; + +public class Fibonacci_Series { + public void generateFibonacciSeries(int count) { + int a = 0; + int b = 1; + System.out.print("Fibonacci Series of " + count + " numbers: "); + for (int i = 0; i < count; i++) { + System.out.print(a + " "); + int sum = a + b; + a = b; + b = sum; + } + System.out.println(); + } +} diff --git a/src/main/java/javaConcepts/randomPractice/ListAverage_0001.java b/src/main/java/javaConcepts/randomPractice/ListAverage_0001.java new file mode 100644 index 0000000..1c9e949 --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/ListAverage_0001.java @@ -0,0 +1,23 @@ +// Problem: Given a list of double values, calculate their average. + +package javaConcepts.randomPractice; + +import java.util.List; + +public class ListAverage_0001 { + private List dblValues_01; + + public ListAverage_0001(List dblValues_01) { + this.dblValues_01 = dblValues_01; + } + + public Double getAverage() { + Double total = 0.00; + + for(Double dbl:this.dblValues_01) { + total+=dbl; + } + + return total / this.dblValues_01.size(); + } +} diff --git a/src/main/java/javaConcepts/randomPractice/WordFrequency_0001.java b/src/main/java/javaConcepts/randomPractice/WordFrequency_0001.java new file mode 100644 index 0000000..371583d --- /dev/null +++ b/src/main/java/javaConcepts/randomPractice/WordFrequency_0001.java @@ -0,0 +1,7 @@ +// Problem: Count the frequency of each word in a given sentence (case-insensitive). + +package javaConcepts.randomPractice; + +public class WordFrequency_0001 { + +} diff --git a/src/main/java/javaConcepts/typeJuggling/PrimitiveJuggling_01.java b/src/main/java/javaConcepts/typeJuggling/PrimitiveJuggling_01.java new file mode 100644 index 0000000..1e4e50a --- /dev/null +++ b/src/main/java/javaConcepts/typeJuggling/PrimitiveJuggling_01.java @@ -0,0 +1,69 @@ +package javaConcepts.typeJuggling; + +public class PrimitiveJuggling_01 { + private byte byte_01; + private short short_01; + private int int_01; + private long long_01; + private float float_01; + private double double_01; + + public PrimitiveJuggling_01() { + this.byte_01 = 99; + this.short_01 = 9999; + this.int_01 = 999999999; + this.long_01 = 999999999999999999L; + this.float_01 = 9999999999.999999999F; + this.double_01 = 999999999999.9999999999999999999999; + } + + public byte getByte_01() { + return this.byte_01; + } + + public short getShort_01() { + return this.short_01; + } + + public int getInt_01() { + return this.int_01; + } + + public long getLong_01() { + return this.long_01; + } + + public float getFloat_01() { + return this.float_01; + } + + public double getDouble_01() { + return this.double_01; + } + + /*------------------------------------------------------------------------------------*/ + + public short getByteToShort() { + return (short) getByte_01(); + } + + public int getShortToInt() { + return (int) getShort_01(); + } + + public long getIntToLng() { + return (long) getInt_01(); + } + + public float getLongToFlt() { + return (float) getLong_01(); + } + + public double getFloatToDbl() { + return (double) getFloat_01(); + } + + public int dblToInt() { + return (int) getDouble_01(); + } +} diff --git a/src/main/java/javaConcepts/typeJuggling/Random_0001.java b/src/main/java/javaConcepts/typeJuggling/Random_0001.java new file mode 100644 index 0000000..7db2b85 --- /dev/null +++ b/src/main/java/javaConcepts/typeJuggling/Random_0001.java @@ -0,0 +1,79 @@ +package javaConcepts.typeJuggling; + +import com.sun.jdi.InvalidTypeException; + +public class Random_0001 { + String text_01; + String text_02; + String text_03; + Integer num_01; + int num_02; + + public Random_0001() { + this.text_01 = "Hello!"; + this.text_02 = "18.587"; + this.text_03 = "712"; + this.num_01 = 122; + this.num_02 = 197; + } + + public String getText_01() { + return text_01; + } + + public String getText_02() { + return text_02; + } + + public String getText_03() { + return text_03; + } + + public Integer getNum_01() { + return num_01; + } + + public int getNum_02() { + return num_02; + } + + public int strToInt(String text) { + try { + return Integer.parseInt(text); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Can not parse an int from the String"); + } + } + + public double strToDbl(String text) { + return Double.parseDouble(text); + } + + public long strToLng(String text) { + return Long.parseLong(text); + } + + public long intToLng(int number) { + return (long) number; + } + + public String integerToString(Integer number) { + return String.valueOf(number); + } + + public String doubleToString(Double number) { + return String.valueOf(number); + } + + public Integer intToInteger(int number) { + Integer n = Integer.valueOf(number); + if (n instanceof Integer) { + return n; + } + try { + throw new InvalidTypeException("Not an Integer"); + } catch (InvalidTypeException e) { + throw new RuntimeException(e.getMessage()); + } + } +} diff --git a/src/main/java/problems/Main.java b/src/main/java/problems/Main.java new file mode 100644 index 0000000..f1d3d18 --- /dev/null +++ b/src/main/java/problems/Main.java @@ -0,0 +1,106 @@ +package problems; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class Main { + + public static void main(String[] args) { + + System.out.println("X----------------------------------StringManipulations starts----------------------------------X"); + + StringManipulations sm1 = new StringManipulations(); + sm1.sortString("How are you?"); + sm1.reverseSortAString("Hey there!"); + sm1.reverseString("Hello!"); + sm1.makeRandomStrings("Hello!"); + sm1.getAPartOfAString("Hello World"); + + + System.out.println("X-----------------------------------StringManipulations ends-----------------------------------X"); + + + System.out.println("X----------------------------------StreamAPI starts----------------------------------X"); + + // StreamAPI + + StreamAPI stAPI1 = new StreamAPI(); + Map fruits = new HashMap<>(Map.of( + 1, "Apple", + 2, "Banana", + 3, "Orange", + 4, "Pineapple" + )); + fruits.put(5, "Lemon"); + + System.out.println("The sorted fruites are: " + stAPI1.sortByValues(fruits)); + System.out.println("The reversed sorted fruites are: " + stAPI1.reverseSortByValues(fruits)); + + + System.out.println("X-----------------------------------StreamAPI ends-----------------------------------X"); + + + System.out.println("X----------------------------------PlayWithArrays starts----------------------------------X"); + + PlayWithArrays pwA1 = new PlayWithArrays(); + + int[] anArr0001 = {5, 8, 76, 3, 75, 3}; + pwA1.findLargestNum(anArr0001); + pwA1.sortArray(anArr0001); + pwA1.reverseArray(anArr0001); + + System.out.println("X-----------------------------------PlayWithArrays ends-----------------------------------X"); + + + System.out.println("X----------------------------------PlayWithLists starts----------------------------------X"); + + // PlayWithLists + + PlayWithLists pl0001 = new PlayWithLists(); + + Integer[] anIntegerArr0001 = {1, 2, 3, 4, 5}; + List aList0001 = List.of(68, 7, 6341, 634, 313, 213, 1); + pl0001.isEven(anIntegerArr0001); + pl0001.sortAList(aList0001); + pl0001.reverseSortAList(aList0001); + + + System.out.println("X-----------------------------------PlayWithLists ends-----------------------------------X"); + + + System.out.println("X----------------------------------PlayWithMaps starts----------------------------------X"); + + // PlayWithMaps + + PlayWithMaps pwM1 = new PlayWithMaps(); + pwM1.countCharacters("Hello World!"); + + + Integer[] anIntegerArr0002 = {1, 2, 3, 4, 5, 1, 3, 5}; + pwM1.countRepeatations(anIntegerArr0002); + + System.out.println("X-----------------------------------PlayWithMaps ends-----------------------------------X"); + + + System.out.println("X----------------------------------PlayWithSets starts----------------------------------X"); + + // PlayWithSets + + PlayWithSets pwS1 = new PlayWithSets(); + + Integer[] intArr0001 = {1, 1, 2, 2, 3, 4, 5, 6, 6}; + pwS1.listAsUnique(intArr0001); + + System.out.println("X-----------------------------------PlayWithSets ends-----------------------------------X"); + + System.out.println("X-----------------------------------PlayWithNumbers_0001 ends-----------------------------------X"); + + PlayWithNumbers_0001 pWN01 = new PlayWithNumbers_0001(); + pWN01.totalOfDigits(1234); + + System.out.println("X-----------------------------------PlayWithNumbers_0001 ends-----------------------------------X"); + + } + +} diff --git a/src/main/java/problems/PlayWithArrays.java b/src/main/java/problems/PlayWithArrays.java new file mode 100644 index 0000000..3d8f268 --- /dev/null +++ b/src/main/java/problems/PlayWithArrays.java @@ -0,0 +1,43 @@ +package problems; + +import java.util.Arrays; + +public class PlayWithArrays { + + // Find the largest number in the given Array + public int findLargestNum(int[] intArr) { + int max = intArr[0]; + for (int i = 0; i < intArr.length; i++) { + if (intArr[i] > max) { + max = intArr[i]; + } + } + System.out.println("The largest number in the Arrays is: " + max); + return max; + } + + // Sort the given Array + public int[] sortArray(int[] arr) { + Arrays.sort(arr); + System.out.println("The Arrays now is: " + Arrays.toString(arr)); + return arr; + } + + // Reverse the given Array + public int[] reverseArray(int[] arr) { + if (arr == null) { + return null; + } + + int[] reversed = new int[arr.length]; + + for (int i = 0; i < arr.length; i++) { + System.out.println("Current index is: " + (arr.length - 1 - i)); + reversed[i] = arr[arr.length - 1 - i]; + } + + System.out.println("The reversed Array is: " + Arrays.toString(reversed)); + return reversed; + } + +} diff --git a/src/main/java/problems/PlayWithLists.java b/src/main/java/problems/PlayWithLists.java new file mode 100644 index 0000000..b5233a3 --- /dev/null +++ b/src/main/java/problems/PlayWithLists.java @@ -0,0 +1,37 @@ +package problems; + +import java.util.*; +import java.util.stream.Collectors; + +public class PlayWithLists { + + // Find the even numbers in the given List + public List isEven(Integer[] integerArr) { + + List theEvensList = new ArrayList<>(); + + for (int i = 0; i < integerArr.length; i++) { + if (i % 2 == 0) { + theEvensList.add(i); + } + } + + System.out.println("The evens in the list are: " + theEvensList); + return theEvensList; + } + + // Sort the given List + public List sortAList(List integerList) { + System.out.println("The sorted list is: " + integerList.stream().sorted().toList()); + return integerList.stream().sorted().toList(); + } + + // Reverse sort the given List + public List reverseSortAList(List numList) { + List reversed = numList.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList()); + + System.out.println("The reversed list is: " + reversed); + return reversed; + } + +} diff --git a/src/main/java/problems/PlayWithMaps.java b/src/main/java/problems/PlayWithMaps.java new file mode 100644 index 0000000..00da450 --- /dev/null +++ b/src/main/java/problems/PlayWithMaps.java @@ -0,0 +1,42 @@ +package problems; + +import java.util.HashMap; +import java.util.Map; + +public class PlayWithMaps { + + // Count the characters in the given String + public Map countCharacters(String text) { + + Map charsCount = new HashMap<>(); + + if(text.isEmpty()) { + return null; + } + + for(char k : text.toCharArray()) { + charsCount.put(k, charsCount.getOrDefault(k, 0) + 1); + } + + System.out.println("The characters count is: "+charsCount.toString()); + return charsCount; + } + + public Map countRepeatations(Integer[] arr) { + + Integer[] intArr = new Integer[arr.length]; + Map elCount = new HashMap<>(); + + for (int i = 0; i < arr.length; i++) { + intArr[i] = arr[i]; + if (intArr[i] == arr[i]) { + elCount.put(intArr[i], elCount.getOrDefault(intArr[i], 0) + 1); + } + } + + System.out.println("Item repeatation counts are: "+ elCount.toString()); + return elCount; + + } + +} diff --git a/src/main/java/problems/PlayWithNumbers_0001.java b/src/main/java/problems/PlayWithNumbers_0001.java new file mode 100644 index 0000000..4e562e8 --- /dev/null +++ b/src/main/java/problems/PlayWithNumbers_0001.java @@ -0,0 +1,19 @@ +package problems; + +public class PlayWithNumbers_0001 { + + // Get the total of the digits of a number + public Integer totalOfDigits(Integer number) { + int total = 0; + String numAsStr = String.valueOf(number); + + for (int i = 0; i < numAsStr.length(); i++) { + char chrDgt = numAsStr.charAt(i); + total += Integer.parseInt(String.valueOf(chrDgt)); + } + + System.out.println("The total of the digits is: " + total); + return total; + } + +} diff --git a/src/main/java/problems/PlayWithSets.java b/src/main/java/problems/PlayWithSets.java new file mode 100644 index 0000000..12b36fb --- /dev/null +++ b/src/main/java/problems/PlayWithSets.java @@ -0,0 +1,17 @@ +package problems; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class PlayWithSets { + + public Integer[] listAsUnique(Integer[] arr) { + + Set intSet = new HashSet<>(Arrays.asList(arr)); + + System.out.println("The unique values are: "+ Arrays.toString(intSet.toArray())); + return intSet.toArray(Integer[]::new); + } + +} diff --git a/src/main/java/problems/StreamAPI.java b/src/main/java/problems/StreamAPI.java new file mode 100644 index 0000000..db74335 --- /dev/null +++ b/src/main/java/problems/StreamAPI.java @@ -0,0 +1,27 @@ +package problems; + +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.stream.Collectors; + +public class StreamAPI { + + public Map sortByValues(Map aMap) { + return aMap.entrySet() + .stream() + .sorted(Map.Entry.comparingByValue()) + .collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new) + ); + } + + public Map reverseSortByValues(Map aMap) { + return aMap.entrySet() + .stream() + .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) + .collect(Collectors.toMap( + Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> oldValue, LinkedHashMap::new) + ); + } +} diff --git a/src/main/java/problems/StringManipulations.java b/src/main/java/problems/StringManipulations.java new file mode 100644 index 0000000..222f703 --- /dev/null +++ b/src/main/java/problems/StringManipulations.java @@ -0,0 +1,77 @@ +package problems; + +import java.util.Arrays; + +public class StringManipulations { + + // Sort the given String + public String sortString(String aString) { + if (aString == null || aString.isEmpty()) { + System.out.println("The sentence is empty"); + return aString; + } + + char[] aStringArr = aString.toCharArray(); + Arrays.sort(aStringArr); + System.out.println("The sorted word/sentence is: " + Arrays.toString(aStringArr)); + return Arrays.toString(aStringArr); + } + + // Reverse sort the given String + public String reverseSortAString(String aString) { + if (aString == null || aString.isEmpty()) { + System.out.println("The sentence is empty"); + return aString; + } + + char[] aStringArr = aString.toCharArray(); + Arrays.sort(aStringArr); + + StringBuilder aStrBuilder = new StringBuilder(); + + for (int i = aStringArr.length - 1; i >= 0; i--) { + aStrBuilder.append(aStringArr[i]); + } + + System.out.println("The reversed String is: " + aStrBuilder); + return aStrBuilder.toString(); + + } + + // Reverse the given String manually + public String reverseString(String aString) { + if (aString == null || aString.isEmpty()) { + System.out.println("The sentence is empty"); + return aString; + } + + StringBuilder reversed = new StringBuilder(); + + for (int i = aString.length() - 1; i >= 0; i--) { + reversed.append(aString.charAt(i)); + } + + System.out.println("The manual reversed string is: " + reversed); + return reversed.toString(); + } + + // Make a random word/sentence from the given String + public String makeRandomStrings(String aString) { + StringBuilder randomString = new StringBuilder(); + int randNum = (int) Math.round(Math.random() * aString.length()); + + for (int i = 0; i < randNum; i++) { + randomString.append(aString.charAt(randNum)); + } + + System.out.println("The random word/sentence is: " + randomString.toString()); + return aString; + } + + // Get a part of the given String + public String getAPartOfAString(String aString) { + String cutString = aString.substring(3, 8); + System.out.println("The part of the word/sentence is: " + cutString); + return cutString.trim(); + } +}