Posts by Douglas • 961 points
27 posts
-
9
votes1
answer109
viewsQ: Can Functional Programming hinder the discovery of certain types of bugs?
As I understand it, functional programming (or at least a functional programming style) makes it easy to find and avoid bugs (it’s easy to test pure functions, immutability protects data,…
functional-programmingasked Douglas 961 -
0
votes1
answer265
viewsA: Java - How to access a String vector of a Class in another Class?
The implementation below is very faithful to the code you made, but now it’s working, I commented the problems I saw: import java.io.BufferedReader; import java.io.FileReader; import…
-
1
votes1
answer1461
viewsA: How to resolve 'Error: Javafx Runtime components not found' java 11 ( linux )
There is a step-by-step Javafx for this, and there it shows when this error occurs and how to solve: "Getting Started with Javafx 12" (in this case, it is updated to version 12 of Javafx, but I did…
-
1
votes0
answers182
viewsQ: Unit Testing - How to test a Try-with-Resources?
I would like to know the best way - or the standard way - to test a Try-with-Resources; with Test Cases for each of the Exceptions that can be launched (simulating the release of each of these…
-
2
votes2
answers198
viewsA: Forcing backreference in regex
My answer complements the response from Paul R. F. Amorim, showing how what he said is applied to the Regex Expression posed in the question. Note that in a Regex you create the Groups in…
-
3
votes3
answers1162
viewsA: create objects dynamically
It seems to me unnecessary an Enum to do this, you can simply create two methods that will be "Factories" of Pagamento: Obs.:It is better to use Bigdecimal than double for monetary values. public…
-
3
votes2
answers1864
viewsQ: Junit 5 - How to run a test method only if another test method passes?
It would be something like that: @Test void metodo1() { assertTrue(...); } @Test void metodo2() { //Deve ser executado após método1(), e SOMENTE SE metodo1() passou! assertTrue(...); } I need to do…
-
2
votes1
answer61
viewsQ: What’s wrong with these hash algorithms?
I’ve researched several hash algorithms, and found some examples on Soen, but they’re returning different hashes to the same file: import java.io.File; import java.io.FileInputStream; import…
-
0
votes0
answers116
viewsQ: How to show the progress of a Progressbar in S.O.’s Taskbar?
I’m using a javafx.scene.control.ProgressBar and a javafx.scene.control.ProgressIndicator, and would like to know if it is possible (and how to do) to be shown the progress in the Taskbar of the…
-
4
votes1
answer59
viewsA: Optical illusion parallel lines
I added a bit of code that basically checks which rectangle line is being created in the current loop iteration and sets the appropriate increment in the x-position (each row has its own increment…
-
1
votes2
answers155
viewsA: How not to lose the decimals when doing "longProperty1.divide(longProperty2)"?
I got a good answer on Soen here (link in English), below is a translation/adaptation of it: The methods provided by LongProperty (and by others NumberExpression) as divide(...) are only methods of…
-
1
votes2
answers155
viewsQ: How not to lose the decimals when doing "longProperty1.divide(longProperty2)"?
What I want to do is very simple, I just don’t know how to "do it right" in Javafx: I have two Longproperty (num1 and num2) and a Doubleproperty (resultado), where this Doubleproperty resultado must…
-
2
votes0
answers60
viewsQ: What is marking an item as "Landmark" in the Eclipse IDE ("Mark as Landmark")?
I’m studying the Mylyn of Eclipse IDE and came across the option "Mark as Landmark" which appears available for some items in the Package Explorer, and I got a few questions about what it’s for,…
-
11
votes2
answers6600
viewsA: What is and how to implement a Java Listener?
The Observer Standard goes far beyond Java and Swing As you have seen, "Listener" and "Observer" are different names for the same pattern, and, it can be used for many things other than use in…
-
4
votes1
answer1186
viewsQ: How to check if a File can be created in a Folder before trying to create it in it?
My program allows user to define a Folder, and later the program will create a New File in this Folder. However, the program is not able to create a File in any Folder, for example: Creates New File…
-
1
votes1
answer1014
viewsA: incompatible types cannot be converted to
The problem is the incompatibility of Types, as Exception itself is saying: incompatible types: deodorant. Deodorant cannot be converted to deodorant.Deodorant Let’s analyze why this occurs:…
-
7
votes2
answers227
viewsQ: How to convert byte to Boolean[8] and convert back?
I need to record some booleans in a File, and then retrieve them. I can record and read one or more bytes with the Classes java.io.FileInputStream and java.io.FileOutputStream, so I need to convert…
-
0
votes1
answer50
views -
0
votes1
answer54
views -
7
votes1
answer311
viewsQ: When to use Supertype or Subtype when returning the method?
Suppose I have a method called "meuMetodo()" that returns an Object of Type ArrayList<String>, i can make this method declare that returns more concrete or more abstract types: public…
-
0
votes1
answer623
viewsA: Add values from an array
The code below solves your problem: import java.util.Scanner; public class Rotas { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[][] km = {{0, 20, 32, 45, 85,…
-
-2
votes3
answers722
viewsA: Initialize private fields in the declaration or constructor?
Advantage of Initializing in Declaration As has been said, "Initializing in the Declaration" is not really what happens, but I will use that term in this answer. If you initialize in the Declaration…
-
3
votes1
answer921
viewsA: Calculator problem in android studio
There are already questions and answers that can help you with this, because there are already libraries able to receive a String like "(2*6)+3" and return the result of the expression. Maybe the…
-
0
votes1
answer261
viewsA: Separate listings of an object for each object of the type of another class
Graphical Interface In the Graphical Interface you can make a Client table, with columns like "Customer Name", "Order Quantity", etc. That is, each Row with a different Customer. By clicking on a…
-
1
votes1
answer104
viewsA: Correct way to update an object property
If you want to eliminate the line "String cargo = funcionarioModel.getCargo();" you can do so: public void atualizar(FuncionarioModel funcionarioModel) throws NegocioException { if…
-
4
votes1
answer3368
viewsA: Implement Runnable or Thread Extension?
According to the book "Use Your Head! Java" you should implement Runnable, because when you extend Thread you are saying that your Class is a new type of Thread, while it is just a Task thread. By…
-
3
votes1
answer442
viewsA: What is the difference between a state (State Machine) and a class?
State (of a State Machine): A State can simply be an Instance of a Class that implements an Interface that we can call 'State'. You can have several classes implementing the 'State' interface, such…