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
-
3
votes2
answers1846
viewsJava Spring Boot project version
I need to take the version value in my spring boot project to create a service that returns that value, the value in question would be version in build.Radle. group = 'br.com.xxxxx' version =…
-
3
votes2
answers313
viewsSpring data Jpa implement generic methods
I have 3 services with these methods in common create(),deleteById(),findAll(),getById() and update(). @Service public class AutorService {create(),deleteById(),findAll(),getById(),update(), etc...}…
-
3
votes2
answers385
viewsProblem with notification icon
I know there are several questions related to this. However, I have found nothing with my specific case. I will explain... I use the same code to display a notification both for notifications when…
-
3
votes1
answer156
viewsHow to manipulate several banks with Hibernate?
I am testing the functioning of Hibernate and I came across a question. I have the following configuration: Hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE…
-
3
votes2
answers82
viewsHow to instantiate Strategy objects
Consider the basic implementation of the standard Strategy. public class Context{ private Strategy strategy; } public interface Strategy{ void algoritmo(); } public class ConcreteStrategyA…
-
3
votes1
answer118
viewsData from Firebase takes a long time to complete loading and hinders sorting objects
I’m trying to sort an object by a value that comes from Firebase. I use a Jsonparcer class to list the database and according to the ID take the field I need in Firebase, which in this case is a…
-
3
votes2
answers57
viewsPage displaying error
I am beginner in spring with java and have the following controller and jsp Controller: @Controller //mapeamento do nome @RequestMapping("/hello") public class HelloController { //mapeamento do nome…
-
3
votes2
answers106
viewsInfinite Loop when reading Scanner values
My goal is to deposit in several notes (10, 20, 50 and 100). For this, in the method main left so: static Scanner lerInfo = new Scanner(System.in); public static void main(String[] args) { int nOpc…
-
3
votes1
answer101
viewsWhy is the "private" access modifier letting me change the attribute outside the class?
Well, I have this class with the attributes private class Conta { int numero; // Atributo private double saldo; Cliente user = new Cliente(); private double limite; } From what I understood of the…
-
3
votes1
answer709
viewsCustomization Spring Security 403
Fala galera! Follow my lead: I have an application with JWT authentication. The authentication is done in the database and I need to add now 2 more validations: failed count on login and registered…
-
3
votes2
answers503
viewsDeleting data from a MYSQL table with Java
I’m trying to delete data from a table with Java but for some reason the code is not working. Excerpt from the code below: public void excluir(ModeloObjeto modelo) throws Exception{ Connection…
-
3
votes1
answer763
viewsEnable or maximize program window
I have a JAVA program that uses Selenium Web Driver to access some pages and print them. I print by simulating the Ctrl+P keys and then Enter. The problem: There are several pages and several…
-
3
votes1
answer1482
viewsTurn String into Localdatetime
I created this Edit Fields button, to change the data of these users I created, the name, name and document are working, without the date of birth is updated, but when I try to edit the Date of…
-
3
votes1
answer1345
viewsDouble chained list - Java
I’m trying to create (I’m learning) a doubly chained list based on an exercise, in which the list will be a train with wagons. The exercise asks to create a class "wagon", where the variables "wagon…
-
3
votes3
answers1314
viewsHow to handle different date formats?
I have an application that at a certain time I recover the obtained date from the system, save it in a table in the database (Sqlite) and then recover it. The problem is that in determinator devices…
-
3
votes2
answers2455
viewsBuild error: "Resource Leak" when using Scanner
I’m solving a question from Deitel’s book question 3.17, but I have a problem in the main class (I’m doing it for Eclipse, in the Linux environment). The code is like this: public class…
-
3
votes1
answer1739
viewsError using scanner.close()
I’m trying to run this code in Java, using Eclipse. The same runs once normal. When trying to repeat the operation (choosing option 1) gives error as shown below. If I remove the scanner.close(); it…
-
3
votes1
answer84
viewsQuickly access exact element instance within List java
I have a list that will be filled with many points (x, y, z) - about 3000. Each point is unique within the list (no repeated points). At some point my program needs to recover the instance of a…
-
3
votes2
answers548
viewsHow to create getter and Setter from Arraylist?
I am creating a question and answer game, with the attributes: question, correct answer and the ArrayList option (private ArrayList<String> opcao = new ArrayList<String>();). I need the…
-
3
votes1
answer270
viewsFunction . filter() for a List<Class>
I have a class Pessoa that has the columns Integer id. String name, and String date_born. In my main Activity I am already retrieving the list of people that comes from my request made in the API…
-
3
votes1
answer56
viewsHow to make an interface method receive any object (Object type) as parameter?
I’m studying polymorphism now, and I’m not getting it. Given the interface: public interface View { public boolean existe(Object obj); } I have this method, which I would like to be implemented from…
-
3
votes1
answer94
viewsIs it possible to improve that part of the code?
I need to improve a part of the code. My problem is it’s too repetitive if and else, the bad news is that I will have more repetitive things on account that are different games. I can improve this…
-
3
votes1
answer563
viewsProgram to generate games and numbers of the mega sena
Unfortunately I’m not managing to generate more than a set of 6 numbers. The correct one would be to generate the amount of games that the user would type and would be stored in the variable jogos.…
-
3
votes1
answer1363
viewsUpdate JSF component via Bean
Inside my code I have two variables called displayMessage and displayImage that are two Strings, as the method is running, the messages are being updated. In my Managedbean messages are updated, but…
-
3
votes1
answer378
viewsJPA Deletes database data each time it restarts
Every time I restart the service, the data is deleted from the database. Has anyone gone through this and can you help? I am using Spring boot with JPA, Hibernate, Mysql, WEB and Rest. One of my…
-
3
votes2
answers88
viewsWhy isn’t my foreach cycle printing anything?
public static Iterable<String> select(Iterable<String> it, Predicate<String> pred) { ((Collection<String>) it).removeIf(pred); return it; } public static void main(String[]…
javaasked 5 years, 5 months ago Hugo Casanova 33 -
3
votes1
answer40
viewsonKey() method is not triggered as desired
I’m trying to capture the enter key to jump from one EditText to another. The problem is that the method onKey() is not called when I press a key, for it to run I need to hold the key for a while.…
-
3
votes3
answers333
viewsReturn text between keys, without returning the keys themselves
I used the following java regular expression to return strings that are between keys: \\{[^\\}]+?\\} My program worked almost correctly, but it even returns the key. Algorithm: public static void…
-
3
votes1
answer53
viewsWhy can I assign an instance of a class to a variable whose type is the interface?
Exactly what you mean when I create an object in memory, but I associate it with variable a1 interface-type (AreaCalculavel)? I’m a little confused, see below the example. package exercicio0101;…
-
3
votes0
answers959
viewsProblem saving date with Time Zone (Time Zone) in SQL Server
I need my system to store dates (date and time) with time zone (time zone). The system needs to support multiple databases, so far SQL Server and Postgresql. With Postgresql the time zone…
-
3
votes1
answer508
viewsHow to know if there is an element in a List index without error?
I’m trying to give a get() in the indices of a ArrayList, so that if there is something in those positions, I add that value with something else. Only if there is no such index, I would add it.…
-
3
votes1
answer1668
viewsInvert simply chained list
I did the implementation of a chained list and the method to list the elements, but I now wanted to print it upside down (For example: 1>2>3 = 3>2>1). Could someone help me?…
-
3
votes1
answer597
viewsHow to consume a message from a remote MQ queue using MDB on Jboss servers
I have an EJB class that writes a message in a JMS queue and would like to consume this message from a Messagedrivenbean (MDB) installed on another server. My class successfully writes in the JMS…
-
3
votes2
answers613
viewsConvert an Arraylist<String> into a String[]
I need to pass on the values that are in my ArrayList<String> for a String[] because I need to make a setInputData("INPUT",input). I mean, I want to convert the next ArrayList<String>…
-
3
votes1
answer363
viewsWhy when creating a Calendar, do I need to subtract 1 of the month?
When I create a product and call the constructor passing the parameters, including day, month and year, I’m not able to understand why I need to subtract 1 month in the method set, note below:…
-
3
votes1
answer134
viewsVariables and methods in the abstract class, where to put?
Cliente and Fornecedor has name, phone and email in common what is the best way for me to treat this, should I create these variables in common in the abstract class? or is there a better way for me…
-
3
votes1
answer116
viewsProblem to use a "System.out" on an object
I’m trying to give a System.out.println on an object I have (even with the toString() in class) I’m getting: Predio [name=LS, aptos=[[Lmodel.Apartamento;@7ba4f24f, [Lmodel.Apartment;@3b9a45b3,…
-
3
votes0
answers104
viewsHow to proceed to implement a Preparedstatement on Android?
We are using the Sqldroid to work as a JDBC driver for Android. However, Sqldroid is an envelope for Android API calls, and this API does not deal well with nulls. So, for us to use…
-
3
votes1
answer69
viewsComparison of index (get) in Array List not working properly
I’ve been trying to compare a string (right answer) for an alternative question as an example in a project I’m developing, but I can’t succeed in all the different ways I try. The goal is that every…
-
3
votes1
answer196
viewsHow to see the cpu usage percentage of each thread of a java process
Well, I have a cpu usage problem, and I don’t know exactly which class or Thread you are consuming ( there’s no way to know externally the code ), I was wondering if you have any method that shows…
-
3
votes2
answers408
viewsHow to identify if a number has been entered in the vector
Write a program that asks the user to enter 6 numbers of a lottery ticket in a vector and later check if there is the number 25 in this sequence of numbers passed by the user. I have a question, I…
-
3
votes1
answer293
viewsScan an Arraylist of objects and check an attribute of an object passed as parameter with an Arraylist
I am a beginner in Java and my teacher passed a list of exercises to practice, in a question I need to create a system that registers a user only if his email has not been registered before. A part…
-
3
votes2
answers95
viewsHow do I set contacts for a Phone object?
In class Pessoa declared a array of the kind Telefone which stores 3 phone contacts in the set referred to below it for each contact assigns a type and a number. I have a problem where I want to…
-
3
votes1
answer54
viewsDifference between changing a variable and a recurring object
I’m recurring in two situations: one changes an object field and the other directly changes the string. What is the difference between these two forms of return since it gives different result?…
-
3
votes1
answer2326
viewsSimple Java application error: Picked up _JAVA_OPTIONS: -Xmx4096m
I’m taking a Java course and I went to solve a simple exercise where I should read two whole numbers from the keyboard and show the sum of them. But in the console I get the error Picked up…
javaasked 5 years ago igortavtib 165 -
3
votes1
answer547
viewsRun a Spring Batch job several times
By default, Spring Batch does not allow you to execute a job that already has a complete execution with the same parameters. If you try to run, get the message: "A job instance already exists and is…
-
3
votes3
answers504
viewsJSON validation with more than one object
I need to send a JSON from a String. When reading a series as below, it works perfectly: json = {"resultado":" resultado 111","peso":98,"sinal":"-44","nome":"divergencia ativos","quantidade":12} But…
-
3
votes3
answers12331
viewshas been blocked by CORS policy: No 'Access-Control-Allow-Origin'
I am developing an integrated Java Backend (Rest Spring) with Angular Front 8. When trying to list the list of users(via JSON) I get this message: Access to Xmlhttprequest at…
-
3
votes1
answer88
viewsIs it possible to have a list as an attribute of a table in a relational database?
I’m doing a Java project using Sqlite as a relational database. Basically the project is a database of passwords, where a User can have several registered platforms and each platform having its…
-
3
votes1
answer77
viewsHow to express a predicate of equality in Java?
I have the following expression: final String idStatusAutorizada = ...; // valor constante return pendencias.stream() .map(TipoBlocCarga::getIdStatus) .anyMatch(idStatusPendencia ->…