Ask coding questions

← Back to all posts
Java and C++ REPLs

Ok, I'm not sure if this is just me or not... But pretty much everything when it comes to Java and C++ REPLs is broken. The little yellow greater than sign that appears below the version of the language doesn't appear. Everything for input is a rectangle, when the area doesn't have focus it is just an outline, when it does it's completely white. Also, when the program ends, the greater than sign still doesn't appear, the cursor doesn't change. Also, (this is the weirdest), on input when I hit arrow keys, something strange happens. For up arrow key: ^[[A, down arrow key: ^[[B, for right arrow key: ^[[C, for left arrow key: ^[[D. If someone could fix this it would be great, thanks!


c++ and Java are pretty old and come from a time where no languages could execute code in the shell. python is able to do that because it is a scripting language and it is build into the language itself. If you want a shell to type in commands to execute, compile, etc. you can right click anywhere over the code, click on command palette, then search and click on "Open Shell" and then under the main console a terminal shell will open. In simpler terms c++ and java are extensions of other languages that are older than themselves. c++ is an extension of c and java is an extension of c++. Java and c++ dont support any kind of interface by default and it needs to be implemented/imported with extra code ex: "#include<iostream>" and "import java.util.Scanner;". to have an interactive mode like in python for java and c++ you would need to download an IDE that has such a feature or get a library that implements it such as JShell for java. Also with java(idk about c++) the java run environment only runs upon compiling and executing, so inputting code directly into the console would be very inefficient as the repl would have to start the runtime enviroment, compile, cache memmory, and execute individual lines of code instead of entire files. as for the "^[[A" input for the arrow keys, that occurs because the console takes direct byte input. in java and c++ it is just a regular input/output stream so it only uses bytes. Every key on your keyboard has an numerical value ex: when you press tab your keyboard outputs a char with the ascii value of 9. if you want to visually represent 9 as a char it would be '\t' but you don't see this elsewhere because your devices OS processes that char and recognizes that it has function. Lastly as a quick tip, if you want to paste something into the console or terminal shell you have to right click instead of ctrl+c or ctrl+v because those are also their own chars.


I'm a teaching assistant for a beginning programming class using C++, and when I heard they were using Replit as an IDE, I thought "Great! We've got a REPL; that'll make teaching much easier." But no, apparently we do NOT have a REPL (i.e. a read-evaluate-print loop) for C++, only for Python and Ruby and a few other languages. Is that correct? Is there any likelihood of Replit supporting a read-eval-print loop for C++ in the future? Something like the CodePad feature in BlueJ?

theangryepicbanana has recently released their xterm console, which works differently from the old console. Maybe there will be an option at some point to change this.