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
votes1
answer66
viewsProblems with Nullpointerexception
I am making a Java application using primefaces 5.1 and was working correctly the part of deleting students in version 2.1 before upgrading to version 5.1. I am trying to delete a student, but this…
-
4
votes1
answer1765
viewsCan I have more than one builder per class?
The question is simple personal: I can have more than one constructor in the same class? At first, I will need to define the variable plugin in my object, then I will use the constructor that…
-
4
votes4
answers806
viewsAssignment of Java Arrays
I have two String Arrays and I have to compare them. After the comparison I must assign the repeated values in another Array. My problem is that I wish to assign only the Strings repeated without…
-
4
votes2
answers124
viewsJava: Copy file with 0 bytes
I backup the database normally and save it to a folder using getRuntime(). exec(). I use a very simple method to copy this file using Filechannel. But it turns out that the copy gets 0 bytes. It…
javaasked 7 years, 4 months ago Maycon Stanguine 104 -
4
votes2
answers137
viewsConstants of non-priminal types
In Java, constants are declared with sequences of Keywords static and final. When we have public static final int UM = 1; "makes sense to "call it constant, since its value cannot be changed. Now,…
-
4
votes2
answers65
viewsIs it a bad idea to automatically versize classes with Jibx?
Where work we have a project (very old) that uses Jibx to generate some classes from schemas. These classes are generated in build logo os source do not exist in the project. Someone gave the…
-
4
votes1
answer51
viewsHow to set content at position 0 with field disabled?
I need that when my component receives a text (it will receive through a query), the text is "set" at the beginning of the field, because in many cases, the text is extended and the beginning is…
-
4
votes1
answer1186
viewsHow to check if a File can be created in a Folder before trying to create it in it?
My program allows user to define a Folder, and later the program will create a New File in this Folder. However, the program is not able to create a File in any Folder, for example: Creates New File…
-
4
votes3
answers430
viewsReplace part of a Java String
I have repeating Strings, just changing a word. I have one case to assemble email content, but do not want to keep repeating the whole string, being that the only value that will be different, is…
javaasked 7 years, 2 months ago Guilherme Nass 939 -
4
votes1
answer2407
viewsDirect PDF Printing on Java Printer
So, I need to print a PDF directly to the printer, because I need to print Tax Notes.If I use this form Desktop d = Desktop.getDesktop().print("Caminho do arquivo") it prints normally the first…
-
4
votes1
answer510
viewsProblem with deploying to Heroku
I’m using Maven, Java, JSF, Primefaces, Hibernate, Mysql, CDI and Tomcat 8 on the local machine to create the app. Now I’m trying to climb up and I’m having great difficulty getting the project up…
-
4
votes0
answers368
viewsERROR: null value in column "id_municipio_id_municipio" violates the non-null restriction
This error is occurring when I try to persist the screen data to the database. I checked, by debugging the screen, that the data is being captured. When the method exits line 33 of the image it goes…
-
4
votes1
answer1031
viewsHow to maintain the screen ratio after being resized by the user?
I need to restrict a certain proportion of a Jframe so that the layout of what I want to display on it isn’t distorted, but I wouldn’t want to have to block resizing with setRezisable(). The minimum…
-
4
votes2
answers399
viewsCustomize the eclipse "Generate toString()..." to print the path of a class
How do I customize the function Generate toString() eclipse (source > Generate toString()) to print the path of a class? For example I have the following entity that prints: package…
-
4
votes1
answer590
viewsHow to create a mask for Jformattedtextfield?
I am making a program that simulates the Turing machine, and the user fills in a form with the states in this way {q0,q1,q2}. But I want to create mask that the user type only q0q1q2 and the value…
-
4
votes1
answer321
viewsHow to cut part of a bitmap?
I want to create a Bitmap that its content is a part of another Bitmap For example: I have a Bitmap (400x900) width = 400 height = 900 I want to cut it in the dimensions (400x400) in order to leave…
-
4
votes1
answer361
viewsChange button color at runtime
I asked for help on how to paint a button with 3 different colors: You can put 3 colors on a button? But I’m trying to change his color at runtime and I can’t. Even instantiating a new and…
-
4
votes1
answer1077
viewsHow to read a list of serialized objects saved in a java file?
I wanted to work with serialization in java files and I read this tutorial about how to write the object in the file and this one on the how to read the file object Then I created the following…
-
4
votes2
answers268
viewsProblem with Javafx
I have a problem when I add a JFX button that is present in the Jfoenix library. When opening my FXML document, it directs right to Scenebuilder, and inside it, to use all the items contained in the…
-
4
votes2
answers1903
viewsHow to convert Lowercase String to UPPERCASE?
My question is in switch (opcao). To perform one of the cases it is necessary to enter with capital letters. Is there any string or Java character conversion function from lowercase to uppercase…
-
4
votes2
answers684
viewsProblems assigning values to variables in an object
I need to pass variable data to another class called Fila.java. There I have a vector of the type that receives objects, so in the main class I created an object that I initialized as follows :…
-
4
votes1
answer533
viewsGet the frequency from a vector in the frequency domain
I was looking at the following topics: https://stackoverflow.com/questions/7674877/how-to-get-frequency-from-fft-result…
-
4
votes1
answer4003
viewsRecursive binary tree and leaf sum
Friends I’m having trouble solving this exercise, and I don’t know how else to do it. I even implemented the tree with recursiveness, but I couldn’t leave the NODE empty and some leaves with number,…
-
4
votes1
answer251
viewsGeneric and Comparable in Java
I have a question I can’t get answered, if anyone can give me a plausible explanation I’d be grateful. Assuming I have two classes: public class Figura implements Comparable<Figura> { private…
-
4
votes1
answer406
viewsSelf-signed Certificate Security ( Self-signed Certificate)
I am making a Java Client-Server system that will manage computers in a room, the scenario is as follows: A computer, the server, waits for connections, when an action is made ( Block Screen ) this…
-
4
votes1
answer236
viewscom.google.firebase.database.Databaseexception
I looked for that mistake and I didn’t find it anywhere, just a few similar but not this: com.google.firebase.database.Databaseexception: Maps with non-string Keys are not supported Controller…
-
4
votes1
answer126
viewsWhat is the most performative way to convert an int into the sum of its digits?
I have a certain int and would like to turn it into another that is the result of the sum of your digits in the best possible way. For example: int n = 2601; Should result in 9 since this is the…
-
4
votes2
answers350
viewsWhy is it necessary to close file?
Why is this line required in Java? fout.close(); Context: LinkedList values = new LinkedList(classe.getTurma().values()); if (!values.isEmpty()) { FileOutputStream fout = null; String FILE =…
-
4
votes1
answer255
viewsWhat is the need for an interface to have abstract methods?
We know that in an interface the methods do not have implementation, only signature, ie only the definition of their methods without the body, we conclude then that all are already methods Abstract,…
-
4
votes3
answers1657
viewsConvert string to blob and save to bank
I’m developing a mobile application that has a form where the user can attach an image, the image is being sent as string via Rest to the server and will be saved in the blob database, however, I’m…
-
4
votes1
answer348
viewsValidation of quantity of sessions with spring boot and spring security
I need to validate the number of sessions that may exist, so that the user cannot log into two places at the same time with the same credentials. Reading the Spring Security documentation and posts,…
-
4
votes1
answer397
viewsJava Priorityqueue Comparator
I’m trying to understand why the native mode of java is not performing the comparison, I don’t know where I’m going wrong. MAIN // EXERCICIO PARA COMPARAR DOIS OBJETOS, USANDO CLASSE NATIVA DE…
-
4
votes1
answer434
viewsHow to create a random number of 5 digits starting from 1?
I have to create a bank account with some requirements, in the middle of them I need to have a 5 digit starting number of the 00001. But when putting "00001" at the time of displaying only displays…
-
4
votes3
answers1162
viewscreate objects dynamically
I’m having a problem in college in software engineering which is the following: I have the following scheme when making the payment of a shopping cart I must know if it is BOLETO or…
-
4
votes2
answers636
viewsI calculate Java water consumption using Eclipse IDE
I’m having a hard time writing this exercise in the Java Language, using the Eclipse IDE: The director of a state school in the city of São Paulo is terrified by the absurd consumption of water that…
-
4
votes1
answer426
viewsHow to make more than one panel transparent?
Implementing the answer of this issue, i managed to make a panel transparent. However, in order to organize the way I want, I wanted to use more JPanels, with different layout managers. But when I…
-
4
votes1
answer112
viewsProgram enters infinite loop
My goal with the code was to put together a game that asked the person what number the computer would be "thinking" (from 1 to 100), and as the person said a number from 1 to 100, the computer said…
-
4
votes1
answer888
viewsConverting String to Arraylist
I am receiving in my java code a variable with the following value String arquivo = "CNPJ;INSCRICAOESTADUAL;COD_IBGE;DT_OPE;VLR_CARTAO_CRED;VLR_CARTAO_DEB 35083840049;0;4312476;13/01/2018;0.00;66.00…
-
4
votes1
answer131
viewsDifficulty in using Datepicker
I’m studying things for a project here and I’m trying to use Datepicker, I managed to implement normally, but I want to use two in the same Activity, putting an initial date and an end date, put two…
-
4
votes1
answer664
viewsWeather API - Cities with accent give error
I have the following Endpoint in which you receive in the URI the name of the city and the state: @RequestMapping(value= "/clima/{nomeCidade}/{ufCidade}/agora", method = {RequestMethod.GET,…
-
4
votes1
answer1006
viewsOverload method is polymorphism?
I’m having trouble understanding the concept of polymorphism in Java, I read two articles of the same portal now and I was more confused, because for my interpretation they contradict each other:…
-
4
votes6
answers2089
viewsCheck if a String contains two words
I have a problem with this exercise here: Write a class that validates data (Validacao), with a method to validate a given name (ehNomeValido(nome)). The method must return true pass the following…
-
4
votes2
answers95
viewsWhat is the best way to define access to the methods of a class I want to use for unit testing?
I have a class Runnable, that does a lot of things in my system. When I created it, I didn’t want to instantiate its methods out of her scope. That’s why I wrote the methods like protected. Now, I’m…
-
4
votes1
answer275
viewsError in java second degree equation algorithm
Good morning, could someone help me understand why my code is not doing the correct processing and why my conditional deviation is wrong? public void cap4ex3e(){ double a,b,c,delta,x1,x2; Scanner in…
-
4
votes1
answer157
viewsProblem generating javascript graph using Spring
I’m implementing Graphics in a web application I’m developing in Spring. I already made my API, it is bringing Json with all the information of my object Cart, however the graphic is not being…
-
4
votes1
answer247
viewsSonarlint, complexity of the "equals() method"
Sonarlint for Eclipse, accuses error: Refactor this method to reduce its Cognitive Complexity from 64 to the 15 allowed. Rewrite this method to reduce your cognitive complexity of 64 for 15 allowed…
-
4
votes1
answer99
viewsIs it possible to change a String of a method at runtime?
If I have one String fixed within a method is it possible to change it using reflection or something like that? Example: public static void main(String[] args) { String nome = getName(); boolean…
-
4
votes1
answer402
viewsHow to convert a list of Strings to an integer list
I have TXT file, and it lies like this: 01 02 03; 01 02 04; 01 03 04; 02 03 04; Well, I upload this file on ArrayList<String> as it is in the code below. How do I pass it to…
-
4
votes2
answers110
viewsHow to do for every time you pass "true", it print the entire instantiated object?
import java.util.ArrayList; public class Loja { private ArrayList<Produto> ListaDeProdutos = new ArrayList<>(); public void cadastrarProduto(Produto produto){…
-
4
votes2
answers594
viewsWhat is Java Sort?
Every programmer know that a list of arrays are printed in an orderly way, but in the middle of the way sort(). The result of the impression was this: Abacaxi Banana Laranja Manga I thought it would…