Posts by Anthony Accioly • 20,516 points
346 posts
-
5
votes1
answer67
viewsA: How do I import the "javax.Measure" package without IDE?
First let’s talk about a problem in your import line. As the comment from Guilherme javax is a namespace generic for extensions, some packages within the javax are part of the Java SE distribution…
-
2
votes1
answer59
viewsA: Is there anything like the ". format" Python method in Java?
In Java string concatenations with + are quite common. In most cases the compiler is smart enough to translate concatenations with + for concatenations using StringBuilder and append; in that way +…
javaanswered Anthony Accioly 20,516 -
2
votes1
answer105
viewsA: Java Spring Rest does not work with separate packages
In accordance with the spring boot documentation the annotation @SpringBootApplication, among other things, defines the root of the application. That is, by convention the class annotated with…
-
5
votes1
answer204
viewsA: Java converts accented characters to "strange" characters
In the following line: builder.append(new String(data, 0, bytesRead, Charset.defaultCharset())); The method defaultCharset returns the charset system standard. You are forcing UTF-8 to read the data…
-
2
votes1
answer206
viewsA: java.lang.Classcastexception: class java.lang.Integer cannot be cast to class java.lang.Void
In the following method: Void EditByUsuario(@Param("usuarioParam") String usuario , @Param("senhaParam") String senha , @Param("emailParam") String email , @Param("dataAltParam") Date dataAlteracao…
-
8
votes3
answers190
viewsQ: How to get the index of the first positive element in a list?
I am looking for a solution to a very simple problem. I need to get the first element of a list greater than or equal to zero. I was able to do this with the following function: def…
-
5
votes0
answers60
viewsQ: What is and what is the advantage of using "span<T>"?
C++20 has a new type std::span. External libraries as GSL also provide C++14 and C++17 compliant implementations. Seeking to understand what a span<T>, I stumbled upon the following…
-
5
votes2
answers213
viewsQ: Like "clone" an Inputstream?
Often I need to read a InputStream more than once. For example, to pass on the content of stream for multiple methods. void readStream(InputStream input) throws Exception { var result1 =…
-
8
votes0
answers77
viewsQ: What is a Memory Model?
Reading the Wikipedia article in English discovered that Java was the first popular language to have a memory model in the presence of well-defined threads, followed by C++11. Reading the article in…
-
4
votes1
answer57
viewsA: Java 8 SE: Finally block of a method is running before entering the method
What is happening is not that the finally is executed before the try, rather that System.out and System.err are not being synchronized. In this case, while your app is writing first on System.out,…
-
5
votes1
answer110
viewsA: Is it correct to use @Mappedsuperclass instead of @Entity to not create a table in the database using JPA?
Correct is relative in this case. You are dealing with a JPA limitation - the fact of annotations @NamedNativeQuery and @SqlResultSetMapping they need to be tied to some entity so JPA can find them.…
-
6
votes3
answers110
viewsA: How to "flatten" a list of lists of integers?
To complement the answers, here are two alternatives I found in the Stack Overflow in English: How to make a flat list out of list of lists? 1. Using sum d = [[1],[2],[3],[3]] flattened_list =…
-
1
votes0
answers19
viewsQ: How does "while / do" work in Scala 3?
Reading the changes planned for Scala 3, I discovered that the do-while was discontinued. I understand that a loop do-while can always be rewritten as a while. That said, the article examples with a…
-
3
votes1
answer88
viewsA: How to make atomic updates with Triemap and Concurrenthashmap?
Scala 2.12.x For those who are still in version 2.12.x, follow a solution with Compare-and-swap that works properly: val map = TrieMap[String, Int]() (1 to 10000).par.foreach { i => val key =…
-
4
votes0
answers31
viewsQ: What is a TLAB and what is it for?
I recently used Java Mission Control (JMC) to track a memory Leak. In doing so I realized that JMC reports memory allocations inside and outside of Thread Local Allocation Buffers (TLAB). In a quick…
-
4
votes1
answer46
viewsQ: Is there a difference between corroding, fiber and green threads?
According to the title of the question, I see these names being used to describe very similar things. In the Python world we have Greenlets described as corroding and Green Threads. In the Java…
-
2
votes0
answers42
viewsQ: Why should we use method Resferences instead of both?
When passing functions as argument to high-order functions, we can usually use two different Java 8 mechanisms+: 1. Lambas: var averageLength = stringList.stream() .filter(s -> s != null)…
javaasked Anthony Accioly 20,516 -
6
votes2
answers138
viewsA: Largest and smallest value of each row of the two-dimensional array
The anonymous, in his comment, killed the riddle of what is happening. You need to isolate the minimum and maximum for each index i. It is also necessary to update the values of max and min us loops…
-
2
votes1
answer202
viewsA: Prime number JAVA
For your code to work without printing repeated numbers just move the last if out of the innermost loop. Also note that 1 is not a prime number, so you should get the outer loop of number 2: import…
javaanswered Anthony Accioly 20,516 -
0
votes1
answer46
viewsA: How to filter information when loading a local file?
You can import all data to a temporary table and then copy only the desired entries to the destination table. Example assuming a table called contatos: CREATE TEMPORARY TABLE contatos_temp LIKE…
mysqlanswered Anthony Accioly 20,516 -
4
votes1
answer63
viewsA: Red numbers in Visual Studio
Quotation marks are missing for the ANSI escape sequences. Try the following: print('\033[33m' + 'hello')
-
1
votes3
answers50
viewsA: Show div only after checking 3 radio Buttons
The only change I needed to make to your code for it to work was to change the Binding of Event Handler click to work with the class form-control (and thus treat clicks of all radio Buttons):…
-
2
votes1
answer59
viewsA: Language C - Understanding the Concept of Pointers and Dynamic Allocation, where is the error?
I made several small modifications to make your code run. #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <string.h> #define MAX 100 #define QACOES 5…
canswered Anthony Accioly 20,516 -
5
votes1
answer57
viewsA: Doubt with logical treatment of two strings
From the logical point of view you want to capture all answers that are not equal to y or equal to n. if (!("y".equals(resposta) || "n".equals(resposta))) { System.out.println("REPOSTA INVÁLIDA!");…
javaanswered Anthony Accioly 20,516 -
1
votes2
answers268
viewsA: Problem with Javafx
Digging up question for future reference: The real problem as the stack trace is the version of Java: Caused by: java.lang.UnsupportedClassVersionError: com/jfoenix/controls/JFXButton has been…
-
4
votes2
answers434
viewsA: Second highest value of a python list
I present below some alternatives to the solution with sorted (see reply of Paulo Marques). Python has the function nlargest that returns the n larger elements of a list using a heap size n. In…
-
2
votes2
answers229
viewsA: How to receive a character array in C with for?
Your code problem is in the following section: int m = 0, n = 0, i, j; char caractere[m][n]; This code is declaring a VLA (variable length array) empty once m and n are equal to 0. If you change the…
-
1
votes1
answer63
viewsA: How to include minimum_should_match in the query of Elasticsearch dsl?
The parameter minimum_should_match should be used in conjunction with optional clauses of the type should. When minimum_should_match=1 an item will only be returned by the query if at least one of…
-
5
votes1
answer325
viewsA: Enum error with JPA + Hibernate
The problem is that you are using the common superclass Enum: private Enum<SituacaoAvaliacaoPedidoEnum> situacao; As opposed to Enum’s direct type SituacaoAvaliacaoPedidoEnum: private…
-
10
votes1
answer1432
viewsA: Translation of programming languages
No, there is no barrier. A compiler is just another piece of software. Nothing stops someone from making a Fork from any compiler / interpreter, translate reserved words and eventually locate the…
characteristic-languageanswered Anthony Accioly 20,516 -
3
votes1
answer715
viewsA: How to pass parameters for IN clauses in Jasperreports?
The syntax to handle clauses IN in accordance with documentation of Jaspersoft is $X{IN, NOME_DA_COLUNA, nomeDoParametro}. In your case: SELECT * FROM TABELA WHERE $X{IN, COD, codigos} codigos must…
-
2
votes4
answers11232
viewsA: JPA Object References an Unsaved Transient instance - save the Transient instance before Flushing :
TransientPropertyValueException. This is because one or more instances of Cidade are not being administered at the time of persistence (i.e., the city is Detached). The solution to the problem…
-
6
votes1
answer557
viewsA: Error while trying to deploy java Tomcat application
Caused by: java.lang.OutOfMemoryError: Metaspace You are having a memory shortage problem available for the application. From the boot logs above it appears that Tomcat has been set up with a low…
-
2
votes1
answer764
viewsA: Exception in thread "AWT-Eventqueue-0" java.lang.Numberformatexception: For input string: "8"
java.lang.Numberformatexception: For input string: "8" The original string contains a space before the number 8. You can solve the problem using the method trim, or, from Java 11, the method strip…
javaanswered Anthony Accioly 20,516 -
6
votes1
answer86
viewsA: Always the same output in C
There are two main problems with the above code. Its implementation of strrev simultaneously inverts the received String as parameter in-place and returns a pointer to that string. Thus the line…
canswered Anthony Accioly 20,516 -
6
votes2
answers271
viewsA: How to eliminate duplicate lines without using distinct?
Try the following: SELECT t1.* FROM #tmpHistorico t1 WHERE t1.DataAtualizacao = (SELECT MAX(t2.DataAtualizacao) FROM #tmpHistorico t2 WHERE t2.IdColuna1 = t1.IdColuna1 AND t2.IdColuna2 =…
-
4
votes1
answer812
viewsA: Comparison of values in python Tuples list 3.x
In your example a list of tuples is being sorted. In the current logic you are using the operator > to compare two tuples. This makes sense since a tuple is a sequence, and as - free translation…
-
4
votes1
answer592
viewsA: I wonder what’s wrong with my code?
Follow an implementation of the exercise: #include <algorithm> #include <array> #include <iomanip> #include <iostream> #include <numeric> #include <tuple> int…
c++answered Anthony Accioly 20,516 -
5
votes1
answer88
viewsQ: How to make atomic updates with Triemap and Concurrenthashmap?
In Java ConcurrentHashMap has an interesting property. Operations such as putIfAbsent, remove, replace, computeIfAbsent, computeIfPresent, compute and merge are atomic. Example: final Map<String,…
-
13
votes2
answers1026
viewsA: Can a subclass have two superclasses?
What you’re looking for is called multiple inheritance. While this is certainly a powerful mechanism, multiple inheritance opens doors to new problems (see, for example, that question on the diamond…
-
1
votes2
answers73
viewsA: Insert data into sql after validation
On the bank side what maintains the consistency of the relationships are constraints of the kind Foreign Key (foreign key): ALTER TABLE corridas ADD CONSTRAINT fk_motorista FOREIGN KEY (m_id)…
mysqlanswered Anthony Accioly 20,516 -
1
votes2
answers479
viewsA: Trigger to connect multiple records
You can implement a Trigger AFTER INSERT in Usuarios. The idea is to use the command INSERT ... SELECT to select all challenges and insert corresponding entries in Usuarios_tem_desafios: DELIMITER…
-
5
votes2
answers78
viewsA: A single SQL query for a user’s products!
Assuming id_produto identifies each product only try the following: SELECT id_produto, produto, (SUM(credito) - SUM(debito)) as producao_total FROM produtos_farm PF INNER JOIN produtos P ON P.id =…
mysqlanswered Anthony Accioly 20,516 -
1
votes2
answers427
viewsA: View "View" from Postgres in Mysql. Is it possible? How to Do?
It seems that this is not possible. Mysql has a engine FEDERATED to connect to external banks. Unfortunately, the current version of Mysql (5.7) limits federated access to other Mysql banks (link to…
-
1
votes3
answers200
viewsA: Speed difference between Plink and Openssh
Returning to answer my own question a year and a half later. A lot has changed in the meantime, including, Windows 10 is getting a native version of Openssh. Nothing more than the Win32-Openssh…
-
4
votes1
answer113
viewsA: Pointer is lost at function output
There are some problems with your code. In particular what is preventing a node from being assigned to its list is the way pointers (and values in general) are passed as parameters in C. C adopts…
canswered Anthony Accioly 20,516 -
3
votes1
answer214
viewsA: How to compile a Java 9 project with Lombok in Gradle?
Try the following: apply plugin: 'java-library' dependencies { compileOnly files("libs/lombok-edge.jar") } tasks.withType(JavaCompile) { options.fork = true options.forkOptions.jvmArgs += […
-
10
votes2
answers312
viewsA: Optimization of SQL code
Here is an alternative capable of bringing up to 50 records of each status sorted by date. In case of a tie between two records the result is unpacked by id (the smallest id prevails). SELECT h.*…
-
1
votes2
answers923
viewsA: Is it possible to use native query + spring date for paging?
Try the following: @Query(value = "SELECT * FROM VRS.TB_CLIE_INVS /*#pageable*/", countQuery = "SELECT count(*) FROM VRS.TB_CLIE_INVS", nativeQuery = true) Page<TbClieInv>…
-
2
votes2
answers1339
viewsA: How to convert negative decimal numbers to hexadecimal
Just leaving an alternative answer for anyone who can use the Java Apis. One of the variations of Integer.toString accepts a parameter radix. System.out.println(Integer.toString(15,…