Skip to content

Conversation

@Seth0x41
Copy link
Contributor

@Seth0x41 Seth0x41 commented Apr 10, 2025

What type of PR is this? (check all applicable)

  • ✨ Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation Update
  • 🎨 Style
  • ♻️ Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • πŸ“¦ Chore (Release)
  • ⏩ Revert
  • 🌐 Internationalization / Translation

Description

Supporting Java language using DoppioJVM

This PR adds support for the Java language in LiveCodes using DoppioJVM and BrowserFS. It enables users to write, compile, and run Java code directly in the browser. Key additions include:

  • Java compiler and runtime with DoppioJVM.
  • Web Worker for efficient compilation and execution.
  • Optimizing DoppioJVM's files size.
  • Optimization to skip compilation if the code is unchanged.
  • A javaStarter template with an interactive counter example.
  • i18n support for the Java template title.

Related Tickets & Documents

Closes #780

Added tests?

  • πŸ‘ yes
  • πŸ™… no, because they aren't needed
  • πŸ™‹ no, because I need help

This PR adds a new language (Java) to LiveCodes, but no automated tests were added because the language runtime (DoppioJVM) and virtual file system (BrowserFS) are third-party libraries that are already tested. The functionality was manually tested using the javaStarter template. If tests are needed (e.g., for the Web Worker or UI integration), I can add them with guidance.

Added to documentations?

  • πŸ““ docs (./docs)
  • πŸ“• storybook (./storybook)
  • πŸ“œ README.md
  • πŸ™… no documentation needed

[optional] Are there any post-deployment tasks we need to perform?

[optional] What gif best describes this PR or how it makes you feel?

@netlify
Copy link

netlify bot commented Apr 10, 2025

βœ… Deploy Preview for livecodes ready!

Name Link
πŸ”¨ Latest commit 4b2bf6f
πŸ” Latest deploy log https://app.netlify.com/sites/livecodes/deploys/67fa879eb8c6dd0008e43248
😎 Deploy Preview https://deploy-preview-788--livecodes.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@hatemhosny
Copy link
Collaborator

Thank you @Seth0x41
That is truly great work.

I have added some edits, mostly organizational for consistency.
The most notable changes:

  • added Java prettier plugin for code formatting
  • added codemirror language support for java (monaco & codejar already support java out-of-the-box)
  • fixed handling translation
  • changed compiler option liveReload to true. This avoids full page reload with every code change, leading to the need to re-download and initialize the environment. Instead, the code is sent to the page to run it in the same environment.
  • removed extra console logs to keep the output cleaner.
  • refactored initializing FS. Previously it checked if initialization was complete while it was still initializing, so files were downloaded twice.

Do we need this file? public/assets/lang-java-worker.js

Please review the changes and let me know what you think.
Thank you very much. I really appreciate your effort.

@Seth0x41
Copy link
Contributor Author

Hi @hatemhosny,
Thanks a lot for these changes! Actually, I had noticed an issue like the FS initialization and already fixed it on my side, but I was digging into the reloading issue and was planning to ask you about it today, looks like you beat me to it πŸ˜„
No, we don’t need public/assets/lang-java-worker.js], sorry about that, I forgot to delete it while working.
I think everything is good now.
Thanks so much for this experience, and if I optimize anything later, I’ll let you know.
All the best!

@hatemhosny
Copy link
Collaborator

hatemhosny commented Apr 12, 2025

Thank you @Seth0x41

I have added docs for Java: https://deploy-preview-788--livecodes.netlify.app/docs/languages/java

It covers the live reload vs full reload. It also covers helper methods & properties that allow communication between Java & JavaScript in the page.

Please review and let me know if you have any comments or additions.

@Seth0x41
Copy link
Contributor Author

Excellent work, @hatemhosny
I just have one comment, I think we need to change the demo in the Usage section, It's currently printing:

WARN: Warn message  
ERROR: Error message

and this might be confusing, especially since it's printed right after the initialization, so someone might mistake it for a compiler error (I was one of them πŸ˜„).
If you don’t have any alternatives, we could use this snippet from The Algorithms instead:

// from https://github.com/TheAlgorithms/Java/blob/master/src/main/java/com/thealgorithms/searches/BinarySearch.java

public class BinarySearchSnippet {

  /**
   * Search an item with binarySearch algorithm.
   *
   * @param arr sorted array to search
   * @param item an item to search
   * @return if item is found, return the index position of the array item otherwise return -1
   */

  public static int binarySearch(int[] arr, int left, int right, int item) {
    if (right >= left) {
      int mid = left + (right - left) / 2;
      if (arr[mid] == item) {
        return mid;
      }

      if (arr[mid] > item) {
        return binarySearch(arr, left, mid - 1, item);
      }

      return binarySearch(arr, mid + 1, right, item);
    }
    return -1;
  }

  public static void main(String[] args) {
    int[] sortedArray = {1, 3, 5, 7, 9, 11, 13, 15};
    int itemToSearch = 7;

    int result = binarySearch(sortedArray, 0, sortedArray.length - 1, itemToSearch);

    if (result == -1) {
      System.out.println("Result: Item not found in the array.");
    } else {
      System.out.println("Result: Item found at index -> " + result);
    }
  }
}

@hatemhosny
Copy link
Collaborator

Good suggestion πŸ˜„
I will do that πŸ‘

Thank you.

@sonarqubecloud
Copy link

@hatemhosny hatemhosny merged commit a804500 into live-codes:develop Apr 12, 2025
15 checks passed
@livecodes-ci
Copy link
Contributor

livecodes-ci bot commented Apr 12, 2025

i18n Actions

Source PR has been merged into the default branch.

Maintainers can comment .i18n-update-push to trigger the i18n update workflow and push the changes to Lokalise.

@hatemhosny
Copy link
Collaborator

Thank you @Seth0x41
This is merged now. It should be available in the next release isA.
Meanwhile you can use it on the development build: https://dev.livecodes.io/

It would be great if we can later on upgrade the Java version.

Very grateful ❀️
Looking forward for your next contribution.

@hatemhosny
Copy link
Collaborator

.i18n-update-push

@livecodes-ci
Copy link
Contributor

livecodes-ci bot commented Apr 12, 2025

i18n Actions: .i18n-update-push

Localization updated and pushed to Lokalise.

Name Description
New Branch for i18n i18n/Seth0x41/feature-java-support
Last Commit SHA a804500

Maintainers can comment .i18n-update-pull after translation is done to trigger the i18n pull workflow and pull the changes back to Github.

@hatemhosny
Copy link
Collaborator

.i18n-update-pull

@livecodes-ci
Copy link
Contributor

livecodes-ci bot commented Apr 12, 2025

i18n Actions: .i18n-update-pull

Localization pulled from Lokalise.

Name Description
i18n Branch i18n/Seth0x41/feature-java-support
Last Commit SHA 019e001
i18n PR #794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: support Java

2 participants