Online compilers that will run code that features TextIO?

  • Thread starter Darkmisc
  • Start date
  • #1
Darkmisc
149
21
TL;DR Summary
I've been trying to teach myself Java but sometimes can't get the solutions to online problems to compile (both on Eclipse and online compilers).
Hi everyone

I've been trying to teach myself coding using the free materials from https://math.hws.edu/javanotes/index.html

I've been using online compilers because I got a "Error: Could not find or load main class" message immediately upon installing Eclipse.

The online compilers work for some solutions, but won't run others. https://www.programiz.com/java-programming/online-compiler/ is one such compiler. I've tried a few different ones and it seems they all run into problems when I try compile code that uses
- TextIO
- The following code:
Java:
switch (operator) {
              case '+' -> value = firstNum + secondNum;
              case '-' -> value = firstNum - secondNum;
              case '*' -> value = firstNum * secondNum;
              case '/' -> value = firstNum / secondNum;
              default -> {
                 System.out.println("Unknown operator: " + operator);
                 continue;  // Back to start of loop!
              }
          } // end switch
The compilers sometimes work if I use Scanner instead of TextIO or "case x:" instead of "case x ->", but not every compiler will do this and I don't know why.

Can anyone recommend an online compiler that will run with TextIO and "case x ->" notation?

Thanks
 
Last edited by a moderator:

Answers and Replies

  • #2
Wrichik Basu
Insights Author
Gold Member
2022 Award
2,021
2,152
I've been using online compilers because I got a "Error: Could not find or load main class" message immediately upon installing Eclipse.
Maybe try NetBeans or IntelliJ IDEA?
- The following code:
switch (operator) {
case '+' -> value = firstNum + secondNum;
case '-' -> value = firstNum - secondNum;
case '*' -> value = firstNum * secondNum;
case '/' -> value = firstNum / secondNum;
default -> {
System.out.println("Unknown operator: " + operator);
continue; // Back to start of loop!
}
} // end switch
Switch expressions were introduced in JDK 12. I bet the online compilers you are using are either supporting Java 8 or JDK 11. TextIO is a 3rd-party library that needs to be added to your project.

If you are a beginner, I strongly suggest you install the latest OpenJDK (JDK 19 being the latest at the time of writing), and also install NetBeans. I used NetBeans instead of Eclipse as a beginner, and it has a fairly flat learning curve. In NetBeans, you can also add external libraries. Those online compilers won't be helpful in the long run.

Later, you can switch to the more advanced IntelliJ IDEA from NetBeans.
 
  • Like
Likes Darkmisc and pbuk
  • #3
pbuk
Science Advisor
Homework Helper
Gold Member
4,026
2,360
I've been trying to teach myself coding using the free materials from https://math.hws.edu/javanotes/index.html
Oh my word, why? And how did you track down such an outdated resource? As you have already discovered Programiz I'd suggest sticking with that - compare and contrast (asserting fair use of copyright material):

JavanotesProgramiz
Object-oriented programming (OOP) represents an attempt to make programs more closely model the way people think about and deal with the world. In the older styles of programming, a programmer who is faced with some problem must identify a computing task that needs to be performed in order to solve the problem. Programming then consists of finding a sequence of instructions that will accomplish that task. But at the heart of object-oriented programming, instead of tasks we find objects—entities that have behaviors, that hold information, and that can interact with one another. Programming consists of designing a set of objects that somehow model the problem at hand. Software objects in the program can represent real or abstract entities in the problem domain. This is supposed to make the design of the program more natural and hence easier to get right and easier to understand.Java is an object-oriented programming language. The core concept of the object-oriented approach is to break complex problems into smaller objects.
To some extent, OOP is just a change in point of view. We can think of an object in standard programming terms as nothing more than a set of variables together with some subroutines for manipulating those variables. In fact, it is possible to use object-oriented techniques in any programming language. However, there is a big difference between a language that makes OOP possible and one that actively supports it. An object-oriented programming language such as Java includes a number of features that make it very different from a standard language. In order to make effective use of those features, you have to "orient" your thinking correctly.
An object is any entity that has a state and behavior. For example, a bicycle is an object. It has
  • States: idle, first gear, etc
  • Behaviors: braking, accelerating, etc.
 
  • Like
Likes Wrichik Basu and Darkmisc
  • #4
pbuk
Science Advisor
Homework Helper
Gold Member
4,026
2,360
  • Like
Likes Darkmisc and Wrichik Basu
  • #5
14,166
8,148
I would look to using BlueJ or Processing IDE to learn about Java programming in a beginner friendly way before venturing into Netbeans, Eclipse or other vendor IDE tools.

BlueJ is specifically designed to be a sandbox for Java. processing uses Java in their sketches which follow the setup() and draw() scheme instead of using a main() function scheme.

https://bluej.org/

https://processing.org/

Processing has a fairly large community and mature set of examples to look at where you can really pickup a lot of Java while writing cool graphics sketches. Processing calls programs sketches.
 
  • #6
Wrichik Basu
Insights Author
Gold Member
2022 Award
2,021
2,152
I would look to using BlueJ or Processing IDE to learn about Java programming in a beginner friendly way before venturing into Netbeans, Eclipse or other vendor IDE tools.
I haven't used Processing, but the reason why I dislike BlueJ is, they have no quick way of showing the documentation of functions, they don't provide a list of functions when you type something like obj. From my experience, the list of functions, and the ability to view documentation are a huge resource for a beginner who has no idea about all the functions a class has. In addition, good IDEs will give tips like using StringBuilder or StringBuffer instead of String, or using ArrayList instead of arrays if I am creating new arrays every time I need to append or delete something. BlueJ also doesn't have refactoring, so good luck changing the name of a function in a pretty long program. :eek: The last time I emailed them about this issue (5-6 years back), they said that they had no intention of supporting refactoring.

One positive thing about BlueJ is the colouring scheme, which helps newcomers visualize blocks easily. And that's all, probably.
 
  • #7
14,166
8,148
Yes BlueJ is great for teaching students programming concepts and refactoring doesn’t help with that process as it allows them skip over these suggestions.

Years ago when the personal scientific calculator overtook the sliderule in college, I witnessed the after-effects. Some students doing an electrical experiment concluded that the circuit with the 12v battery was actually generating 12000v.

When asked how they got that answer, they said that’s what the calculator computed and we knew they missed a few decimal points somewhere that would not have happened had they used a sliderule and thought about it more.

One thing in BlueJ’s favor is the class diagrams it makes that visualizes your program.

Processing doesn’t support the dot expansion either unless you use a variant of the IDE that is based on Eclipse. I’m not sure if that still exists with the latest Processing 4 IDE.

EDIT: There is an extension tool for Processing 3 not yet 4 that provides a Java api reference and another that works with Processing 4 that does (if, for, while) … expansion when ctrl-space is pressed after typing the word (if, for, while).
 
Last edited:
  • Like
Likes Darkmisc and Wrichik Basu

Suggested for: Online compilers that will run code that features TextIO?

  • Last Post
Replies
7
Views
153
Replies
7
Views
521
  • Last Post
Replies
5
Views
625
Replies
9
Views
258
  • Last Post
Replies
2
Views
407
Replies
7
Views
1K
Replies
3
Views
128
Replies
18
Views
760
Replies
21
Views
2K
Top