Most voted "java" questions
Use this tag when the question refers to some resource, information, or problem relating exclusively to the Java programming language. Java is a class-based, statically typed, reflective, and execution environment (JRE) language. Java programs are compiled to bytecode and run on a virtual machine (JVM), allowing a "write Once, run Anywhere" philosophy (WORA).
Learn more…14,468 questions
Sort by count of
-
4
votes0
answers148
views -
4
votes2
answers93
viewsWhat are pre-specified classes?
Reading the wikipedia publication about POJO (Plain Old Java Objects), I came across the term pre-specified classes. I understood very superficially that perhaps these are the classes of…
-
4
votes0
answers222
viewsTreating JSON Response with Retrofit in Android Studio
To be clear, I am developing a simple application test, where my user type the Cpf of a registered customer and their data as customers appear on the screen. My server returns me a json with a…
-
4
votes3
answers1697
viewsRemove 2 specific characters from a String
Good afternoon ! Devs, I’m having trouble solving the following problem: In a calculator app, calculations always return a Double, which automatically inserts a decimal place even if it is to deploy…
-
4
votes2
answers193
viewsJsonobject with multiple values without using Array
Goal Create a JSON with the following structure: { "auth": { "user": "rbz", "token": "abc123" } } Setting Creating the root structure: JSONObject JOraiz = new JSONObject(); Creating the values user…
-
4
votes3
answers715
viewsRead JSON array on Android
I’m having trouble reading a JSON in the format: [{"RESULTADO":"SUCESSO"}] Webclient.java: //PARA LER UM JSON, USAMOS A Scanner Scanner scanner = new Scanner (connection.getInputStream()); String…
-
4
votes3
answers81
viewsDifference in arithmetic and assignment operators practice
package entities; public class Product { public String name; public double price; public int quantity; public double totalValueInStock() { return price * quantity; } public void addProducts(int…
-
4
votes1
answer661
viewsJava spring: Infinite recursion (Stackoverflowerror) error
I’m having trouble carrying out the method list of translations of the document, I’m not understanding the reason for the error, follows code: Translation.java @Getter @Setter @NoArgsConstructor…
-
4
votes1
answer278
viewsInterpretation of logic operators in Java regarding short-circuit
I read that question Doubt about logical operators && e || in Java, but I follow with the doubt. Solving some exercises on Java I find such a statement: Operators & and | operate in the…
-
4
votes2
answers2567
viewsJunit Eclipse Error: "No test found with test Runner Junit 5"
I’m not being able to run my tests in Eclipse, below is a simple test that doesn’t work: import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; class…
-
4
votes1
answer664
viewsCount with HQL JPA
Problem How do I receive the amount of record from a database table? public Integer quantidadeRegistros() { try { Query query = em.createQuery("SELECT COUNT(*) FROM Categoria cat"); return (Integer)…
-
4
votes2
answers296
viewsInserting data into an Arraylist
I have a problem to implement this code, I can not enter the data in Arraylist. public class Principal { public static void main(String[] args) { Faltas faltas = new Faltas();…
-
4
votes1
answer247
viewsUsing replace in a character in the middle of a String to add text before and after the String
I have this expression stored in a String: 1 * Math.pow(x, 3.0) + 4 * Math.pow(x, 2.0) + 1 * Math.pow(x, 1.0) + 27 However, I use a derivation library that only accepts the character ^ to make…
-
4
votes1
answer3026
viewswhat is a service and what is its difference to a controller?
I have read many articles and seen many lessons on Java and lately I come across a lot with the concept of services and controllers, I have the clarity of the role of the Controller within an MVC…
-
4
votes3
answers165
viewsWhy authenticate your cell phone number via text in the register?
I am developing an android app, early on I come across the following question about security. Why authenticate by SMS? It brings extra security? Why not just check the number present on the cell…
-
4
votes1
answer744
viewsWhat are the dangers of keeping the Oauth2 token on the frontend?
I believe I am paranoid, but I could not find any situation similar to mine (if you know pass me the link, I am grateful) so I wanted to ask this question to get a definitive answer. Before the…
-
4
votes1
answer296
viewsImplementation Doubt in Object Orientation
I am implementing the whole book set exercise deitel 6th edition: Create the class IntegerSet. Each object IntegerSet can store integers in the range of 0 to 100. The set is represented by an array…
-
4
votes2
answers113
viewsGeneric types in Java method call
I wanted to understand how this works and the name they give it in Java. Follow the code snippet: public <I, O> SimpleStepBuilder<I, O> chunk(int chunkSize) { return new…
-
4
votes3
answers1637
viewsHow to iterate with two-dimensional array?
Hello, I am making a library to help in the creation of games and for that I would like to know how to iterate in two-dimensional arrays, I know that the array for one-dimensional is just to do:…
-
4
votes2
answers3601
viewsHow to compare two different lists in Java?
I have two lists that share a common value between them. I wanted these selected objects to be filtered so that it is added to another list List<Objeto1> lista1 = new…
-
4
votes1
answer68
viewsIn Assumptions on Timing - I don’t understand this concept of a book
Cited in the book that a critical region has 4 key points: Progress: Ensures that all threads are entering and leaving the critical region, avoiding deadlocks. Mutually Exclusive: Only one thread…
-
4
votes2
answers163
viewsHow to pass numbers between "{ }" in the url?
I’m having a dumb doubt in some exercises using Spring Boot. The exercise requires that I receive the list of numbers as follows: http://localhost:8080/listaDecrescente?lista={12,55,70,22} And…
-
4
votes1
answer101
viewsGenerics <? super T> and <? extends T>
In the coding below, because the Box<? extends T> extends and the EqualityComparator<? super T> super T? uses so as to make part of the code println true return? public boolean…
javaasked 4 years, 11 months ago Pirategull 659 -
4
votes1
answer89
viewsIs it possible to replicate a Union in Java?
As unionthe ones I’m talking about are the same as C/C++. The goal of union is to save memory using the same region of it to store different data at different times. It’s like a hotel room.…
-
4
votes1
answer463
viewsHow to schedule a task and run only once independent of the number of instances?
My application has a scheduled method to run every 5 minutes with the @Scheduled of Spring, but I would like to rise more than one instance of implementation and that this task should not be carried…
-
4
votes1
answer91
viewsError reading Jsonobject inside an array
I have the following JSON: { "setor":6, "tipo":"S", "filial":1, "peso":0, "doca":1, "operacao":1, "usuario":1, "empresa":1, "movimento":23, "local":4, "ativos":[ "{\"ativo\":1,\"quantidade\":25}",…
-
4
votes1
answer97
viewsDoubt with While
I’m a beginner and I’m having second thoughts While / Do…While, follows the doubt in which question. I have an exercise to follow that the teacher solved with the command Do…While, I was trying to…
-
4
votes1
answer96
viewsNonstatic nested interfaces can be used independent of instance of the enclosing class?
I was reading about JsInterop and I come across an example of code: package com.example; @JsType public class Bar { @JsFunction public interface Foo { int exec(int x); } public static int…
-
4
votes1
answer59
viewsHow to deal encapsulated a field that is a list of immutable elements?
Imagine that you have an object and one of its fields is a list of immutable elements. You want to make this field available to the clients of this object in a controlled way, after all a list can…
-
4
votes2
answers77
viewsUsing integers as Java Locks
I have the following code snippet: class classe{ public static void main(String[] args){ Integer lock = 0; Thread t1 = new Thread(){ public void run(){ // instruções thread sem sincronia…
-
4
votes1
answer75
viewsCompilation error on non-static element reference
public abstract class Teste { public static final Teste IMPLEMENTACAO_1 = new Teste() { @Override public void executar() { teste1(); } }; public static final Teste IMPLEMENTACAO_2 = new Teste() {…
-
4
votes2
answers88
viewsA Setter method can receive a getter + value as a parameter?
I created the advisory methods Setter and getter for the balance attribute. It is correct to use these advisors within each other? One being used as parameter for the other. More specifically the…
-
4
votes0
answers48
viewsIdentify new, removed and modified objects from two ordered "collections" using extra O(1) memory in O(N) time
I have 2 "sets" of elements, neo and old, which has elements of the type T, all non-zero. Also, I know that these elements are identified by a key K and I can extract using this key using a…
-
3
votes1
answer850
viewsPrimefaces Datatable Lazy - Table does not present records
I’m creating a Lazy datatable, but although the class load is loading the records correctly, the table remains empty. XHTML: <p:dataTable value="#{chamadoMB.chamados}" var="c"…
-
3
votes1
answer3916
views -
3
votes2
answers659
viewsHow to use Quartz Scheduler with Demoiselle?
I created a job using Quartz Scheduler within a Java web application that uses the Demoiselle framework with JSF and Tomcat 7. The job must call a Business Controller (BC) method, which calls a DAO…
-
3
votes3
answers2230
viewsJava shows "Type Safety: Unchecked cast from Object to Hashmap"
I’m creating a class that through that works similar to Xpath. The function works perfectly, the problem is that in this part of the line (HashMap<String, Object>) test.get("test-map");,…
-
3
votes3
answers5690
viewsCatch latitude Android - Location == null
I’m having trouble getting latitude and longitude on Android. Using this function, always the "Location" returns "null". public void onCreate() { LocationManager locationManager = (LocationManager)…
-
3
votes2
answers169
viewsHow to disable Eclipse code replacement for "setters"?
When I create a class in eclipse with a type attribute public class MinhaClasse{ private String variavel; } The eclipse underlines the word "variable" in yellow and if I right-click on it, it allows…
-
3
votes2
answers2721
viewsHow to write in a text file concatenating with existing text in Java?
I would like to write in a text file using Java, but whenever I use the functions write of BufferedWriter the previous text is deleted and the new one is written, I would like to keep the old text…
-
3
votes2
answers451
viewsSpecifying an EJB-client with Maven
I am unable to use the interfaces of an EJB-client generated by Maven. I have basically two separate projects with different functions. An EAR containing EJB’s and a WAR using EJB’s interfaces from…
-
3
votes2
answers997
viewsHow to get the reference of the selected class in Eclipse Package Explorer?
I’m making a plugin and when I right click on a class of Package Explorer, my Handler could reference the clicked class. When I right click on a class of Package explorer opens the menu, in this…
-
3
votes2
answers2488
viewsUpdating values in a Listview
I add the values that are within 3 arrays in the hashMap to insert into the listview: ArrayList<HashMap<String, String>> lista = new ArrayList<HashMap<String,String>>();…
-
3
votes2
answers12503
viewsHow to save data to the internal memory of an Android device?
I am writing files in the external memory of the device, I am doing it as follows: File arquivo = new File(Environment.getExternalStorageDirectory()+"/"+ nomeArquivo.getText().toString() + ".txt");…
-
3
votes1
answer490
viewsGet components that are inside a xhtml file
In a source code facelets (xhtml) of the primefaces, I want to extract all tags <p:inputText>. After that, I want to take the attribute label. Could you do that? Remembering that the…
-
3
votes2
answers2185
viewsTransparent java background
I have a problem with background transparent of a JTextField, by changing the content of JTextField it seems to superimpose the text and get all mixed up: I’m setting the background like this:…
-
3
votes1
answer1384
viewsError deploying to Wildfly
I’m getting an error trying to do deploy of my Wildfly 8 app: Caused by: org.jboss.as.server.Deployment.Deploymentunitprocessingexception: JBAS011445: Failed to get Adapter for persistence Provider…
-
3
votes2
answers1248
viewsHandling java/python/c directories
I have an A directory, and this A directory has several subdirectories, and in each subdirectory, it has a varied number of files. I would like to put all the files in a directory in the order they…
-
3
votes1
answer62
viewsHow to display a layout in the Homescreen Widget for each day of the week?
I would like to show certain layout in the Homescreen Widget for each day of the week. I have the 5 days, and when identifying them, the device should update the widget layout. How could I do it?…
-
3
votes5
answers411
viewsHow to avoid a comparison by brute force?
Possessing a class of any kind ClassA which has an attribute value and that, depending on the type of value i need to perform an operation differently, as I would avoid a gross comparison, as in the…