Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 145549

Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.

2 votes

Practicing to learn java through the ecommerce pack app

Without knowing what your program's requirements are, I can only comment on general aspects. It looks like you're a programming beginner. Having a program do something useful is an achievement in itse …
Ralf Kleberhoff's user avatar
4 votes

Bi directional full relation between classes + small working tasks

Your class structure is seriously flawed. How would you describe your relationship to your grandmother? you: Newborn instance, with mother referring to your mother. mother: Mother instance, with a re …
Ralf Kleberhoff's user avatar
2 votes
Accepted

Architecture and error handling in simple java program

But maybe, in some future Java version, a class named FileProcessor gets included into the java.io package. Then the confusion starts: does FileProcessor mean your class or the one from java.io? …
Ralf Kleberhoff's user avatar
5 votes

leet code calculator II code

One additional remark on validate(). You have three output cases: invalid number operator Instead of encoding them as integers (which is not a natural natural choice, as you can't meaningfully add, …
Ralf Kleberhoff's user avatar
2 votes

Computing quantity-based discounts

One additional suggestion regarding the .95 constant: In sales, it's more natural to express the discount percents instead of the factor private static final double QUANTITY_DISCOUNT_PERCENT = 5.0; pr …
Ralf Kleberhoff's user avatar
10 votes

Extending class vector in java

For this reason, I'd recommend not to extend Vector, but to keep your class independent from the Java Collections framework. …
Ralf Kleberhoff's user avatar
3 votes

JAVA OOP concept issue

The Java OOP system does the switch for you. The evaluation of an expression happens where it should happen, in the expression's own class, and you can eliminate the main evaluate() method. …
Ralf Kleberhoff's user avatar
3 votes
Accepted

StringBuilder replacing specific characters

It's two consecutive ranges that you want to get replaced with *. So, I'd do two loops like: for (int i = 1; i < mp-1; i++) { sb.setCharAt(i, '*'); } for (int i = mp+2; i < mp+dp- …
Ralf Kleberhoff's user avatar
4 votes

Solving hard 3rd-grade math

The main performance problem of your code is that you check for duplicate digits only in the innermost loop, although a collision between e.g. a and b can be detected already in the second loop. This …
Ralf Kleberhoff's user avatar
4 votes

Calculating the Factorial of a number

Maybe, in Java 20 or so, they introduce a class java.util.concurrent.Factorial (contrived example), and then you have a name collision with one of your classes. …
Ralf Kleberhoff's user avatar
3 votes

Grade Statistics

Package Name Java code should be placed into a package with a name that avoids collisions with other developers. … In 20+ years of Java development, I rarely ever had to look into the Java source code, the Javadocs explained all the pre-existing Java classes and methods well enough. …
Ralf Kleberhoff's user avatar
3 votes

Concat two strings by slicing them with same length

Package Java code should avoid the unnamed package, but instead be placed into a unique package, one that most prabably never collides with any other Java code. … Typical Java style is to have it at the end of the same line. Your indentation is inconsistent. Most of the time, it's 4 spaces, but sometimes 8. Typical style is 4 spaces. …
Ralf Kleberhoff's user avatar
2 votes

A Union Data Type

developers expect to see (and thus gives the best readability in the Java community), and what your IDE would typically produce with its auto-formatting. … Typical Java generic methods are designed such that the type parameters can be omitted, as the compiler can deduce them from the method arguments. …
Ralf Kleberhoff's user avatar
3 votes

Temperature Scale Converter in Java (for 8 scales)

With Java streams, I very often see this style of method chaining, as if it were mandatory to do all streams operations in one long chain of method calls. Of course, this isn't true. … inputValuesStream .map(toKelvin) .map(fromKelvin); outputValuesStream.forEach(System.out::println); And, to even further improve readability, you might want to replace var with the proper Java
Ralf Kleberhoff's user avatar
3 votes

CSES Number Spiral Java TLE

If you want to produce reliable code that will also work with future Java versions (where there might be more classes in the surprise package), maybe in 5 or 10 years, it's better to replace this wildcard … import with the explicit ones that you really need: import java.io.InputStreamReader; import java.io.BufferedReader; import java.io.IOException; (That's a rule coming from 20+ years of working with Java
Ralf Kleberhoff's user avatar

1
2 3 4 5 6
15 30 50 per page