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
answers140
viewsMaximum number of classes in Java
I was doing some exercises of the course and I came up with a question. If I create a project in Eclipse and in it I will include my classes, assuming that each class is a specific exercise, each…
-
3
votes1
answer80
viewsRun function in android app when a button on a web page is pressed
I have an app (developed in android studio) that gets data from the accelerometer. Now I need to make a web page with a button, when the button of the web page is clicked, the data of the…
-
3
votes1
answer1778
viewsObject persisting problem with @Manytoone - JPA/Hibernate
I have the following problem: I can save/persist the two objects below, but JPA is not linking the ID of the DeclaracaoImportacao in the column ID class/entity . Follows code @Entity @Table (name =…
-
3
votes1
answer98
viewsHow to remove this shadow that appears when it reaches the "end" of the screen?
How do you remove this shadow using Android Studio? It appears when you finish scrolling the page.…
-
3
votes1
answer73
viewsCryptographic test diverging from class execution
I made my class in java for encryption using AES. However I went to test it on this site here: http://aesencryption.net/ Java class: text: test key: abcdefghijklmno1 outworking:…
-
3
votes1
answer58
viewsVraptor - Uploading files to IE 8/9 does not work
I’m trying to upload files and it’s not working on IE 8. OBS.: Works on Chrome and Firefox perfectly. I did some research and saw that the IE 8/9 can not stand FormData as enctype. Ex: <form…
-
3
votes1
answer93
viewsNullpointerexception when saving an object
I have a save methodRegister and in this method I save the company and its address, it saves the company first, but when saving its address occurs a Nullpointerexception Entity Address Person…
-
3
votes3
answers1706
viewsHibernate and JPA are the same thing?
It is a question of who just took this subject to study but confuses me a lot. I read some articles about ORM and did not understand very well what is one and what is the other, are the same thing?…
-
3
votes1
answer1397
viewsOpen camera/file by Webview
I made an application to open my responsive site using Webview from Android Studio. Wheel ok, but when I need to send some file through the site, take a photo and save, do not open the camera!…
-
3
votes1
answer67
viewsHow to write this java program using javascript and Node?
public class Principal { private static int x = 0; private static int y = 0; public static void sum() { x = y + 1; y = x + 1; } public static void main(String[] args) { for (int i = 1; i <= 10;…
-
3
votes2
answers3831
viewsHow to use vectors/arrays in Java?
Hello, I am very layy in Java and need to use a variable storing several others. How can I do this? I have the following: LatLng ponto1 = new LatLng(-19.924312,-43.931762); LatLng ponto2 = new…
-
3
votes1
answer2946
viewsHow to transform this Json into an object Arraylist?
I am working on a project where I am doing a database query and need to return a list of users from the database to be listed in my application. I have the following Json line (returned by the…
-
3
votes1
answer145
viewsHow to make an if by comparing a value with a list in an yml?
I get a request and want to check if that channel is in a list I created in yml. My method: private void insereNome (String canal, ListaNomeWebRequest listaNomeWebRequest){…
-
3
votes1
answer893
viewsHow to popular a p:datatable with a List<> that contains two List<> attributes inside?
I spent all day today trying to do something that’s supposed to be simple but I couldn’t. The thing is, I’m wearing the primefaces and I’m new to it yet and I need some popular way of my…
-
3
votes1
answer731
viewsReturn data obtained in Onresponse
How do I make the return of this String rest? If I give the Return there it does not accept... and if and at the end of the method and use an auxiliary variable runs the risk of returning a null.…
-
3
votes2
answers192
viewsAm I required to set the size of a Linkedlist in Java?
Since the LinkedList in Java is a double chained list, I understand that I could insert an element in any index I wanted, right? Or wrong? For example, I create a list and use the method add(indice,…
-
3
votes0
answers67
viewsHow to use a two-dimensional array to pick up the values of radioButtons?
I’m developing a quiz game in Android Studio with 10 activities. For each question I have only two alternatives where there would be 1 for the chosen alternative and 0 for not chosen. I would like…
-
3
votes3
answers1826
viewsObject search/registration via REST url and registration with SPRING
I’m new to REST and Spring. I am doing an exercise where I have to search a client via url and return (GET) it in JSON format and insert(POST) a client in JSON format. To search for sera in the…
-
3
votes1
answer294
viewsHow to convert the String "20190930120000[-3:BRT]" to Localdatetime
I got the following String: "20190930120000[-3:BRT]". I need to convert to LocalDateTime. Does anyone know the mask to be used in DateTimeFormatter.ofPattern("?????")? I’ve come this far:…
-
3
votes1
answer219
viewsWhat is the "real" meaning of the key word 'extends' in Java?
First of all, I know how to use and work the keyword extends, my real doubt lies in the meaning of that word, more precisely because extends and not inherit or something like that? The only thing…
-
3
votes4
answers246
viewsError using Collections.Sort()
Studying collections, I tried to use the following example in Eclipse: public class TestaLista { public static void main(String[] args) { List <Conta> list = new ArrayList<Conta>();…
-
3
votes1
answer298
viewsHow to set SELECT values in Textview?
I have the following class for bank appointments: package com.example.tais.books.Dados; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase;…
-
3
votes1
answer571
viewsHow to change the Jtable header background without removing the edge?
I’m trying to change the color of the background header of JTable. With this code I got: public Principal() throws UnsupportedLookAndFeelException { initComponents();…
-
3
votes2
answers373
viewsJava square (geometric figure)
I have an exercise that is to form a square with the number we are given. Here’s the code I made: int altura=5; int largura=5; for(int i=0; i<altura; i++) { for (int j=0; j<largura; j++) {…
-
3
votes3
answers843
viewsShow the amount of each alphabet letter in a String
I’m doing an exercise in Java where the user enters with a sentence. After that, I have to list how many letters there are in the sentence, for example: Input = Daniel Henrique Exit: A = 1 B = 0 C =…
-
3
votes2
answers223
viewsComparator - Priorityqueue
I’m building a comparator to then use inside a Priorityqueue. private PriorityQueue<Conta> listaOrdenada = new PriorityQueue<Conta>(new ComparadorConta()); The object I want to sort is…
-
3
votes2
answers106
viewsHow do I get a variable in another method?
I declared a variable within the class Main and I want to use it within a method, as I put it there? public class Main { static Scanner entrada = new Scanner(System.in); Aluno aluno = new Aluno();…
-
3
votes1
answer843
viewsProblem with Eratosthenes sieve - JAVA
My teacher passed the following class for implementation of the Eratosthenes sieve, but gave very vague instructions on how we should do it, although he made it very clear that we should only touch…
javaasked 8 years ago Leonardo Felix da Silva 33 -
3
votes1
answer5807
viewsPercentage in Java
Business rule: A program that receives the code of a user, the Qtd in Kwh q he consumes and the type of it that can be 3: each type multiplies the cost of energy consumed as the constants are…
-
3
votes2
answers383
viewsAbout method chaining. Why are you giving nullPointerException?
I got the class Request: package teste; import java.util.ArrayList; import java.util.List; public class Pedido { List<Item> lista = new ArrayList<Item>();; Cliente cliente; public Pedido…
-
3
votes2
answers1732
viewsWhy does if only work with the return of a method?
Follow my code that contains a boolean method: import java.util.Scanner; public class ativ16 { public static void main(String[] args) { int n, i, v[]; Scanner entrada = new Scanner(System.in); n =…
-
3
votes1
answer337
viewsHow to Call Values from Another Class
I am creating a vehicle control, and in it I have a register of Fuel that has description and value, and another record of Supplies. My supply record has a autoComplete of Fuel. The problem starts…
-
3
votes2
answers1007
viewsHow do I display what’s on the list?
I have this method that adds things to the list: public Pedido adicionarPedido(int quantidade, String nome){ lista.add(new Item(quantidade, nome )); return this; } And I’ve entered that class into…
-
3
votes4
answers422
viewsWhat is the best way to convert an int array to String in Java?
What is the best method to convert {1, 2, 3, 4, 5} for "12345" ? Example: int[] array = {1, 2, 3, 4, 5}; array.toString(); // Existe alguma função que faça isso? I know you can do it with a for loop…
-
3
votes1
answer79
viewsHow do I make the student registration number of the logged in account stick in the published table?
I am doing a rating project of a "college", I have the publication class and in it the method: public String NovaPublicacao(Connection conn){ String sqlInserir = "INSERT INTO Publicacao (Assunto,…
-
3
votes0
answers76
viewsHow to make pincode activator via serial?
I’m trying to do brush validator (serial), but I don’t know how to do it. I have two tables: "validation" and "maturity". In the "validation" table, you have the following fields: id(int),…
-
3
votes2
answers76
viewsI have a mistake I can’t identify in the println
These are my classes but still the error occurs: Exception in thread "main" java.lang.Nullpointerexception funcio20.Principal.main(Main.java:16) /home/Lucas/.…
-
3
votes1
answer508
viewsBreak java loop
My project in Java is a lighthouse control with Arduino. Up to there everything right. However I made a function in which the leds is automatic in a loop after a RadionButton be selected. My problem…
-
3
votes1
answer1606
viewsHow to read from a file and save to variables in Java
I’m having difficulties, because in a file manipulation exercise in Java, the teacher asked us to create a program that takes the name and note 1 and note 2 of two proofs and store in a txt file as…
-
3
votes2
answers168
viewsString.split() function with separator containing brackets and asterisk
I have the following code: String teste = "meta[[*]]etapa[[*]]especif[[*]]unid[[*]]qtd[[*]]01/01/2000[[*]]02/02/2000[[**]]"; String[] split = teste.split("[[*]]"); for (String string : split) {…
-
3
votes1
answer2002
viewsWhat is Java 8 Optional for? How to use it?
What is the use of Optional Java 8? How to use this feature? The best answers I found on the site were these... What is the difference between the orelse() and orElseGet() methods of…
-
3
votes1
answer128
viewsProcessing SQL statements with JDBC
I am trying to use JDBC, but having difficulties with the proper use of language. I would like to move the sql code down to java, and I need help with SELECT. Regarding the variables sql1, sql2,…
-
3
votes1
answer934
viewsModify String object value passed as parameter
I need to change the value of a variable dynamically by passing it as a parameter by an auxiliary method. I have always used the values of the parameters by moving from right to left. It is possible…
-
3
votes2
answers936
viewsRead file and save lines
I want to read a txt file recording each line of the file in variables of type String, (I use to save some data, of a basic program that I am doing) I thought of something like this try { FileReader…
-
3
votes3
answers77
viewsHow can I access a subclass method through a superclass-like object
Having an ABC super class public class ABC { int x = 0; public int getABC() { return x; } } public class XYZ extends ABC { int y = 0; public int getXYZ() { return y; } } Instantiating an ABC object…
-
3
votes2
answers782
viewsHow to use JUNIT to test void methods of my DAO class
Hello I have a DAO class and I want to implement tests with JUNIT, but many of the methods have the return void. Here’s a piece of the class that makes up the DAO package public class ExemplarDAO {…
-
3
votes4
answers1255
viewsIndex returning -1 in Java Arraylist
Good morning. For study purposes, I am making a simple application in Java RMI that simulates some operations (create account, check balance, debit etc.) on one or more accounts. For each account I…
-
3
votes4
answers1038
viewsHow to create a regex to filter and delete files with a particular chunk in the name
I’m trying to figure out a way to delete files that windows duplicates when making multiple copies. I was able to do something by creating the code below: import java.util.*; import java.io.*;…
-
3
votes2
answers91
viewsreplace more than one char utitlizando . replace()
I have the following function: public String replaceCharToNull(int row, int colum) { String result; result = (((String)jTableLoan.getModel().getValueAt(row, colum)).replace("x", "")); return result;…
-
3
votes2
answers1010
viewsRecursive search in all directories and Ubdirectories of a given folder
I am developing a script to scan a particular folder for certain files and delete them or move them to another folder, according to some rules I already got answered in this question and in this…