Posts by utluiz • 72,075 points
957 posts
-
1
votes1
answer1761
viewsA: How to get the value of the <version> property in pom.xml?
The Maven Resources Plugin allows you to perform Maven variable overrides on files (Resources) of the project. This plugin is part of the standard Maven execution plan in the phases…
-
8
votes2
answers1363
viewsA: What is the relationship between JPA and ORM?
To Java Persistence API (JPA - Java Persistence API) is a specification of how the Object-Relational Mapping (ORM - Object-Relational Mapping) should be implemented on the Javaee platform.…
-
7
votes1
answer1403
viewsA: Save image link as file in Storage location
Downloading and saving an image The following function makes a request to get the image data, converts the received data to base 64 using the FileReader and then sends the result to a callback…
-
16
votes2
answers994
viewsA: Why use a generic return?
Understanding the syntax Considering the important part: <T> Optional<T> empty() T is a type variable. This works more or less like a variable in a template, where you can replace T by…
-
12
votes5
answers1382
viewsA: No return on method?
Read a File to a String You don’t need to create a method for this. The recommended way to read an entire file to a String is the next: String dados = new String(Files.readAllBytes(file.toPath()));…
-
6
votes2
answers1757
viewsA: How to receive a List (Java) in Javascript, using Spring MVC?
Current problem The code will not work because the value of ${processosList} will not be a list that Javascript understands, but the list representation in a String returned by your method toString.…
-
4
votes1
answer730
viewsA: Client-Server Chat application with Sockets does not work
Nimbus Look & Feel The Nimbus is a cross-platform visual user interface (UI) implementation included in Java 6. It is to be an evolution to the themes already existing in Swing and is really…
-
3
votes2
answers409
viewsA: Pass-by Object Reference Wrapper to Method
What happened What happens logically after the first assignment is this: No matter what you used new Integer(1) or simply 1, the result is the same. When you called the method muda, what happens is…
-
2
votes1
answer798
viewsA: Create extension to manipulate DOM from other pages
I don’t think you can access directly, however you can perform a function in the scope of the page using executeScript and then collect the result using communication through the Shared DOM. Example…
-
3
votes3
answers382
viewsA: Design Standard for Filters
You can combine the @Rogeroliveira response on the SQL side with the default Builder and Interfaces Fluents on the C-side#. Basically you would use the filter like this: new…
-
5
votes2
answers174
viewsA: Grouped id rendering speed vs class
Tool Google Chrome had a CSS profiler, but this was removed because it is considered that the performance of CSS today is reasonably good for cases that were slow a few years ago, so simply this…
-
9
votes1
answer336
viewsA: Error when rounding Bigdecimal
Method that does not exist The error message "method ??? is Undefined" means that the method does not exist. This could occur if you were using different versions of Java or some library at compile…
-
4
votes3
answers753
viewsA: Does Java have a class to work with command line arguments?
If you use the framework Spring to do dependency injection and manage your Beans, you can decouple your code from searching command lines and simply inject read values from the environment. Example:…
-
15
votes3
answers16185
views -
1
votes2
answers579
viewsA: Two threads running the same function
Competition problems usually have a common cause: shared objects In this case, it seems that the shared object Dm is used by both threads. That means both of you threads are sending and receiving…
-
5
votes1
answer544
viewsA: Encryption using java stacks
If you don’t necessarily need to use stacks and use Java 8, everything can be done very directly like this: String texto = "Uma mensagem confidencial"; String reverso =…
-
4
votes1
answer533
viewsA: Method Invocation may Produce Nullpointerexception
The cause is that you do not treat the exception in the s I try/catch. The variable addresses will be null and the method will continue running. A possible correct encoding for this code would be:…
-
7
votes2
answers168
viewsA: java desktop "ajax" exists?
There are several ways to solve synchronization between multiple clients from one data source. Some are simple and inefficient, others efficient but complex. I will cite two approaches. Periodic…
-
1
votes1
answer83
viewsA: Difficulty getting object inside a CDI Extension
According to the documentation, extensions execute before any bean is created, precisely for the purpose of being able to interfere with how they are created. However, you can listen to events and,…
-
6
votes1
answer7203
viewsA: How do I resolve the "No appenders could be found for logger" warning?
The archive log4j.properties should be placed in the folder WEB-INF/classes of your application. If you are only in WEB-INF or in another directory will not work. This is documented in log4j.…
-
7
votes3
answers10606
viewsA: Convert object to String?
First we need to differentiate conversion, which consists in transforming one type of data into another, one cast, which consists in accessing an object as a type more specific than the current…
-
1
votes1
answer24
viewsA: Is it possible to use Tiles within Springmvc tags?
You can’t do that. Of course, sometimes we mix a JSP tag with an HTML tag, but we can’t put a JSP tag inside another JSP tag. One way to resolve this is to make template attributes available as…
-
7
votes2
answers930
viewsA: What does "serialVersionUID" mean?
What is In practice, this number would be the version of your class. You should change it whenever you add, modify or remove an attribute from the class. Serialization This is used during the…
-
4
votes1
answer419
viewsA: How to change style in pure javascript?
The selector is the same, what changes is the way you go through the element(s) and apply the desired style. Example: var e = document.querySelectorAll('#main article:nth-child(3) .postSnippet');…
javascriptanswered utluiz 72,075 -
8
votes1
answer4684
viewsA: How to create a stopwatch in JAVA?
To execute commands after a certain time, you can use the class java.util.Timer. For example: new java.util.Timer().schedule(new TimerTask() { @Override public void run() { //executar ação aqui } },…
-
0
votes1
answer165
viewsA: Error when viewing postgres table using Jpa, Hibernate and Postgres
The only problem I see is having attributes like java.lang.Number in class. This does not seem to be supported by Hibernate according to the documentation I found, for example on manual and in the…
-
4
votes3
answers404
viewsA: Grab Preview image of a video / listFiles() does not work
Decode videos Regarding the problem #1, there is no magic solution to read images of whichever video format. Each video format needs a specific algorithm to interpret it and hardly a single…
-
13
votes2
answers13314
views -
3
votes1
answer327
viewsA: What types of storage for desktop applications?
What are the advantages and disadvantages of these forms? Methods 1 and 2 are good for read-only data as it is easy to load and access what you want. However, considering that you will often want to…
-
3
votes1
answer126
viewsA: Is there any way to start a Thread that is in a method in another class?
The correct way to solve this is to extract the anonymous class that implements the thread so that you can reuse. Example: class MinhaClasse { //inner class private Runnable insercao = new…
-
1
votes1
answer320
viewsA: Using Jexcel for reading and writing
The error is caused because the Jexcel library failed to evaluate a formula in its template sheet. The formula must have a crease of which one or more cells of that line are part and when trying to…
-
1
votes2
answers964
viewsA: How to take a string arraylist value, for a File array
In Java 8 you can do so: strList.stream().map(File::new).collect(Collectors.toList()) Most complete example: List<String> strList = new ArrayList<>(); //adiciona itens em strList…
-
3
votes1
answer1544
viewsA: How to use the Servlet context Listener to start a Servlet so when the application is loaded?
I think you’re very close to the solution, but going the wrong way. First, you were right to use the tag <load-on-startup>. This causes Servlet to be initialized during application startup.…
-
5
votes4
answers257
viewsA: Use of setters in the builder
I don’t know exactly what you meant by semantics, but we can see the question from various perspectives. Clarity Use methods Setter can be more confusing because if someone else will read your code.…
-
4
votes2
answers2293
viewsA: What is the best (fastest) way to read a file from a web server?
TL;DR The fastest way depends on the goal of the program. If the idea is to load everything in memory, just use a more efficient method. Reading file in a String The fastest way I know to upload a…
-
2
votes4
answers4670
viewsA: Select string at random
To select a String among many in one array: String[] opcoes = { "A", "B", "C", "D", "Z" }; String selecionada = opcoes[new Random().nextInt(opcoes.length)]; To do the same with a list:…
-
0
votes2
answers82
views -
24
votes2
answers17812
viewsA: What is a Thread? How does it work?
Think of a thread as a sequence of commands being executed in a program. If you have two threads, will have two sequences of commands running at the same time in the same program or process. Note…
-
7
votes2
answers403
viewsA: TDD in existing function (Django)
TDD is not unit test TDD is a software development methodology or often functions as a set of principles where testing plays a key role. What you’re looking for is unit testing. Of course this is…
-
8
votes2
answers2353
viewsA: When should I inactivate or delete a record? Good database practices
To complement the theme, I would like to point out some reasons for deciding to remove the data from the database instead of disabling the respective records: A system where historical data would…
-
9
votes2
answers2282
viewsA: How to do binary search in a txt file?
The best approach to a text file search will depend on how often the file is modified, how long it takes to go through the file, and how often the search functionality is used. Depending on the size…
-
19
votes15
answers4487
viewsA: Determine if all digits are equal
Java 8 with chars stream In Java 8 is easy with streams: boolean digitosIguais(Long numero) { return numero.toString().chars().distinct().count() == 1; } Traditional loop Nod digits Or, if you…
-
3
votes2
answers1301
viewsA: Techniques for setting requirements and writing use cases
I agree with Leo that theory is different from practice, and the whole answer is very good. Theory vs Practice We have to be careful. Many theories are created to then be implemented and tested in…
-
24
votes5
answers1899
viewsA: Is dealing with business rules in the model bad practice?
Forget the patterns (for a moment) Certain specific problems are best solved if we don’t try to fit everything into some pattern. MVC is not a silver bullet, it is a model, a guide that helps us…
-
1
votes3
answers1408
viewsA: Working with JPA+Hibernate cache
Scope of EntityManager Answering the first question: maintain an instance of EntityManager by class does not seem correct. Of course this can work in certain circumstances, as in the case of the…
-
4
votes2
answers247
viewsA: With resource in Java
This "resource" is just syntax sugar modifying the resolution scope including the object passed in the with. Although it can save a little typing, the use of this feature can cause confusion in…
-
16
votes2
answers957
viewsA: How to test software well?
My answer aims to complement the @guiandmag, as some questions remain. It is important to know the techniques to test a software, but it takes a good deal of wisdom to determine what is feasible and…
-
8
votes2
answers9610
viewsA: Pick current date from machine
Just don’t pass any parameter. So: Date now = new Date(); As can be seen here, this is the same as calling the builder passing the value of System.currentTimeMillis: Date now = new…
-
5
votes2
answers865
viewsA: I can’t save to the database in a Spring MVC project
The first thing you should do is add a log configuration to display errors in the console or in a log file. I saw in the pom.xml of your project that is using Log4j, so this means that it would be…
-
7
votes1
answer140
viewsA: Premises for a testable software
TL;DR There are many different types of testing at different levels of system abstraction, from unit testing to user acceptance testing. See more details in this other answer. Testability is the…