Posts by StatelessDev • 2,534 points
98 posts
-
1
votes2
answers80
viewsA: Return Null Print Java
When you initialize an array of nonprimitive elements in Java, all positions are filled with null. So when you perform this method: lista.listap(tam); You are initiating your array pontos. If at…
-
2
votes1
answer57
viewsA: Doubt about Android Activity syntax and the "onCreate" method and what are its arguments!
Bundle is a class whose function is to save and retrieve state information about the Activity in question. There are certain situations, such as changing the orientation of the apparatus (portrait…
-
3
votes2
answers254
viewsA: Using Enum in Java
Flipping heads or tails presupposes randomness, so your program needs to have a method that can randomly choose one of the Enum values you created. Java has a class called Random, that cares about…
-
0
votes1
answer143
viewsA: Program execution error with Spring Boot: null id
The error is quite clear: Caused by: org.hibernate.id.Identifiergenerationexception: ids for this class must be Manually Assigned before Calling save(): com.cardoso.cursospringboot.domain.Product…
-
1
votes1
answer148
viewsA: .gitignore being automatically created by Eclipse IDE
It is possible that the "Automatically ignore derived Resources" option triggers the creation/modification of the .gitignore. A solution for this behavior (i.e., preventing the creation/alteration…
-
0
votes1
answer704
viewsA: REST API using Spring Boot
You need to look at JSON as the representation of an object, not as a set of Strings. The error is because Spring (in this case Jackson) cannot find an object that matches exactly what he expects.…
-
1
votes1
answer44
viewsA: simple.Jsonarray for json.Jsonarray
You can import and use both yes. Just import normally and, when using the code, pass the complete reference, including the package path. Something like: org.json.simple.JSONArray json = new…
-
2
votes1
answer128
viewsA: What is it for and where should I use "strictfp"
There is a technical standard called IEEE 754, which defines how the double precision is to be represented in practice in floating point. In Java, this representation is materialized in the data…
-
2
votes3
answers302
viewsA: Save value after JAVA comma
Use the module operator, which returns to you the rest of a division, which is the value you want: int x = 175%10 //resultado é 5 You don’t even have to divide to work with the decimal. You can…
javaanswered StatelessDev 2,534 -
2
votes3
answers81
viewsA: Difference in arithmetic and assignment operators practice
There is no conceptual difference between the two. In both cases, you are defining that a becomes worth the current value of a plus 2, which you correctly claimed to be 12. The term "receive" is…
-
5
votes2
answers1334
viewsA: What is the difference between Double and Double in java?
double is a type of primitive data (i.e., it is not created by reference, in other words, it is not an object). Not being an object, you don’t have access to a number of facilities that object…
javaanswered StatelessDev 2,534 -
1
votes1
answer25
viewsA: Draw between Activities
Your question is not very clear, but what you probably want is to pass data between activities. For that, you will need a Intent. Assuming you have generated one int and want to pass it between…
-
1
votes3
answers110
viewsA: Does the File(String) constructor create a file?
Does not create. The documentation says the following: File(String pathname) Creates a new File instance by Converting the Given pathname string into an Abstract pathname. As the text informs, an…
javaanswered StatelessDev 2,534 -
3
votes3
answers715
viewsA: Read JSON array on Android
You can build something more object-oriented. The idea is to have an object that represents the answer, with a field resultado. The return of the API (a String) would be mapped to this class, which…
-
6
votes2
answers2154
viewsA: Converting Int to String!
The method parseInt() class Integer receives a String and converts it into a primitive value of the int. As you said yourself id is declared as a int in class Produto, the call…
-
1
votes1
answer1971
viewsA: How to make a program calculate the area of several objects separately using the values given by the user (scanner)
public static void main(String[] args) { /*Descubra a área do que o usuário passar * Trapézio: A = ((B + b)/2) * h * B = Base maior, b = base menor, h = altura * * Triângulo: A = (B*h)/2 * B = Base,…
javaanswered StatelessDev 2,534 -
1
votes2
answers1846
viewsA: Java Spring Boot project version
Yes, it is possible. Spring has a bean called BuildProperties, that has some project information, such as version number. For that, you need the following: 1) a) If the project is Maven, add the…
-
3
votes2
answers1037
viewsA: How to make an infinite count loop in Java?
Whatever the language, its "infinity" is relative to the maximum size that the data type you are going to use supports or, in the latter case, the available memory of your machine. That means an…
-
1
votes2
answers1589
viewsA: How to pass CSV file data to an array in Java?
I will offer a more functional and cleaner alternative: List<String> numb = Files.lines(Paths.get(new File(LocalFile.getText())).toURI()), StandardCharsets.UTF_8)…
-
6
votes1
answer863
viewsA: Deadlock concept in Java
Deadlock is the cyclical dependence that happens between two or more threads sharing two or more resources (variable, code block, etc.). In other words, a thread T1 depends on another T2, whereas…
-
1
votes2
answers66
viewsA: Return data from a subobject
If you want to access an attribute of Tarefa, not only access the object itself, but the field within it. In your case, the getters of Task return a String. Thus, a solution to your problem may be:…
-
2
votes1
answer86
viewsA: What is the difference between the Join() method and the Synchronized statement?
join() interrupts the execution of thread current until the thread who invoked the method join() be fully executed. synchronized prevents multiple threads execute a code block or access a variable…
javaanswered StatelessDev 2,534 -
1
votes1
answer158
viewsA: Collection of an Object making calculations with Bigdecimal
BigDecimal is an immutable class, just like a String, for example. This means that you need to store the return of the invoked method in a variable, otherwise the performed computation is lost.…
-
0
votes1
answer35
viewsA: Error Passing Object To Other
The error is quite clear, as you yourself noted: Here is the method that arrow the variable internado: public void setInternado(String internado) {...} He gets a String. Now, what you’re passing on…
javaanswered StatelessDev 2,534 -
2
votes1
answer190
viewsA: How to exclude a parent entity without excluding the daughter entities?
Add nullable=true the mapping of its daughter entity and, in its delete() of the parent entity, before effectively erasing that entity, you have to set null in all children related to it. For…
-
1
votes1
answer54
viewsA: How do I run my code asynchronously and in real time or with each given time span?
You need to use the class Timertask. The ideal is to have a class on the side that extends TimerTask. In it, you must implement the method run(), which is the code you want to run. class…
-
0
votes1
answer31
viewsA: Save excel file to an array
A 2d matrix is nothing more than a line-to-column crossing. In the case of Excel, this is easily visualized in the name that the cells receive: A1, B2, D5 etc. What we want then is, in each column,…
-
1
votes1
answer384
viewsA: What happens internally when running a Spring Boot application?
In general, Spring Boot cares about 3 main things on its startup: 1) Automatically configure your project from the dependencies you declare in the build system (pom.xml - Maven or build.Gradle -…
-
3
votes1
answer53
viewsA: Spring Rest - Use of Various Services and Repositories
Early in the application, Spring already sweeps its classes in search of Beans to be managed by him. This means that even in classes in which your program has not even passed yet, the Beans are…
-
1
votes1
answer2872
viewsA: How do I verify that a given field/value exists in the JSON document?
Using the Gson API, the ideal would be for you to create a POJO class that maps all fields in your json. From there, just check if a certain field is null. Here you find a basic example of how to…
-
1
votes1
answer94
viewsA: Method using JAVA thread and inheritance
In anonymous classes, such as the one implicitly created by thread, the variables must be final, ie constants. For this reason, the compiler does not allow you to change the variable ar. For your…
javaanswered StatelessDev 2,534 -
1
votes1
answer48
viewsA: How to use two date parameters for two Betweens without repeating the parameters using Spring Boots?
The between connects two parameters, which are not reusable after the internal assembly of the query by Spring. The error message already gives you this tip: No Parameter available for part…
-
2
votes1
answer1007
viewsA: How to solve this Spring Boot problem?
Spring Boot features the Autoscan feature, which scans classes for Beans to be managed by them. The default behavior is to scan packets below that in which the class with the method main is located…
-
4
votes4
answers430
viewsA: Print variable inside a repeat structure
An important concept in programming is called scope. In Java, it is defined by curly braces, the { }, but let’s call them block, ie each pair of { } is a block and, as you may have noticed, you may…
-
4
votes1
answer862
viewsA: Building select in HQL
Suppose a class mapped and annotated with JPA/Hibernate that represents Usuario with these fields, reflecting a table you already have in the database: @Entity class Usuario { @Id private long id;…
-
0
votes1
answer268
viewsA: Null return when using Double type variable
Double and double are different things, hence perhaps your surprise. The first is an object and as such, whenever it is not explicitly initialized, it will be null by default (it is the same…
javaanswered StatelessDev 2,534 -
1
votes3
answers209
viewsA: Polymorphically manipulating subsclasses
Polymorphism, whose concept has already been explained in other responses, can occur between classes that have a "é-um" relation, that is, that have inheritance. In the case of your example, the…
-
1
votes1
answer662
viewsA: Import the postgres library into the intellij idea IDE
Click on your project and then: File > Project Structure... Under Project Settings, go to Modules > Dependencies > "+" sign > Jars or Directories... Select the jar file and click OK,…
-
6
votes1
answer303
viewsA: Hibernate does not recognize column in database
The error is quite clear, as can be seen from this line of stacktrace: Unknown column 'categoria0_.codigo' in 'field list' JPA/Hibernate was unable to find a column with the name in its database…
-
2
votes3
answers318
viewsA: How do you get part of a String?
Taking into account your need from the clarifications in the comments of the question, this should suffice: String linha = "Nota fiscal - 502: Status do retorno da transmissão: 778 - Informado NCM…
javaanswered StatelessDev 2,534 -
0
votes1
answer39
viewsA: How to use different fonts in the same Text field
To change the style of the text, you need to define a Typeface and then apply it to the desired component: Typeface boldTypeface = Typeface.defaultFromStyle(Typeface.BOLD); //negrito Typeface…
-
1
votes1
answer140
viewsA: I can’t access a form page
Spring is prepared to handle multiple urls "/". Modify this line: resolver.setPrefix("WEB-INF/views/"); for resolver.setPrefix("/WEB-INF/views/");…
-
2
votes2
answers152
viewsA: When do I use.metodo(). metodo()?
This is called method chaining (method chaining). It can be used to give more clarity in the code and to use you need each method to return an instance of the object that has, in turn, the method to…
javaanswered StatelessDev 2,534 -
2
votes4
answers1245
viewsA: Hibernate - How to search all rows of a table with Hibernate?
Assuming an entity called Pessoa, which is correctly mapped into your system, and a variable session in which you have already started a Hibernate session, you want something like this to recover…
-
1
votes1
answer64
viewsA: Nullpointerexception when reading Jsonarray passing String
Within the JSONArray, you have a collection of JSONObject and not String (therefore the message JSONArray[0] not a string.). To NullPointerException happens because you try to access estado which is…
-
1
votes1
answer1050
viewsA: Spring Security blocks POST requests despite settings
You must disable the CSRF: @Override protected void configure(HttpSecurity http) throws Exception { http // ... .csrf().disable(); }
-
1
votes1
answer490
viewsA: Tostring problem in Android Studio
Android Studio is complaining that the method insert() wait 3 parameters of type int, but you’re passing them as String, precisely by using the method toString(). Doesn’t make much sense. In that…
-
1
votes1
answer1439
viewsA: Request Post API Messenger with Spring Boot
You need the class Resttemplate, Spring Boot. It allows you to perform HTTP requests quite easily. For this request, you need 3 things: the headers, the json with the data, the URL to call. To…
-
1
votes1
answer215
viewsA: Is it possible to return the values of a Resultset?
The ideal, in these search methods, is not to return boolean, but the very entity (or object) you are seeking at the base. That’s because, as you yourself realized, return a boolean in this case has…
javaanswered StatelessDev 2,534 -
2
votes1
answer71
viewsA: Doubt Socket Server
Because a keyboard typing operation is an infinite data input, that is, the system is eternally in a state of waiting for the next line to be typed, even if it is never actually typed. In other…