Posts by utluiz • 72,075 points
957 posts
-
8
votes1
answer109
viewsA: Can Functional Programming hinder the discovery of certain types of bugs?
TL;DR The case in question in that posting involved a relatively complex functional code base, written in Java, and the question of Accessibility from a developer who was unfamiliar with her so that…
functional-programminganswered utluiz 72,075 -
6
votes2
answers4119
viewsA: Difference between DTO and Viewmodel?
TL;DR Use DTO to model the API of your system or component (backend), i.e., how the "outside world" views the data model. Use Viewmodel to model the data exposed in the user interface (frontend).…
-
11
votes6
answers4346
viewsA: What is the difference between attribute and field in the classes?
TL;DR The other answers are interesting in how they unravel the different uses of terms attribute, field and property. They are useful for reflection. In specific contexts, paradigms or technologies…
-
5
votes3
answers1162
viewsA: create objects dynamically
Goal I understand that the purpose of the question would be how to design an API to facilitate extension and maintenance. Principles and reservations A good approach would be to adopt SOLID…
-
2
votes1
answer78
viewsA: How do you force threads to perform certain functions?
This is a common multithreading problem. Basically you’re sharing a ArrayList or similar structure for the various threads without any control mechanism or synchronization, thus violating the…
-
2
votes2
answers4588
viewsA: define environment variable in application.properties
The official documentation on configuration outsourcing Spring Boot has all the details on this. First of all, parameterizing everything regarding external access to your program is good practice in…
-
6
votes2
answers237
viewsA: Is it correct to adopt a design specification for an entire project?
TL;DR In general terms, yes. And not just for one project, but for the entire family of projects if possible. Practical example Let’s take as an example the newly launched design language of…
-
1
votes1
answer139
viewsA: Configure orphanRemoval=true in Generate Entities of Table - JPA Tools - Eclipse
The only direct reference to such an option which I found is from many years ago and basically it was said that it was not supported and there were no plans for this. The reason, I believe, is…
-
7
votes2
answers1329
viewsA: JAVA: What is the difference between Outputstream and getOutputStream()?
In addition to Victor’s response, which correctly emphasizes the difference between type (class OutputStream) and the method of access to the object of that type (getOutputStream), I think it’s…
-
1
votes2
answers155
viewsA: How not to lose the decimals when doing "longProperty1.divide(longProperty2)"?
I have honestly never used this Java FX API, but I have experienced the same "problem" in several different Apis and languages. Basically, what seems to occur is that when you work with whole types,…
-
4
votes1
answer553
viewsA: How do I use Atlassian Connect to get Jira data and generate a JSON?
Atlassian Connect allows you to create extensions (integrations or plugins, depending on how you prefer to call) and is not necessary if you just want to make some requests for endpoints jira. As…
-
2
votes1
answer64
viewsA: Filter in a project that consists of several projects and that are executed in different ports (Spring Boot)
Splitting an application into smaller ones is part of the concept of Microservices, but that’s not all. There are several definitions, but one important is that each microservice should reflect a…
-
3
votes2
answers185
views -
0
votes2
answers325
viewsA: How to verify which result will appear more often in a chronological sum of an established sequence?
If understood, what you want is to make the combination of all numbers in the list with themselves, generating a kind of sum matrix, where each element is the sum of two numbers in the original list…
-
11
votes3
answers478
viewsA: Can Garbage Collector language be used for games?
Specifically for Java, there are two items I would highlight on the subject: First, the Java GC is not a mystery. In fact, there are more than one and each with different configurations that can…
-
2
votes1
answer142
viewsA: Global control for Executorservice
If the program has several different interactions with threads, it makes sense to center and encapsulate this functionality in a specialized class. On the name, I would avoid anything named "global"…
-
1
votes2
answers108
viewsA: Is there a Pattern design that can help with this problem?
Modeling of the Code From a code point of view, the problem sounds exactly like the Strategy Pattern. Example: abstract class CalculoHoras { int calcularHoras(int mes) { List<Servico>…
-
0
votes1
answer252
viewsA: Working with Generics
Using more generic types Here, you could use K and V as key and value types respectively: public class SortedMap<K, V> implements Comparable<K> { public static class Pair { Object key,…
-
2
votes1
answer66
viewsA: What is the java class stack growth policy?
Stack The class java.util.Stack stretches java.util.Vector, which will define much of its functionality. Vector allows specifying in its constructor both the initial capacity and the increment of…
-
1
votes1
answer52
viewsA: What happens after Wait synchronization?
Yes, since objeto == objeto. A common problem, especially in complex systems, is that at some point you end up having duplicate instances of objects that should be Singleton or, on the contrary,…
-
3
votes3
answers404
views -
8
votes2
answers5722
viewsA: What is the difference between Wait() and Sleep()?
Sleep Thread.sleep - or also TimeUnit.sleep - causes the thread current stop running for a predetermined time interval. Wait Object.wait also causes the current thread to stop running, but without a…
-
0
votes1
answer86
viewsA: Character difference enconding Charset Difference using JPA but not with Prepared statement
Identifying coding problems in a Java web application There are several hypotheses that can only be validated with due verification in the system. The data is already corrupted in the database. In…
-
18
votes2
answers11298
viewsA: How does Try-with-Resources work?
TL;DR of the try-with-resources What is: a Java syntactic resource for safe use of resources in a secure manner. Goal: ensure that scarce resources - such as database connections, file references,…
-
3
votes1
answer3803
viewsA: How to indicate in a regex that the symbols '(' and ')', the parentheses, are one of the alternatives in a list of symbols in Java?
The process to "escape" a special character in a String in Java has two steps: "Escape" special characters to Java. "Escape" special characters to the regular expression, which may include, "escape"…
-
7
votes1
answer310
viewsA: Is it possible to have Java SE and Java EE on the same machine?
Java EE is an extension for Java SE. For example, the Java Standard Edition includes the API called JDBC for database access. The Java Enterprise Edition includes the API called JPA for…
-
3
votes3
answers414
viewsA: Close connection in another method
The class Connection is closeable, that is, you can use a block try-with-resources to finish automatically. Besides, there are other things that can be improved in the code, such as: Initialize the…
-
0
votes1
answer149
viewsA: Configuration file
The problem is the lack of an appropriate separation between the application code and the configuration. You should not know the connection data (password!) of clients. This is precisely why Java…
-
3
votes1
answer579
viewsA: Conversion of Hibernate Result to json
I ran a little test with the code: List<Map<String,Object>> listObj = new ArrayList<>(); Map<String,Object> map1 = new HashMap<>(); map1.put("f1", "v1"); map1.put("f2",…
-
2
votes1
answer109
viewsA: Change function return to synchronous
A simple way to solve this is to use your own callback. Example: function Confirm(messageOfConfirmation, functionOfCallback) { //nenhum alteração necessária } function PodeExcluir(){ Confirm("Tem…
javascriptanswered utluiz 72,075 -
6
votes1
answer332
viewsA: Nullpointerexception when removing stack element
Consider the excerpt: if(index==0){ inicio.getAnterior().setProximo(inicio.getProximo()); // LINHA #17 In this case, the NullPointerExeption (NPE) occurred because if index is zero, so there is no…
-
1
votes1
answer421
viewsA: Return to main() after using start()
The execution is returning to the method main, but different than you might think. The "finished" line is printed before the first iteration of the thread Esquiador. I guess you were hoping the…
-
5
votes1
answer214
viewsA: What is the difference between using the Enum Standardcopyoption constants?
How flags are used All flags are passed to the file copy implementation specific to each operating system. For example, in the case of UNIX-based systems, the class UnixCopyFile uses the options to…
-
1
votes1
answer358
viewsA: Help with Date and Time Search
Although it is possible to execute an SQL query using text concatenation, do not, because it is putting your system at risk by allowing SQL injection. Use a PreparedStatement and pass the date…
-
10
votes3
answers3964
viewsA: What is Threadpool all about?
Executioner The question should be about the ExecutorService or just Executor. Such Apis are an abstraction to manual thread control for executing a set of asynchronous operations. Therefore, the…
-
2
votes2
answers98
viewsA: Evaluation of conditional expressions in Java
I do not believe that the compiler javac have any option for this. However, in this case, it is recommended to use at least one (may be more) of the static code analysis tools, such as: Checkstyle,…
-
1
votes3
answers189
viewsA: Is it better to have a kind of exception for each case or a more general exception?
It depends. And you don’t have to give up one thing to have another. For example, in an API used by third parties, you will certainly want the possible well-defined and documented exceptional…
-
22
votes4
answers4254
viewsA: Why should we avoid returning error codes?
Such a recommendation has very strong reasons. I will illustrate some... Avoiding assumptions When developing the API of financial calculations, it was assumed that some routines would return only…
-
3
votes2
answers318
viewsA: Java Routine Inside Loop Repeat
Depending on your need, I see at least two possibilities. Timer If you want to perform a process repeat times, but without interleaving the executions, that is, always leaving an interval between…
-
11
votes4
answers724
viewsA: Java: When to use Interrupt vs flags?
The use of a flag volatile, as presented in the question, it brings no benefit beyond a feeling on the part of the developer to have in his hands the "control" of execution. :) Interruptions The…
-
2
votes1
answer359
viewsA: How to write data to the webstorage without overwriting already recorded data?
As stated in other issues linked in the comments, you need to recover the existing data and add the new ones. Since web Storage accepts only strings, the recommended solution is to use JSON…
-
1
votes1
answer156
viewsA: Bean dependency injection on Tomcat
I’m a little rusty with these Apis, but the problem might occur if you put the class MyBean together with the application, within WEB-INF/lib. Web containers have a hierarchy of class loaders so…
-
6
votes3
answers13820
viewsA: Calculate age per day, month and year
First of all, the use of classes like java.util.Date and java.util.Calendar should be avoided, being alternative library classes Joda-Time or classes as LocalDate and LocalDateTime, in addition to…
-
5
votes2
answers608
viewsA: How do I know which Arraylist objects are being modified or deleted?
Simplistic response You can’t do this in Java. Impractical response You could instrumentalize Java classes so as to intercept the accesses and changes made to the objects. Reasonable response…
-
1
votes3
answers1870
viewsA: Assign value to variable in method declaration
If you are looking for an optional parameter, use method overload. public void teste() { teste(false); } public void teste(boolean b) { //executa ação aqui } This works for simple methods. I would…
-
4
votes1
answer731
viewsA: Return data obtained in Onresponse
The first step to solving the problem is to understand how code execution works. You’re passing an object Listener whose method onResponse shall be invoked as a callback when the request is…
-
6
votes4
answers92747
viewsA: Convert String to whole in Java
Documentation The first important thing for someone who is starting to study or work with Java is to consult the required class documentation. For example, Scanner has the method nextInt, which…
-
2
votes2
answers525
viewsA: How to get and count elements that DO NOT have a certain CSS property with js/jquery?
Selecting what is visible The jQuery has a special selector :visible that selects all elements that occupy some space in the document. It’s not exactly your requirement on display:none, but is more…
-
2
votes1
answer212
viewsA: Error au render screen in pimefaces application - Nullpointexception
The expression in the method isEditando will launch an NPE if the attribute produto is void. To fix the problem, either you must ensure that the product is selected before the method is executed or…
-
0
votes1
answer84
viewsA: Javascript that permanently changes server css
The two main possibilities are: Create events in Javascript where, after the user makes a change, he makes an AJAX request, saving the values on the server as you see fit. Such values are restored…