{"id":16550288,"url":"https://github.com/sylhare/java","last_synced_at":"2025-06-25T22:03:49.149Z","repository":{"id":92385261,"uuid":"87549786","full_name":"sylhare/Java","owner":"sylhare","description":":coffee: Some java experiences for fun","archived":false,"fork":false,"pushed_at":"2023-09-18T13:30:54.000Z","size":30003,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-04T15:34:57.676Z","etag":null,"topics":["beginner","cucumber","documentation","encapsulation","intellij","java","java-development","java-virtual-machine","maven","polymorphism","sdk","tutorial"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sylhare.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-04-07T13:42:11.000Z","updated_at":"2024-10-21T17:31:00.000Z","dependencies_parsed_at":"2024-11-14T21:40:44.611Z","dependency_job_id":"a37a34bc-7ca2-4598-875e-37120c04a750","html_url":"https://github.com/sylhare/Java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/sylhare/Java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FJava","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FJava/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FJava/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FJava/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sylhare","download_url":"https://codeload.github.com/sylhare/Java/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sylhare%2FJava/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261960495,"owners_count":23236571,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner","cucumber","documentation","encapsulation","intellij","java","java-development","java-virtual-machine","maven","polymorphism","sdk","tutorial"],"created_at":"2024-10-11T19:33:45.947Z","updated_at":"2025-06-25T22:03:49.095Z","avatar_url":"https://github.com/sylhare.png","language":"Java","readme":"# Java \n\n[![forthebadge](http://forthebadge.com/images/badges/built-with-grammas-recipe.svg)](http://forthebadge.com) [![forthebadge](http://forthebadge.com/images/badges/you-didnt-ask-for-this.svg)](http://forthebadge.com)\n\nHere is a little playground for Java development. \n\n## Some Java insight\n\nThe java language developed by Oracle is:\n\n- Portable, robust and dynamic\n- Platform independent\n- Runs on the JVM (Java Virtual Machine) which is system dependant\n\nWith the JVM, you can write `.java` files, that get compiled into Java byte codes into `.class` file. The `.class` files can be executed on the Java Virtual Machine.\n\n## Environment set up\n\n### MacOS\n\nGet the open JDK (open source) with brew\n```sh\nbrew install java8\nbrew install java11\n```\n\nthen switch between multiple version using an alias to the Home of your java:\n```sh\njava11='export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home'\njava8='export JAVA_HOME=/Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home'\n```\n\n### Windows\nSDK for Software Development Kit also called JDK - Java Development Kit.\nYou can get the Oracle Java SDK [here](http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html). Choose the one for your system, here for windows. \u003c/br\u003e\nThere's the Oracle JDK (Commercial, Stable with proprietary code from Oracle) and the Open JDK (Open source, maintained by Oracle).\n\nThe JDK includes, it can be called inside a command prompt:\n\n- The Java compiler javac - **javac**\n- The Java Archiving Tool - **jar**\n- the Java Debugging Tool  - **jdb**\n\nWhen installing the JDK, don't forget to add the `JAVA_HOME` (path to the JDK and JRE - Java Runtime Environment) as an environment variable. \n\n\u003e Environment variables in windows are accessed via the start up menu (windows key) then:\n\u003e\n\u003e - right click on computer \u003e properties \u003e advance system settings \n\u003e - Click on the environment variable button\n\nI have added `setPathJava.bat` script to update the `JAVA_HOME`. The path variable is only changed for the current cmd session. (Need to update the key registry to make it definitive).\n\n### Get an IDE\nIDE for Integrated Development Environments. \u003c/br\u003e\nI'll be trying [IntelliJ: Community version](https://www.jetbrains.com/idea/#chooseYourEdition) by Jet Brain which has pro feature. \nIf you click on the link you should be able to download it (the community version is free).\n\n## Maven\n\n### What is maven\n\n[Maven](http://maven.apache.org/what-is-maven.html) is a framework developped by Apache that add standards in Java projects. By having the same hierarchy it helps keep a consistent project, manage dependencies and falicitate the build. It is a good way to share information and JAR across multiple projects.\n\n\u003e \"Maven, a Yiddish word meaning accumulator of knowledge\"\n\n### Installation\n\nHere are the steps to install Maven on [Windows](https://www.mkyong.com/maven/how-to-install-maven-in-windows/):\n\n- Make sure you've intalled java and set `JAVA_HOME`\n- Download maven at [maven.apache.org](http://maven.apache.org/download.cgi)\n- Unzip it in C:\\Program Files\\Apache\\maven\n- Add this location to the `M3_HOME` and `MAVEN_HOME` environment variable\n- Add `%M3_HOME%\\bin` to the `PATH` environment variable \n\t- :warning: no space between the variable path separator `;` and `%M3_HOME%\\bin`\n\n\n#### Maven commands\n\nFirst make sure maven is installed by running:\n\n\tmvn -version\n\nMaven can now be used to build the project:\n\n- `mvn compile` to run the test, compile the project, install the dependencies, create the library package.\n- `mvn package` to create the library package (such as a JAR file for example)\n- `mvn test` to use the maven \"surefire\" plugin to run unit test in the `src/test/jave` folder with a matching `*Test`name\n- `mvn install` to add your project's JAR file to your local repository (like a `compile` but making it ready as a dependency to be referenced by another project\n- `mvn clean install` to copy the libraries if the first one fails.\n\n### Getting started\n\nHere is a getting started from the Apache Maven website:\n\n- [Maven getting started in 5 min](http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html)\n- [Maven getting started](http://maven.apache.org/guides/getting-started/index.html)\n\n#### The pom.xml file\n\nWhen using Maven a `pom.xml` file is created to manage the dependencies of the project. Here is a basic example of what it could look like:\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n    \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n    \u003cgroupId\u003egroupId\u003c/groupId\u003e\n    \u003cartifactId\u003eJava_hero\u003c/artifactId\u003e\n\t\u003cpackaging\u003ejar\u003c/packaging\u003e\n    \u003cversion\u003e1.0-SNAPSHOT\u003c/version\u003e\n\n  \u003cbuild\u003e\n        \u003cplugins\u003e\n            \u003cplugin\u003e\n                \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.google.guava\u003c/groupId\u003e\n            \u003cartifactId\u003eguava\u003c/artifactId\u003e\n            \u003cversion\u003e22.0\u003c/version\u003e\n        \u003c/dependency\u003e\n\n        \u003cdependency\u003e\n            \u003cgroupId\u003eorg.apache.commons\u003c/groupId\u003e\n            \u003cartifactId\u003ecommons-lang3\u003c/artifactId\u003e\n            \u003cversion\u003e3.6\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\n\u003c/project\u003e\n\n```\nHere are some [details](https://spring.io/guides/gs/maven/) on all of the shown tags:\n\n- `\u003cmodelVersion\u003e`: POM model version (always 4.0.0).\n- `\u003cgroupId\u003e`: Group or organization that the project belongs to. Often expressed as an inverted domain name.\n- `\u003cartifactId\u003e`: Name to be given to the project’s library artifact (for example, the name of its JAR or WAR file).\n- `\u003cversion\u003e`: Version of the project that is being built.\n- `\u003cpackaging\u003e`: How the project should be packaged (Optional tag). Defaults to \"jar\" for JAR file packaging. Use \"war\" for WAR file packaging.\n- `\u003cdependencies\u003e`: Dependencies to be installed or loaded with the project\n- `\u003cbuild\u003e`: Define what will be built and how.\n\n## Gradle\n\n[Gradle](https://gradle.org/) is an open source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration\n\n### Installation\n\n- [Installation](https://gradle.org/install/)\n- [Install on Windows](http://bryanlor.com/blog/gradle-tutorial-how-install-gradle-windows)\n\n### How to use\n\n- [Gradle User guide](https://docs.gradle.org/4.4/userguide/userguide.html)\n- [Guides](https://gradle.org/guides/)\n\n## IntelliJ\n\nIntelliJ is an IDE developed by [JetBrain](https://www.jetbrains.com/idea/), the community version is free and comes with a lot of pro features (that might be overkill in some cases).\n\n### Getting started with IntelliJ\nFirst you have to create a Java project: File **\u003e** New **\u003e** Project.\nWhen a screen pops up, you need to specify the link to your project SDK. \n\n- You should find the path to the SDK here : `C:\\Program Files (x86)\\Java` with a name such as `jdk1.8.1_02`\n- Or you can use the installed JDK of IntelliJ (Clicking the down arrow and selecting it)\n\nThen you can start your project, creating a class and doing some coding.\nTo compile the code, you will need to hit the `build` button (top right) or `ctrl + F9`. \n\nTo Run it, will have to edit configurations (next to the build button). Click on the arrow and select `Edit Configurations`. \u003c/br\u003e\nA window appear, on the left side there's a dropdown menu (called `Defaults`). Click on it and select `Application`. On the right panel, add a name and the main class you've just created. Press ok to validate. \n\nNow that you have that set up you should see a green arrow next to that field (next to the build button). If you click on it, it will run your project and you'll see on the bottom a split screen with the output (like Netbeans, yeah!).\n\n### Maven on IntelliJ\n\nSo to use [Maven](https://github.com/Sylhare/Java_hero#maven) with IntelliJ, you first need to right click on a project and select **Add framework support ...**.\n\nA new page will show up and you can select *Maven*, it will automatically reformat your code structure to adapt to Maven. A **pom.xml** will be created.\n\n:warning: Sometime IntelliJ push the compiler to v1.5 [#2](https://github.com/Sylhare/Java_hero/issues/2). There is two way to specify the right language for the compiler in the pom.xml file. Either add or modify the already existing `\u003cbuild\u003e` tag in the `\u003cproject\u003e` tag : \n\n```xml\n    \u003cbuild\u003e\n        \u003cplugins\u003e\n            \u003cplugin\u003e\n                \u003cartifactId\u003emaven-compiler-plugin\u003c/artifactId\u003e\n                \u003cconfiguration\u003e\n                    \u003csource\u003e1.8\u003c/source\u003e\n                    \u003ctarget\u003e1.8\u003c/target\u003e\n                \u003c/configuration\u003e\n            \u003c/plugin\u003e\n        \u003c/plugins\u003e\n    \u003c/build\u003e\n```\n\nThe above solution worked great on IntelliJ. You can also can try this solution from [Apache Maven](http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html).\n\n\n### Setting up dependencies, add external libraries\n\nYou can add external libraries to your Java project. Here are two ways of doing in with IntelliJ.\n\n####  with JAR\n\nYou can download the JAR file of the external library and add it to your project. For that you can do go on **File** \u003e **Project Structure** (or `[ALT] + [ctrl] + [shift] + [S]`).\n\nOnce there you can click on the green plus and add the .jar file. (Save the Jar in your place for libraries such as *lib/directory*).\n\nNow you should be all set, you can now import the library:\n\n```java\n//Importing a library\nimport main.java.com.library;\n```\n\n#### with Maven\n\nTo add an external library to your project, just copy and past the `\u003cdependency\u003e` into `\u003cdependencies\u003e` inside `\u003cproject\u003e` of your pom.xml\n\nHere for example for the [Guava](https://github.com/google/guava) library from Google:\n\n```xml\n\u003cproject\u003e\n\t\u003c!-- information about your project --\u003e\n\t\u003cdependencies\u003e\n\t        \u003cdependency\u003e\n\t            \u003cgroupId\u003ecom.google.guava\u003c/groupId\u003e\n\t            \u003cartifactId\u003eguava\u003c/artifactId\u003e\n\t            \u003cversion\u003e22.0\u003c/version\u003e\n\t        \u003c/dependency\u003e\n\t\u003cdependencies\u003e\n\u003c/project\u003e\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylhare%2Fjava","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsylhare%2Fjava","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsylhare%2Fjava/lists"}