{"id":20102266,"url":"https://github.com/temikfart/java-classloading","last_synced_at":"2025-03-02T17:17:51.873Z","repository":{"id":211937821,"uuid":"721637704","full_name":"temikfart/java-classloading","owner":"temikfart","description":"Here are examples of loading classes and modules using custom class loaders in Java 8 and Java 9+.","archived":false,"fork":false,"pushed_at":"2024-01-24T14:02:45.000Z","size":1535,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T04:29:03.826Z","etag":null,"topics":["classloaders","classpath","guide","habr","java-8","java-9","java-9-modules","module-api","module-path","module-system"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/temikfart.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-11-21T13:21:53.000Z","updated_at":"2024-07-05T20:32:42.000Z","dependencies_parsed_at":"2024-01-24T15:27:25.717Z","dependency_job_id":"7a7e2b49-4426-46a8-ac7a-a4b8d993f130","html_url":"https://github.com/temikfart/java-classloading","commit_stats":null,"previous_names":["temikfart/java-classloading"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/temikfart%2Fjava-classloading","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/temikfart%2Fjava-classloading/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/temikfart%2Fjava-classloading/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/temikfart%2Fjava-classloading/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/temikfart","download_url":"https://codeload.github.com/temikfart/java-classloading/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241541454,"owners_count":19979122,"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":["classloaders","classpath","guide","habr","java-8","java-9","java-9-modules","module-api","module-path","module-system"],"created_at":"2024-11-13T17:29:30.694Z","updated_at":"2025-03-02T17:17:51.593Z","avatar_url":"https://github.com/temikfart.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Java Class Loading examples\n---\nThis repository contains the code for all the examples from [the article on Habr](https://habr.com/ru/companies/isp_ras/articles/788618/).\nEach example comes with its own README.md.\n\nEach example demonstrates how class loaders are associated with `classpath`/`modulepath`. Examples using Java versions 8 and 17 are considered, where the main difference is the modular system that appeared in Java 9.\n\nExamples:\n- Java 8\n    - [Manual Loading](java-8/manual)\n    - [Auto Loading](java-8/auto)\n- Java 17\n    - Manual\n        - One Module\n            - [Java 8 Style](java-17/manual/one-module/java8style)\n            - [Java 17 Style](java-17/manual/one-module/java17style)\n        - Few Modules\n            - [Together](java-17/manual/few-modules/together)\n            - Separately\n                - [No Dependencies](java-17/manual/few-modules/separately/no-deps)\n                - [No Dependencies (hack)](java-17/manual/few-modules/separately/no-deps-hack)\n                - [With Dependencies](java-17/manual/few-modules/separately/with-deps)\n    - Auto\n        - One Module\n            - [Java 8 Style](java-17/auto/one-module/java8style)\n            - [Java 17 Style](java-17/auto/one-module/java17style)\n        - Few Modules\n            - [Together](java-17/auto/few-modules/together)\n\n### Used classes\n---\nEach example uses just a few classes for demonstration purposes. Below are the features of each of them.\n\n#### class `Main`\n---\nA class with a `main` method, in which, depending on the example, either the simplest classes `Cat` or `Dog` are loaded, or instances of the simplest classes are created. At the end of the method, the `talk` method is called on an instance of the simplest class.\n\nBetween instantiation and calling the `talk` method, information about class loaders and/or the name of the modules to which the classes belong is printed.\n\n#### class `CustomClassLoader`\n---\nA custom class loader that almost completely satisfies the [**delegation model**](https://docs.oracle.com/javase/tutorial/ext/basics/load.html), except that it first tries to load the class , and only then delegate to the parent loader.\n\nMethods:\n- `loadClass`:\n    1. First, an attempt is made to find a class among the loaded classes;\n    2. Then an attempt is made to load the class yourself, if it is from the application;\n    3. If the class is not from the application, then the loading is delegated to the ancestor.\n- `findClass`: Loads the bytecode of a class (if found) and defines it as a class.\n\nIf you try to load a class from the `java.*` package, the JVM will throw `java.lang.SecurityException: Prohibited package name: java.*`. To determine that the class is from an application, it checks that [binary name](https://docs.oracle.com/javase/specs/jls/se17/html/jls-13.html#jls-13.1) begins with `ru.ispras`.\n\n#### class `Cat`\n---\nThe simplest class to load with a single `talk` method that prints the word *\"Meow\"* to `stdout`.\n\n#### class `Dog`\n---\nThe simplest class to load with a single `talk` method that prints the word *\"Woof\"* to `stdout`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftemikfart%2Fjava-classloading","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftemikfart%2Fjava-classloading","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftemikfart%2Fjava-classloading/lists"}