{"id":13471556,"url":"https://github.com/IanDarwin/javasrc","last_synced_at":"2025-03-26T13:31:12.952Z","repository":{"id":11136894,"uuid":"13501496","full_name":"IanDarwin/javasrc","owner":"IanDarwin","description":"Ian's Collected code examples from the O'Reilly Java Cookbook \u0026 elsewhere","archived":false,"fork":false,"pushed_at":"2024-10-21T19:25:16.000Z","size":55243,"stargazers_count":244,"open_issues_count":0,"forks_count":152,"subscribers_count":35,"default_branch":"main","last_synced_at":"2024-10-30T02:59:46.438Z","etag":null,"topics":["basics","environment","java"],"latest_commit_sha":null,"homepage":"http://javacook.darwinsys.com/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/IanDarwin.png","metadata":{"files":{"readme":"README.adoc","changelog":null,"contributing":"CONTRIBUTING.adoc","funding":null,"license":"LICENSE.txt","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":"2013-10-11T14:50:06.000Z","updated_at":"2024-10-21T19:25:21.000Z","dependencies_parsed_at":"2023-01-11T20:15:58.229Z","dependency_job_id":"e94a0616-9b06-4635-bb8b-c0da2ae263d0","html_url":"https://github.com/IanDarwin/javasrc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanDarwin%2Fjavasrc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanDarwin%2Fjavasrc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanDarwin%2Fjavasrc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IanDarwin%2Fjavasrc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IanDarwin","download_url":"https://codeload.github.com/IanDarwin/javasrc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245662843,"owners_count":20652095,"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":["basics","environment","java"],"created_at":"2024-07-31T16:00:46.604Z","updated_at":"2025-03-26T13:31:12.915Z","avatar_url":"https://github.com/IanDarwin.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":":LTS:  21\n:LATEST:  22\n= JavaCook Source Files (javasrc)\n\nThis is my assorted collection of (you guessed it) Java source.\nIt remains focused on building with bleeding-edge Java (currently {LATEST}),\nhttps://maven.apache.org/[Maven],\nand the\nhttps://jetbrains.com/idea[IntelliJ IDEA] IDE.\nSome modules may still build with the\nhttps://eclipse.org/[Eclipse] IDE;\nfor those that don't, pull requests welcome.\n\nAs of 2024-04-14, this does not work on Eclipse,\neven with the \"Java 22 updater\"\n(https://marketplace.eclipse.org/content/java-22-support-eclipse-2024-03-431[]).\nTheir compiler\nfails to realize that \"classless main\" doesn't need (and isn't allowed to have)\na package statement.\nThis seems to be an Eclipse bug, and fails even with the source attribute set to\n22 and using a Java 22 JDK with \"Preview\" checked.\nFurther, their library appears to be missing at least two methods in the FFI `Arena` class,\ncausing `CallCFromJava` to fail to compile.\n\n== Maintenace Note\n\nDon't delete files without checking if they're still used in the Java Cookbook repo.\n\n== Origin\n\nThese files began as my personal collection of Java examples, back when Java was first unleashed on a \npublic (well, developers) accustomed to having to choose between portability and performance.\nI turned what I'd learned from working with Java into \na course for https://learningtree.com/[Learning Tree] and \nthen the first edition of the https://javacook.darwinsys.com/[Java Cookbook].\nNow in its fourth or fifth edition, this book consists of several hundred how-to \"recipes\"\neach discussing a particular problem that devs have to code, how to solve it, and \nillustrated with one or more code examples. \n\nThe Contents of the Fourth Edition looks like this:\n\n// Uses * not + because of what's at the end of this list.\n// Updated for JCB 4E; will need changes for 5E.\n* 1 Getting Started: Compiling and Running Java\n* 2 Interacting with the Environment\n* 3 String and Things\n* 4 Pattern Matching with Regular Expressions\n* 5 Numbers\n* 6 Dates and Times\n* 7 Structuring Data with Java\n* 8 Object-oriented Techniques\n* 9 Functional Programming\n* 10 Input and Output\n* 11 Data Science and R\n* 12 Networking: Clients \n* 13 Networking: Server-Side Java\n* 14 Processing JSON Data\n* 15 Packages and Packaging\n* 16 Threaded Java\n* 17 Reflection, or \"A Class Named Class\"\n* 18 Using Java with Other Languages\n* Afterword\n* Appendix: Java Then and Now\n\n== Technical Issues Compiling This Code\n\nIf you want to compile everything, *the minimum Java release is currently {LATEST}*.\nYou can compile for Java 17 by checking out the java-17 branch, but it's not actively maintained.\nOr you could just add exclusions for the few files that use newer features.\nFor releases before that, I don't have branches or tags, but if somebody wants to 'git bisect'\n(maybe starting around commit `628efafe`) and tell me what works for 11,\nI shall be happy to add a tag.\n\nSome files use Java \"Preview\" features, which work if you're compiling with the Maven POM file provided.\nIf not, you'll probably need the argument `--enable-preview`\n(and maybe `--source-{LATEST}`) to get these to compile.\n\nAs mentioned above, a goodly number of these files are featured in my O'Reilly\nhttps://javacook.darwinsys.com/[Java Cookbook].\nTo avoid copy-and-paste errors (or, worse, retyping!),\nI use a script (`copyCodeSamples`) to pre-format these for inclusion in the O'Reilly publishing toolchain;\nthese source code files will have `// tag::foo[]` and `// end::foo[]` comments to mark sections for\nmechanical inclusion into the book, and `// \u003cn\u003e` comments to refer to the code in the text.\nThese are all just comments as far as Java tooling is concerned,\nand can be completely ignored by people looking at the source code normally.\nN.B. Not all files with these comments necessarily appear in the book;\nfiles are included from the manuscript using \nhttps://asciidoctor.org[asciidoctor]'s `include` mechanism and,\nwhen a code sample gets dropped from the book, I have no motivation\nto edit the tags out of the code, in case I use it elsewhere.\n\n== Structured as Maven Modules\n\nThis repo consists of about a dozen Maven modules (aka subdirectories\n:-)).  The reason for this is discussed below (TL;DR: Dependencies).\nThe layout is as follows:\n\n* main - everything that isn't in one of the others\n* desktop - GUI/Graphics, JavaFX, comm devices, etc.\n* ee - Jakarta EE (Java EE, J2EE) stuff\n* graal - Only works with graal vm\n* jlink - Not ready yet?\n* json - JSON parsing and formatting with various APIs\n* lombokdemo - Project Lombok - not working ATM\n* Rdemo-web - NOT a maven module - some R demos\n* restdemo - REST\n* spark - Apache SPARK\n* unsafe - com.sun.Unsafe\n* testing - code that shows more details on testing (other modules have normal unit tests)\n* testing-spock - testing with the Spock framework\n* unsafe - you shouldn't want to know\n* xml - XML parsing and formatting with various APIs\n* sidebyside - NOT a maven module - some non-Java versions of demos\n\nA few modules are disabled because I don't have time to fix them now.\n\nPrior to the revision (late 2019/early 2020) for the Fourth Edition of _Java Cookbook_, \nthis repo was one single module with no sub-modules. This became difficult\nto manage and to use, since, to compile anything, a user would have to wait for Maven\nto download all the dependencies and their dependencies and theirs... \nThat revision seemed like a good time to split the whole shebang into smaller pieces.\nEach module has its own POM file, Maven structure, etc.\n\nA main reason was that the CLASSPATH was becoming unmanageable.\nNot to mention MODULEPATH, and the time it takes to build the whole thing.\nNow that it's done this way, you can choose to just build one module\nor another, _without having Maven download 3/4 of the Internet_ for\ndependencies. Just `cd` into one of the module directories and\ninvoke `mvn compile` there. Or you can do them all by invoking `mvn` in\nthe top-level directory. \n\nUseful mvn targets include `compile` and `test`.\nDo not use `mvn package` as the jar files won't be useful on their own.\n\n=== I broke it (but it's easy to fix)\n\nUnfortunately for those who already had the old all-in-one _javasrc_ project from before 2020\nchecked out, and an Eclipse project created in that directory,\nIf you *do not have any changes worth keeping*, then just delete\nthe entire project and start over.\nIf you perform the `git clone` inside Eclipse, there's a \"Create projects from import\" checkbox\nthat will make all the projects for you. If not, clone the repot and go to the step \"Back in Eclipse\" below.\n\nIf you *do have changes you want to keep*, then do the following:\n\n* In Eclipse, delete the `javasrc` project (do NOT check 'delete contents on disk'!);\n* Delete the old target folder (*only*): {`rm -r` or `del/s`} __javasrc/target__;\n* Do a \"git pull\" to rearrange the project and get the extra pom files;\n* Deal with any files that didn't get moved,e.g., because of conflicts;\n* Back in Eclipse, `File-\u003eNew Java Project-\u003ebrowse to (but not into) workspace/javasrc/main`.\nSet project name to `javasrc-main`. \nIf asked to upgrade the JDK release, say OK.\nIf asked to create a module-info, *click Do Not Create*.\nClick `OK/Finish`.\n* You may want to create some or all of the other projects such as xml, jlink, spark, unsafe, ...\nDo this same way as previous step: File-\u003enew Java project etc.\nRecommmended names are javasrc-xml, javasrc-unsafe, etc.\n\nIt's easier if you use IntelliJ: just open the module you want via ++Open Project++.\nBut IntelliJ flubs out if you have even one file in a project that won't compile.\n\nThe older 'javasrcee' repository was originally formed by splitting\nit off from this repository, years ago. Now, with this modularization,\nit has been merged back in, as the `ee` module.\n\n= No module-inf\nThere are no module-info.java files in most of the subdirectories\nbecause this is not meant to\nbe built and used as a library or even as a cohesive software base.\nA few that need them for imports \u0026c have them.\n\n== Notes on Individual Modules\n\ntesting::\n\tWorks under \"mvn test\". Compiles as an Eclipse project, but can't run there due to\n\ta Junit 5 loading conflict (pull requests welcome on this one, thanks).\n\n== Building\n\n* You MUST HAVE a current release of Java (see notes at beginning) to successfully compile this whole package.\nSorry if you are on some relic platform that doesn't have current Java.\nEven https://openbsd.org[OpenBSD] has Java 21 (Thanks Kurt!).\nAlso sorry if your organization is stuck on an ancient Java due to application server issues.\n\n* I am using Eclipse for most of my development, and Maven for building, and Jenkins\nfor automated building. The Ant scripts have been removed (except for a few in the ee module\nunder _ejb2_ and _rmi_; the few that remain\nwill someday get deleted, or converted to Maven exec:java configurations).\n\n* Building with Maven 3.x works and tests pass.\n\n* Building with Eclipse tested with Eclipse 4.x; MUST HAVE \"m2e\" (free in the Eclipse Marketplace)\nCompiles and tests pass.\n\n* Building with other platforms? Good luck, but let me know if it works.\n\nIan Darwin\n\nJava Cookbook author\n\nhttps://darwinsys.com/contact\n\n== Misc. ToDo\n\nCONSIDER Moving all \"compilation error\" methods in $js into \"dontcompile/\"\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIanDarwin%2Fjavasrc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FIanDarwin%2Fjavasrc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FIanDarwin%2Fjavasrc/lists"}