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
votes1
answer48
views -
2
votes1
answer363
viewsSave and load objects inside a list
Hello, can someone tell me why it is only loading value, and the key is blank/void? Code I use to save and load: public static List<Pair<String, String>> cash_player = new…
-
2
votes2
answers104
viewsbootstrapValidator.js with jsf does not work
My validation script using bootstrapValidator.js <h:outputScript library="primefaces" name="jquery/jquery.js" target="head" /> <h:outputScript library="primefaces"…
-
2
votes2
answers499
viewsError android.database.sqlite.Sqliteexception: no such table: fs_promocoes
public class PromocaoDAO { private static final String DATABASE_NAME = "app_promocoes.db"; private static final int VERSAO_BANCO = 2; private static final String…
-
2
votes1
answer120
viewsHow to read objects from an XML?
I have an XML like this: <?xml version="1.0" encoding="UTF-8"?> <java version="1.8.0_101" class="java.beans.XMLDecoder"> <object class="java.util.ArrayList"> <void…
-
2
votes2
answers3265
viewsHow to go through Enum in Java
I have the following Enum: public enum TipoPokemon { FIRE("FIRE"), WATER("WATER"), GRASS("GRASS"), ELECTRIC("ELECTRIC"), ICE("ICE"), DARK("DARK"), GHOST("GHOST"), FAIRY("FAIRY"), PSYCHIC("PSYCHIC"),…
-
2
votes2
answers201
viewsAssociative class with double dependency
I was searching the internet and saw this way of making association between Java classes. Is it correct to make this type of association? 'Cause I did a lot of research on the Internet and I…
-
2
votes4
answers140
views"Enum" should be used to indicate business rule options?
Let me give you an example that is better: in the supermarket there are several categories of products such as vegetables, canned vegetables and others. To register more enumDo I have to change the…
-
2
votes0
answers98
viewsWhat is the difference between JVM, JRE and JDK
I have been researching and still do not understand very well the difference between them, mainly between the JRE and JDK. The JVM would be like the heart of Java, and besides I heard that it…
-
2
votes2
answers100
viewsAssigning Strings to a Date List
I need to assign for each day a list of dates of an interval period, a given String among three possible (Class A, Class B, Class C), so that the result is sequential until filling all the dates of…
-
2
votes2
answers645
viewsWhere should I place the Try/Catch blocks using MVC?
I am making a web application in java and I have some doubts regarding the block Try catch, I am using the standard MVC and I have the following codes: Controller: try { String pesquisa = "%" +…
-
2
votes2
answers886
viewscompare and remove repeated element
I have this array of objects, and I would like to scroll through and remove the repeated author by name, but I cannot. public class Pessoa { private Autor autor[]; int cont = 0; public Pessoa(Autor…
-
2
votes1
answer512
viewsProgram that read 3 numbers with repeating structure with scanner class!
How do I make a Java algorithm that reads 3 numbers and averages? I know how to do it without repeating structure, but how to do it with repeating structure? Follow my code below, but do not have…
-
2
votes1
answer516
viewsDifference between using struct and class to create an object
He had already "learned" object orientation in college, right on top of it. Now that I’ve started to revise I realize that no matter how much they say structs do not form objects, I really see no…
-
2
votes2
answers110
viewsDoubt using array
I would like to know why the index is used in the code 0 when a for to identify if the size of the array is smaller than the counter j. public class Aplicacao { public static void main(String[]…
-
2
votes1
answer37
viewsNullpointerexception when trying to log into the system inside netbeans
Soon after I did some icon overwrites on the main screen and on the About screen, error occurred NullPointerException, I have no idea how to continue and continue the course I am doing. I use Mysql,…
-
2
votes1
answer57
viewsIs this path valid for all devices?
I am developing an app. It has the function of saving image in an own folder of the app. And I am using the following code : File file = new File("storage/emulated/0/PastaTeste/");//PastaTeste é a…
-
2
votes1
answer379
viewsFormat numbers correctly in Java
I’m trying to use the NumberFormat to format some values in Java but it always returns the rounded value. I’ve done enough research to see if I can make it not happen, but I haven’t found anything…
-
2
votes2
answers1050
viewsAnnotation problem for mapping
I’m having errors due to my mapping to my java program, I’m still starting to mess with Annotation (I ask you to forgive possible stupid xD errors). Error must be on @Manytoone/Onetomany... I have…
-
2
votes2
answers125
viewsFormat string with durations
I have a time string with minutes, seconds and milliseconds. Example: 1:25.684 How can I format this String to a full hour format, filling with 0, to look like this: 00:01:25.684 String tempo =…
javaasked 4 years, 6 months ago Rodrigo Lima 315 -
2
votes0
answers483
viewsSpring Security Oauth2 in API Rest
Good morning. I have a Web Service Rest implemented and I am working on the security of it at the moment. This Web Service has been implemented using Spring Boot. Initially I will have as customers…
-
2
votes0
answers25
viewsJAVA - How to remove the default action from enter in a Joptionpane?
I have a Joptionpane with the "OK" and "Cancel" options. When navigating with Tab between them, even if Cancel is selected, by pressing Enter it pulls the default option, in case OK, and confirms…
-
2
votes1
answer360
viewsHow to search for ID’s in the bank and display the names on the screen?
In my JSF + Primefaces project, I have the following entities: @Entity @Table(name = "geracao") public class Geracao { @Getter @Setter @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private…
-
2
votes1
answer61
viewsHow does this code of turning the number into binary work?
I’m trying to understand this function that calls itself, but it doesn’t enter into the head as if it can transform a number into binary without at least a repetition, as it works? static int…
-
2
votes1
answer285
viewsProblems picking up accentuated files on Tomcat 8!
I have the same application on Tomcat 7 and in the Tomcat 8, only in the Tomcat 8 is a problem, I’m src of an image but in the image files it has an "not found" error accentuation, it follows…
-
2
votes1
answer607
viewsno such table: tbcarro
After following some examples, I am doubtful about the following error: 11-24 20:49:14.803 18215-18215/tiburski.rg.cadastrocarro E/SQLiteDatabase: Error inserting nome=ggggg modelo=ggggg placa=hhhh…
-
2
votes2
answers1688
views -
2
votes1
answer47
viewsIf B is a subtype of A, why is a collection of B not a subtype of a collection of A?
Dice: public interface A { ... } public interface B extends A { ... } private Set<B> bs = new HashSet<>(); RecebeA qualquerCoisa = new RecebeA(bs); Why does the last line compile if the…
-
2
votes2
answers558
viewsSave Image with Better Resolution
Hello, I am saving images in the database. But the resolution is very bad. I am using the following: btncamera.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {…
-
2
votes2
answers2545
viewsMove file list between folders
I have a method that copies files from one folder to another, then deletes the file. It suits me perfectly, but I wonder if there’s any way to do it without having to resort to InputStream and…
-
2
votes2
answers56
viewsData Binding Formatted Strings Losing Format
Apparently Data Binding for formatted strings does not work properly. For example: <string name="minhaString">Você tem um limite de <b>%s</b> reais.</string> If I use Binding…
-
2
votes2
answers2323
viewsError "is not an enclosing class"
I’m doing an exercise in Handler just to test how it works, but I’m trying some problem that I can’t understand. This is my master class code: public class MainActivity extends Activity { protected…
-
2
votes1
answer275
viewsWhat is the point of using Assert.assertNotNull() in frameworks?
I have seen in the Spring Boot framework that they use a lot of Assert.assertNotNull() to validate the variables if they are receiving null values. It is correct to use this same approach in…
-
2
votes2
answers98
viewsEvaluation of conditional expressions in Java
I’ve been observing that conditional expressions in Java that are formed only by literals or constants (or operations between them) are evaluated in different ways. Therefore, the code below…
-
2
votes2
answers46
viewsProblem to check list
I have a problem that I don’t understand because here’s the thing: When I go to add an item to the list, it has to check if that item is already in the list but it is not doing that.…
-
2
votes1
answer1069
viewsHow to access variables from another class of objects per array?
I have two classes, : Route and Costs. Route : public double getKmPercorrida() { return kmPercorrida; } public void setKmPercorrida(double kmPercorrida) { this.kmPercorrida = kmPercorrida; } public…
-
2
votes1
answer56
viewsWhy instantiating objects using new keyword is hardcoded?
I am learning Spring, and several times I have come across instructors solving the "problem" of instantiation of objects being made by keyword new, as in: private SpeakerRepository repository = new…
-
2
votes1
answer579
viewsConversion of Hibernate Result to json
I need help with the case of converting the Hibernate SQL result into json. I reached the stage that is converting correct, but the same does not come with the defined name of the column, and I was…
javaasked 7 years, 11 months ago Kelvin Stang Oenning 380 -
2
votes1
answer81
viewsNullpointerexception error while running while
public List<Produto> read(){ Connection con = ConexaoMysql.conectar(); PreparedStatement stmt = null; ResultSet rs = null; List<Produto> produtos = new ArrayList<>(); try { stmt =…
-
2
votes0
answers416
viewsValidation with Spring MVC
You guys talk beauty? Well, I started studying Spring by Algaworks courses recently and today I came across a problem, is the following: I have a form that shows me a list of employees, and as it…
-
2
votes2
answers221
viewsError in CRUD UPDATE command - java.sql.Sqlexception: No value specified for Parameter 8
I am building a Java system with connection to Mysql database, but I stopped at a certain point because I can’t locate the error. My update method happens an error in Junit, but I can’t figure out…
-
2
votes2
answers114
viewsIs there a way to interpolate strings in Java?
I’m starting in Java and found the path to concatenate String and variables very tiring. In Javascript, we can use `string ${variavel}`; in Python, 'string {}'.format(variavel) or f'string…
-
2
votes3
answers556
views -
2
votes1
answer1612
viewsThymeleaf does not find Sources
I’m creating a project with Springboot and Thymeleaf. I set up the whole project, I find the template and the pages, so my template can’t find the files css and js; Html <link rel="stylesheet"…
-
2
votes1
answer40
viewsError searching blogger information via json
I’m trying to get information from the blogger via json and put to appear in a recyclerview. But I’m not getting it. I’m a beginner in programming, so I’m unharmed if you have to sign any key so you…
-
2
votes1
answer3803
viewsHow to indicate in a regex that the symbols '(' and ')', the parentheses, are one of the alternatives in a list of symbols in Java?
I am developing a code that captures a text using regular expressions (regex). This text consists of parentheses. The point is that parentheses are used in regular expressions as a group definator…
-
2
votes2
answers333
viewsDelete data with the @Manytoone interface
How do I delete data with the interface @ManyToOne? It does not give error, but does not erase the data in the database. My class Pedido: public class Pedido extends GenericDomain{ @Column(nullable…
-
2
votes3
answers818
viewsHow can I set the address as the street and neighborhood corresponding to latitude and longitude?
I have that code: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == MAPA_REQUEST_BAIRRO){ if(resultCode == RESULT_OK){ try { Place place =…
-
2
votes1
answer132
viewsTrayicon with hidden console
I have a program in java, no graphical interface, just console. The only output commands are System.out.println(). I implemented it so the program would have a trayicon. The problem is that I only…
-
2
votes1
answer504
viewsHow to make this relief by hovering your mouse on a Jlabel?
The board is 500x500 and each square of it is 50px, so the variables NovaPosicaoX and Y always take the edge of the square where ta the mouse pointer. The problem is that the relief only works on…