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
-
2
votes0
answers161
viewsJPA Criteria - Using between with Subquery
"The numbers at the beginning of the consultations and the "criterias" were inserted to facilitate the explanation. (1-...)(2-...)(3-...)" I need to do this on JPA criteria: SELECT DISTINCT…
-
2
votes2
answers60
viewsError in class object generation
I have the following method: private ArrayList Clientes (JSONObject jObect) { Log.e("Lis: ", jObect.toString()); /* A linha acima impime E/Lis::…
-
2
votes1
answer63
viewsHow to make a JPA query with mappings @Manytomany
Good morning. I’m having trouble performing a query in the database where my Employee entity has 2 mappings @Manytomany and 1 mappings @Manytoone. When performing a query the Employee and Projects…
-
2
votes3
answers345
viewsAn array index error
I’m trying to make an algorithm for Selection Sort, just to train algorithms even, in my view my logic is right about ordering, but it is returning me an error that I do not understand. Code: import…
-
2
votes1
answer256
viewsInstantiating an object in the same constructor class is "inelegant"?
It is always seen as a good practice of programming if we create a class for the object, where we have the constructor and make the methods and another class where we instantiate several objects of…
-
2
votes1
answer1041
viewsJava and Mysql - Error - Timezone
I try to connect with Mysql, with the code below. I don’t use Hibernate or anything. It is just to connect to the database and run a simple SQL clause. I get the error that is below. I see you have…
-
2
votes1
answer3802
viewsError trying to use Javafx 11 with Netbeans 9.0
I’m trying to update my version of Java to 11, but I cannot make it work on IDE. This error appears when trying to create a new project. I know that the JavaFX was taken from JDK from version 11,…
-
2
votes3
answers1642
viewsFirefox Error: Access-Control-Allow-Origin
response.setHeader("Access-Control-Allow-Origin", "*"); In the Chrome works normally. Even with the configuration Access-Control-Allow-Origin in CORS, Firefox gives error: (translated) Blocked…
-
2
votes1
answer93
viewsWhy does my synchronized method not work as expected?
I have a class called GerenciadorServerSocket: @Service public class GerenciadorServerSocket { private CopyOnWriteArrayList<Integer> portasUsadas = new CopyOnWriteArrayList<>(new…
-
2
votes1
answer2219
viewsAssertThat method and use of Matcher
To perform unit tests using the method assertThat in Junit, you need to pass an object Matcher as a parameter. public void assertThat(Object o, Matcher matcher){ ... } An example of using passing an…
-
2
votes1
answer89
viewsCreate a protected directory in the device’s Storage
Through an application it is possible to create, edit and remove both files and directories, but we know that it is necessary for the user to give permission to read and write depending on the…
-
2
votes2
answers103
viewsHow to check whether String[] Random Text is true or not
I’m creating a game at Android Studio and I need to compare if the text on the screen is that or not, to then present the tip. Ps: When using the equals get everything true by showing the message…
-
2
votes1
answer55
viewsProblem showing data Many to Many
I’m having trouble displaying the result of the query. I’m not being able to display the results correctly. I have the following tables and records: CREATE DATABASE IF NOT EXISTS `livraria`; USE…
-
2
votes1
answer149
viewsIBM Watson + Java
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package…
-
2
votes1
answer33
viewsAccessing resources with spring
Hello. I am having some problems recovering an image in a folder of my project. Here is a basic explanation of what I am trying to do: In my application a form is submitted and next to it an image…
-
2
votes1
answer197
viewsAccent problem ( -jar mysql)
Hello, I made a program in Java that inserts several texts in a database, running from my machine (Mac Os), everything works very well. But, putting in a VPS (Windows) for the program to run 24/7,…
-
2
votes2
answers66
views -
2
votes1
answer24
viewsYou can create @POST method with Jersey returning a List
Good afternoon! I am developing a Webservice where I need the query method to receive an object as a search parameter and return the list found in the database. I found several tutorials from…
-
2
votes1
answer97
viewsTreatment of the Arithmeticexception exception exception
Hello, is there any way to use the "Arithmeticexception" Exception in the division by zero in the same Try/catch and the program still show the results? When I enter the second value as "0" it…
javaasked 5 years, 8 months ago Diego Davi 23 -
2
votes1
answer594
viewsJavafx Tableview setting values to Tablecolumn
I ended up finding a problem that I believe is trivial but I don’t know how to solve. I have a class Seller who has an association with another class: Department. And I need a Tableview that…
-
2
votes1
answer459
viewsVery slow recursive Fibonacci method, what is the cause?
I made a program with recursiveness, but when the user type 50, the processing to generate the Fibonacci sequence is now over extremely slow. Is it due to data input/output processing on the…
-
2
votes1
answer257
viewsProblems with multiple inheritance and interface use
I am creating a simple bank system (studying), there is a Account class with basic registration information, and a System class that manages all accounts. I intend to create a class ContaDiretor…
-
2
votes2
answers2385
viewsHow to call a method of one class in another class
I had posted earlier but could not edit, I will try to be clearer this time. I am doing (trying)a code for Fonica account. I have class time, connection and contagion. in the account link class I…
-
2
votes1
answer173
viewsHow does an object return using addListenerForSingleValueEvent from fire base?
Hello, I would like to know if it is possible returns an object using Query.addListenerForSingleValueEvent() from firebase, follow example code... public static Passageiro getDadosUsuarioLogado() {…
-
2
votes1
answer123
viewsSocket with threads in Java
I have this code that involves socket TCP and threads. How do I get the server to send a message when the client connects? In this case the client sends the message and the result has to return to…
-
2
votes2
answers120
viewsHow to declare a vector with 2 positions?
I have an exercise with the following statement: Write a class whose objects represent students enrolled in a class. Each object in that class must keep the following student data: registration,…
-
2
votes3
answers67
viewsEvery time I run always print Invalid login
/* Make an algorithm that checks the login and password entered by user is correct. The algorithm must request from the user: login and password, and check on a set of 3 stored information…
javaasked 5 years, 7 months ago Gabriel Brito 21 -
2
votes0
answers22
viewsJava with Javafx
People I’m trying to make a thread call when opening the customer registration screen, but my screen is not opening, someone can help?? @FXML void OpenCliente(ActionEvent event) { try { //CREATING A…
-
2
votes2
answers106
viewsStandardization in building Rest api with Vraptor
Well I have a question about standardization in the creation of Rest endpoints. According to Vraptor documentation I can set the request path using the annotation > @Path("/paciente-api") here at…
-
2
votes1
answer86
viewsGenerate String from list contents
I have a class called CoreFiltroSearch that has a list of ICoreFiltro calling for filtros. Follows the class and interface: public class CoreFiltroSearch { private List<ICoreFiltro> filtros =…
-
2
votes1
answer138
viewsWhy does my program only work if I avoid parse Try catch?
I get a date from SQLITE but cannot understand where the error is, it is simply not visible. String dateValue = empDatadevolucao.getText() .toString() .trim(); SimpleDateFormat ft = new…
-
2
votes1
answer43
viewsHow do I compare one object type parameter to another (java)
I have the addCurso method that receives a parameter that is a course type object, it has information such as name and area, all within the College class, which has a vector where these courses will…
-
2
votes1
answer2891
viewsJava 8 - Browse list, change found case, if not, add
In a shopping cart app, I have inside the class CarrinhoCompras the following attribute: List<Item> itens = new ArrayList<>(); And a method to add item, which receives a product, its…
-
2
votes1
answer61
viewsSynchronization Java Web Method
I have a web application selling school canteen product, this process is accessed by several users simultaneously.. I have a method that updates and validates if quantity is available.. I need this…
-
2
votes2
answers67
viewsHow to programmatically rescue a newly inserted auto increment ID in JDBC?
I am saving a feature for time-consuming processing and must return your ID so the user can check its status in the future. The idea is that the user insert a set of data for import (for simplicity,…
-
2
votes2
answers104
viewsHow to return an integer when accessing an end-point?
I am trying to return a automatically created key in a spring-boot service (this one, by the way). I tried to directly return an integer by end-point: @RestController public class Controller {…
-
2
votes0
answers281
viewsArray in the jokenpo
I’m making a game of jokenpo and it should have an option of how many players (multiplayer) will play, which can be, 3 humans and 2 computers, or more. But I can’t get him to receive this option…
-
2
votes3
answers159
viewsScanner gives error if inverting the order in which data is read
When I put to read first the int and then the chain of string, the system works smoothly, but when I invert it gives an error and does not finish. import java.util.Scanner; class main { public…
-
2
votes1
answer1551
viewsHow to make monetary mask on Edit Text Android
Good morning gentlemen, I’m having trouble putting a monetary mask on an Edit Text, I checked several forums and tutorials but no method worked. My project is to basically make the customer put the…
-
2
votes1
answer260
viewsCall method with defined vector elements parameter
Good night! I have created a method that calculates the elements of a vector and makes the general mean, but I am not able to call it in the main method. PS: I am a beginner. Thanks for your help!…
-
2
votes1
answer181
viewsHow to control multithreading in parallelism?
I’ve tried using the methods wait() with notify and even the depreciated methods stop(), and did not succeed. I have three (3) threads which are: Tankcontroller Faucetfill Faucetempty What I’m…
-
2
votes2
answers147
viewsObject Array (not objects) in Java - How to use
Hello, I have the following task to do: I have three types of employees (Commissioned, Salaried and Hourly) and I have to add them to a list (ArrayList) to manage them. ArrayList<Commissioned>…
-
2
votes1
answer199
viewsConvert a file path to String
I’m in need of help, I need to read a JSON file (I’m using the GSON library), and for that I need to transform a Path variable to a String. Below is the code for better understanding. public void…
-
2
votes1
answer187
viewsHow to open an Activity when you don’t have internet?
I’m with a project that uses internet, and when there is no internet the same does not leave the menu because I put a lock access to other activit when there is no internet, but in did not open I…
-
2
votes1
answer192
viewsReplace HTML tag with text with regex
I need to replace an HTML tag (with a specific attribute) with a text, follow my example below: String stringTest = '<variable data-id="1" name="test2" style="background-color:red;">Variable…
-
2
votes1
answer219
viewsHow to reference more than one ID attribute using the jpa API?
My question is whether I can use the annotation @ID several times in a row, if this is possible or if there is another way to reference attributes of the type ID after the first. import…
-
2
votes2
answers1169
viewsException error in thread "AWT-Eventqueue-0" java.lang.Nullpointerexception
I’m doing a college project where I can register, change, delete and consult a product. In the query part, I try to search for the ID. Only this error happens and I am not able to solve. Exception…
-
2
votes0
answers39
viewsReturn an array in a java application
I’m making a java application that uses the neo4j database. One of the functions I call is to list all the contacts that have already been saved in the database, but I’m not able to implement the…
-
2
votes1
answer132
viewsHow to map a Map in Hibernate
I’m trying to map a diary to an apprentice, where in the diary I have a Map<data,mensagem>, that is, the date that was created and its respective message, but with the mapping that I did, I…
-
2
votes1
answer325
viewsEnum error with JPA + Hibernate
When performing a query in the database with JPA + HIBERNATE the following exception shall be made: java.lang.IllegalArgumentException: Unknown name value [Respondido] for enum class…