Is it possible to create an in-game code editor?

For example would it be possible to create something where you walk up to some sort of computer terminal and not only edit but also run code written in either Java or C++?

Not sure where one would even begin with that.

You would either need to write an emulator or simulator. It depends if you need a real full Java or C++ language support or just a partial simulation of that.

Would it be any easier with C++? I would need the full language features, similar to what one would expect with an online IDE.

Probably much easier to use an actual online IDE shown via an ingame web browser.

Possible, yes. Practical, no. There are kinda two elements to what you are trying to achieve, the user interface for typing in and such and a compiler which does something useful with the code when its ready to be run. The IDE is totally doable, the compiler would take a level of understanding that is probably not worth the effort. Best solution, build a user interface that invokes an existing compiler but be warned this could create licensing issues.

If you are capable with C++ there is some advice to take advantage of the fact that UE4 is built on C++. From the forums:

This almost worked except in game web browser only seems to work when displayed on the view port. It’s possible to display it on a object like a monitor or TV screen but then there it doesn’t register any mouse/keyboard input. Seems like this has been a problem since 4.15.

You can do this with Unreal.JS and the Webbrowser plugin. Use a code editor library like CodeMirror or Ace as your editor in the Webbrowser plugin. Now you can run Javascript code (or Typescript or any number of other languages that transpile to javascript) in your game with an in-game editor.

Lucky you, that seems trivial to fix compared to implementing it all from scratch.