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
-
5
votes1
answer91
viewsIs it possible to make a mistake that triggers others?
Follow an example: public class Teste { public static void main(String[] args) { func1(); } public static void func1() { try { func2(); } catch (Exception e) { System.err.println("Error 1\n"); } }…
-
5
votes1
answer95
viewsWhere is the function taking the current time?
I have a function that returns the current time. Where does this value come from? Phone time? Server? Just follow my lead: public static Date getAgora() { Calendar calendar = Calendar.getInstance();…
-
5
votes3
answers177
viewsWhy does the this(6) command inside a constructor initialize the class array?
In the code: public class Lista{ int [] a; int n; public Lista(){ this(6); } public Lista(int i){ this.a = new int [i]; this.n = 0; } public static void main(String [] args){ Lista l = new Lista();…
-
5
votes1
answer944
viewsHow to switch between the next element and the previous element of a Listiterator with just one click?
I have a list of words stored in my variable listaPalavra already initialized with values, of type ArrayList<T>: listaPalavra.add("Palavra 1"); listaPalavra.add("Palavra 2");…
-
5
votes1
answer1734
viewsCode for calculating 2nd degree equation returns "Nan" as roots
I tried to create a program that calculates the two roots of a second-degree equation. When I run my code, it asks for the values of a, b and c correctly, but when showing the result, it always…
-
5
votes1
answer813
viewscannot be cast to java.util.Map
The method below that I created in the model layer, is returning me the error "cannot be cast to java.util.Map" public List<NotaFiscalProduto> listaItens (boolean entSaid, Date dtinicio, Date…
-
5
votes2
answers180
viewsIncorrect value in vector when binary search
import java.util.Arrays; /** * @author Vinicius * */ public class Vetor04 { /** * @param args */ public static void main(String[] args) { int vet[] = {3, 7, 6, 1, 9, 4, 5}; int s =…
-
5
votes1
answer154
viewsEclipse executes the ANT xml buildfile 2 times, even if it only has one run
In netbeans, after a few searches, I was able to edit the file build.xml in order to customize the way the IDE generated my jar and my manifest file. I had to migrate some projects to the eclipse,…
-
5
votes2
answers134
viewsWhen do I need to use a class that inherits from an Arraylist of a kind? I don’t understand what that’s for
Example: public class ListaAdapterItem extends ArrayList<Item>{ } And I got a class Item: public class Item { private int imagem; private String nome; private String descricao; public Item(int…
-
5
votes1
answer1828
viewsHow to present the correct accent on the return of cmd?
Considering a method to list files from a folder using ProcessBuilder I have the incorrect return of the accented words. Code import java.io.BufferedReader; import java.io.IOException; import…
-
5
votes2
answers147
viewsIn Java because (250 >> 4) is more optimized than (250 / 16)
I’m taking a Java course and in a class the teacher said that this code: int xstart = Camera.x >> 4; int ystart = Camera.y >> 4; is more "fast or optimized" than this code: int xstart =…
-
5
votes3
answers414
viewsClose connection in another method
I have a class called JavaConnect and in it I have two methods: ConnectDB and DesconnectDb. Connection class: public class JavaConnect { Connection conn = null; public static Connection ConnectDb(){…
javaasked 7 years, 11 months ago Leo Bufalo 333 -
5
votes1
answer1139
viewsHashmap manipulation between classes (Interpretation and Application)
is my first question, sorry for the length, I am in doubt in the following exercise: Create a Pizza class that has the added method Cooking() that receives a String with the ingredient to be added.…
-
5
votes3
answers543
viewsHow to display a multidimensional array without looping?
When trying to run the section below: int[] vetor = {1, 2, 3, 4, 5, 6}; System.out.println(Arrays.toString(vetor)); The array is normally displayed as [1, 2, 3, 4, 5, 6] but if I try with a…
-
5
votes1
answer7176
viewsI want to compare start date and end date. The start date always needs to be less than the end date. Compareto() an error came to me
When the final date is with the time of 00:00, it identifies that the initial date is greater than the final date only it is not, the initial date remains smaller. When I set the final date…
-
5
votes3
answers307
viewsIgnored line of code
The line marked with /*ISSO AQUI*/ is being ignored, ie the name for the second employee is not read, only the last name. import java.util.Scanner; public class EmployeeTest { public static void…
-
5
votes2
answers396
viewsconsume REST service with totalcross
I would like to know how to consume a REST service using totalcross. I made an example following what is in the documentation, I am using Httpstream. String url = enderecoWS + servico; HttpStream hs…
-
5
votes1
answer772
viewsConverting Textview value to double
Good afternoon, on my project I’m having the following problem. In it you have an Activity in which products are added. To add a product you need to fill the fields Name, Quantity and Unit Value.…
-
5
votes1
answer1210
viewsTest effective internet connection
I have an app where I do a connection test before consulting a webservice, just to display a message to user who has no internet connection. I use a method this way: public static boolean…
-
5
votes1
answer585
viewsEnable GPS within the app
Currently to check if the GPS is enabled use the following code: public boolean checkSetting(){ LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); return…
-
5
votes1
answer1677
viewsJdesktoppane background without losing quality and expandable
I have code to add a background image to a JDesktopPaneand it works perfectly on widescreen 16:10 screens. However, when the screen is a little wider (16:9), it does not fill the rest of the…
-
5
votes1
answer415
viewsTemporary variable performance within loop
During college a professor commented with me that declare a variable before a loop and reuse it was an economic and more interesting way to do it. For example (in Java): String str; for(Pessoa p :…
-
5
votes1
answer1139
viewsJSF is specification or framework?
In Javaee’s Github there is the repository javaserverfaces-spec that in his README.md says: Javaserver Faces (JSF) is a JCP Standard technology for Authoring Component based user interfaces on the…
-
5
votes2
answers697
viewsRegular expression supporting at least two of the four conditions
I am writing a regular expression for password validation. I wanted to know the easiest way to get a regular expression to accept, at the very least, two of these conditions: Capital letters…
-
5
votes6
answers8998
viewsSum of multiples of 3 or 5
I’m trying to build a program that finds and adds the multiples of 3 or 5 below 1000. The problem is that is returning a result of the sum that does not match what I asked. package basicojava;…
-
5
votes1
answer677
viewsComparison between dates
I am wanting to validate the inclusion of dates in my system, referring to the lot of products, but I believe I am a little hasty in the way I am doing. For what I need, I thought of three…
-
5
votes3
answers2851
viewsJava repeated letter counter
I made a method to count the repeated letters that are stored and ordered alphabetically within a list. The method is counting right but the bug is at the time of printing, it prints the letter and…
-
5
votes1
answer677
viewsWhat is the difference between getCanonicalName() and getName()?
To return the package name with the class name I always used the method getName(). However in that reply of @Articuno of the question: Customize the eclipse Generate toString() to print the path of…
-
5
votes1
answer705
views"No Persistence Provider for Entitymanager" for Hibernate 5.x
Well, you have to update the version of hibernate that was already I want to implement in my project to avoid bugs of the past version, but I’m having difficulty making the persistence in the new…
-
5
votes1
answer590
views -
5
votes2
answers1339
viewsHow to convert negative decimal numbers to hexadecimal
I was able to pass an integer number to hexadecimal. The problem now being tested is that the negative numbers do not work with this formula. This is the code I have: public class PPROG_pl6_ex8 {…
-
5
votes2
answers1584
viewsHow to avoid infinite recursion without using the Jsonignore annotation in Springboot
I have a relationship @OneToMany amid Produto and TipoProduto where a TipoProduto may have several Produtos and a Produto may have only one TipoProduto. I’d like to list all the Produtos of a…
-
5
votes1
answer2036
views@Enumerated(Enumtype.STRING) Hibernate JPA
I have the following field classificacao in a table. This field is filled in elsewhere and is filled with, only, 'P' or 'N', acronyms for Positive and Negative. I then created the enum Java.…
-
5
votes1
answer54
viewsLink does not send parameters and redirects to Servlet
I put on my index page where I have three links one with T-shirts, Bermuda and Pants on href I put so that when clicked on the link it was redirected to Servlet and sent the parameters according to…
-
5
votes1
answer146
viewsHow to view data from a serialized Java file?
I’m starting in Java and I need to make a system that registers students and saves their data in a serialized file. I can even create and save the data in the serialized file (I think rsrs) but I…
-
5
votes2
answers279
viewsConverting string to long int
I have an activity to do in which the teacher asks that the names of the numbers in the integers be converted (long int). I wonder if in Java there is any function that does this... I searched in…
-
5
votes2
answers156
viewsExecution of programs in pararelo WITHOUT use of Threads
They ask me to develop a Java program, to run programs (ls, firefox) in parallel that are contained in a file. For now I have the following code: File file = new File()`; List<String> lista =…
-
5
votes1
answer861
viewsHow to run DOS command in JAVA with Administrator privilege?
Hello, I have a program where I need to every run of it, go on the server, pick date and time, and change on the local PC. I am running the following command line: Runtime.getRuntime().exec('DATE…
-
5
votes1
answer2819
viewsUsing Switch Case for Ranges
My teacher passed an exercise in which we should use the cases of a switch to treat intervals, he strictly said that we should use the switch and we cannot use if and neither while/do. I’ve tried…
-
5
votes3
answers1175
viewsJPA + Wildfly + Hibernate
Is there any way to dynamically change the connection to the database by changing the file standalone.xml of Wildfly 8 (or 10)? Currently I have a class Hibernatesessionfactory that creates um…
-
5
votes2
answers432
viewsPermutations of an integer disregarding the zeros on the left
I have the following problem: Given an input n I have to calculate the number of possible permutations with the digits that compose it. For example, if n = 123 I have 6 numbers that can be formed:…
-
5
votes1
answer88
viewsHow to make atomic updates with Triemap and Concurrenthashmap?
In Java ConcurrentHashMap has an interesting property. Operations such as putIfAbsent, remove, replace, computeIfAbsent, computeIfPresent, compute and merge are atomic. Example: final Map<String,…
-
5
votes1
answer3287
viewsError using Mock: Wanted but not Invoked: Actually, there Were zero interactions with this mock
I’m making a list of exercises and I’m having doubts on the following: Question 3 - The Verify method, from the org.mockito.Mockito.Verify package, is used to check the amount of times a method is…
-
5
votes2
answers131
viewsFuncionameto Iterator
I’m having an absurd doubt with use of Iterator, I’m doing an exercise in which I have a Data class that checks the existence of the date, this is working perfectly,in my main I make an array of…
-
5
votes1
answer232
viewsTextfield click event conflicts like Joptionpane
I am learning how to create a sales system and created this method to take information from a Textfield and play within a table by clicking the enter button. I created a Try-catch to handle…
-
5
votes1
answer129
viewsDifferent regex strategies to get the same result
I have the following input: Detalhamento de Serviços nº: 999-99999-9999 I need to get the number in a group, for that I would use: Detalhamento de Serviços nº: (\d+-\d+-\d+) However I can’t trust…
-
5
votes1
answer396
viewsHow to expose a bean method to use spring dependency injection
I need to expose a method like a bean on ApplicationContext of Spring to use it in the injection of an attribute, which has more than one implementation. What I did was the following: I added the…
-
5
votes1
answer85
viewsWhat is the Java equivalent of this Ruby lambda?
In his text on Inversion of Control, Fowler uses as an example an excerpt of code in Ruby that promotes the said principle to "invoke a bind method over the text input field that passes an event…
-
5
votes1
answer64
viewsHow to know if the list contains so many elements that meet and do not meet a condition, using stream?
I have a list of columns, I need to know if this list contains both columns that are keys and columns that are not keys. I guarantee the existence of at least one column on the list My class of…
-
5
votes2
answers103
viewsHow to make an implicit conversion (inheritance) without losing information
Hello, I am doing a project for college where I have to implement 3 classes. These classes inherit from each other as in the model below: public class AssinanteFree { protected int id; public int…
javaasked 6 years, 4 months ago LeandroLuk 4,989