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
-
12
votes1
answer2421
viewsWhat is the best way to store money in Sqlite?
Li that post on the lack of precision of double, and virtually every link in the post. Then I realized that this was a vulnerability of my software in production (since I have rounds to every corner…
-
12
votes2
answers965
viewsIs there any way to run a java program (.jar) from a C or C++ program?
I wonder if there’s a way I can write a program .jar, and write a C/C++ program that called the JVM to run the file .jar. Is it possible? If so, can you give me an example of code or an instruction…
-
12
votes1
answer660
viewsHow to optimize the game Battleship in JAVA?
I don’t know if this is allowed here on the site, so in case I’m breaking any rules let me know! I recently started learning the JAVA language. I made a naval battle game (human x computer) using…
-
12
votes1
answer3396
viewsHow does authentication with digital certificate work?
I want to authenticate via digital certificate in a web application. I have been able to read the data of my digital certificate that is connected to my machine. The question is: "How to…
-
12
votes2
answers490
viewsWhy is it not recommended to use Defaulttablemodel?
I searched some sites about how to fill a table in java and many suggested to avoid the DefaultTableModel? Why should one avoid using this class for more complex object cases? What does its use…
-
12
votes2
answers669
viewsJAAS or Spring Security on page control
I’m doing an Eclipse project with JSF 2.2, JPA 2.1, Hibernate 5, Primefaces 5.3, CDI (Weld 1.1). I want to implement the security part of the application and I’m in doubt between JAAS and Spring…
-
12
votes3
answers2210
viewsWhat is the purpose of the builder of an Enum?
In Java constructors are required to create an object in memory, i.e., to instantiate the class that has been defined. Meanwhile, I discovered that a Enum has a builder, but he is not a class, and I…
-
12
votes2
answers6600
viewsWhat is and how to implement a Java Listener?
Although I’ve already asked the Differences between listeners and Adapters in swing and also if Listeners are an Observer implementation?, I would like a more detailed explanation regarding. What…
-
12
votes3
answers1357
viewsIs it wrong to use multiple cases for the same action on the switch?
It’s wrong to do that with the switch? I programmed like this with him, it’s wrong? switch(estado){ case "AL": case "BA": case "CE": case "MA": case "PB": case "PE": case "PI": case "RN": case "SE":…
-
12
votes4
answers229
viewsIs overloading methods less performatic?
I was reading about interfaces as part of my studies and came across an overloaded class (overloading) methods, with two comments saying that it should be avoided. I was in doubt about it affecting…
-
12
votes1
answer191
viewsIs it correct for a method to make the same exception for two different reasons?
I’m practicing TDD simulating an alarm system. Alarm centers work connected to sensors that detect intrusion (opening a door or window, or movement within a room, for example). They have a fixed…
-
12
votes2
answers214
viewsWhat is the difference of var between Kotlin and Java?
With the release of Java 10, the possibility of using the var: var list = new ArrayList<String>(); I’ve seen the difference between val and varin Kotlin, but I would like to know more about…
-
12
votes3
answers1093
viewsHow to check if at the end of String is one or zero?
How can I check whether at the end of a string is 0? The problem with this code is that the string may contain: jrp_documento.jrp_doc_001fornecedor|0 My need is to check if at the end of the string…
-
12
votes3
answers1178
viewsWhat is the difference in use between the Matcher() and find() methods?
I’m trying to understand the difference in the use of these two methods of the class Matcher, but I couldn’t understand it from the description of the documentation that says: public Boolean…
-
12
votes2
answers360
viewsWhy are primitive types with floating points divided or multiplied by certain multiples of 10 displayed in scientific notation?
In this answer we can see that Java has a peculiarity when displaying the result in certain types of operations with primitive types that have floating point, such as division by multiples of 10,…
-
12
votes1
answer1140
viewsWhy should I use Joda-Time or not?
The question comes mainly based on comment from one of our most active users today and who has already demonstrated extraordinary knowledge in time use, especially in Java. the java.time API would…
-
11
votes2
answers2459
viewsCriteria API - Hibernate vs JPA 2
I will try to phrase this question in the least opinionated way possible in the spirit of stackoverflow in English. For a new project I need to make the decision between using the JPA 2 or Hibernate…
-
11
votes2
answers3208
viewsDifferences and use of Strings vs. Charsequence
Many methods in Java expect parameters CharSequence, but the code runs normally when I pass a String without conversion, for example: String mensagem = intent.getStringExtra(MainActivity.MENSAGEM);…
-
11
votes1
answer1892
viewsCheck whether a path is relative or absolute
I wonder if there is a Java function that checks whether the string is a relative path or not: Ex: String caminho = funcao("\\pasta\\arquivo.xml") // retorna true que é um caminho relativo String…
-
11
votes8
answers2292
viewsWhy create an object using the superclass?
Given the following code: public class Musico { public void tocaInstrumento() { // faz algo } } . public class Baterista extends Musico { public void giraBaqueta() { // faz algo } } . public class…
-
11
votes2
answers2940
viewsDraw path on the map
How do I draw a particular path using the Google Maps V2 API? What I want is something more or less like this: I inform the street A and the street B and get the drawing of the path between these…
-
11
votes5
answers61683
viewsUsing line break " n" in Java
What problem can a Java programmer have when using "\n" to jump line? Observing: I’ve used it for N reasons, record a file TXT and others.
-
11
votes2
answers14796
viewsTurn Byte into String
Problem: I’m getting byte and when I try to turn into String is making a mistake. ... byte[] msgBytes = ch.decode(hex, ch.key()); // retorna byte String msgDecode = msgBytes.toString(); // tentando…
-
11
votes4
answers1866
viewsHow do Stringbuffer() and Stringbuilder() behave?
Problem and Mystery: StringBuffer y = new StringBuffer("Eduardo"); I’m wearing a StringBuffer, because I need to add some values later to it. I was debugging and noticed that there is a blank at the…
-
11
votes2
answers536
viewsWhy invert the array index in a for, to popular the array, makes the process faster?
I was doing some tests in Java and I noticed a very strange behavior. I made an array with two dimensions and populated the array in two different ways, filling with random numbers up to 2 31-1 and…
-
11
votes3
answers7424
viewsHow to get the last business day of the month?
Is there a reliable Brazilian library of holidays that we can integrate and get the last working day of some month? Anyway, if there is no such library, how could I get the last weekday of any…
-
11
votes2
answers2686
viewsRunning JAR by Browser
I’m having a hard time figuring out how to do it: What I Wish I want to create a Google Chrome/Firefox extension that when I press a button in the html of my extension, it will run a file. JAR…
-
11
votes2
answers17877
viewsWhat are the syntax of the for loop in java?
Hello! Everyone programming in Java should be tired of using loops for, that almost always has a syntax similar to this: for (int x = 0; x < y; x++) { ... } I was analyzing some codes and came…
-
11
votes4
answers28007
viewsHow to read CSV files in Java
I am developing a web application, where after the user uploads a CSV file, my java application needs to read this CSV. Preferably separate the data into fields, for example to add these into a…
-
11
votes2
answers210
viewsHow to detect USB connection via application?
It is possible to detect a USB connection in my Android application and how to do this? I have a sync menu that is performed via USB and FTP, however I want to make the USB option accessible only…
-
11
votes2
answers1232
viewsUsing Java together with C
I am working on a micro controller project. My source is all in C however I would like to interact with this program using Java. Would that be possible? For example: The C program executes…
-
11
votes2
answers4523
viewsInner Class in Java, when to use?
Sometimes I find class codes with Inner class, such as: class ClasseExterna { private int a = 10; // ... class InnerClass { public void accessOuter() { System.out.println("Outra classe " + a); } //…
-
11
votes3
answers11380
viewsHow to copy objects in java
You can make an object copy in Java? MinhaClasse mc = new MinhaClasse(); MinhaClasse mc2 = mc; But I wanted to make changes in mc2 unaffected mc.…
javaasked 9 years, 6 months ago Messias Lima 199 -
11
votes3
answers238
viewsPrevent an action from being intercepted by the Interceptor Handle
I implemented a class to intercept some urls and check if I have a logged-in user in the session, if yes access url, otherwise I am automatically "played" to the login screen. It happens that on a…
-
11
votes1
answer255
viewsCanonicalized Mapping and Weakreference
I would like someone to explain the concept (and applications) of Canonicalizing Mapping and how your reference implementation would work using Weakhashmap.…
java performance memory-management hashmap garbage-collectorasked 9 years, 5 months ago Reginaldo Soares 2,256 -
11
votes3
answers191
viewsHas the standard Java output function accepted several parameters?
My teacher taught the class to use the System.out.println("Mensagem") this way for the class (the type of total_alunos it doesn’t matter): System.out.println("Existem ", total_alunos, " alunos na…
javaasked 9 years, 5 months ago Rafael Almeida 2,585 -
11
votes1
answer27744
viewsConcatenate Strings into Java Loops - Stringbuilder or '+'?
Java allows us to concatenate Strings in Java using only the operator '+' String str = "a" + "b" + "c"; It’s a simple way to do the job, and much less verbose than with Stringbuilder. But in cases…
-
11
votes1
answer1518
viewsHow to get hardware and system information?
I found only the class Runtime, but it returns only values in numbers, such as total memory and processors. Is there any API that returns data from hardware (processor version, RAM, architecture,…
-
11
votes3
answers533
viewsPure Java and Android App
I’m a beginner in Java. I preferred to start studying pure Java, that is, I discarded studying by dragging components. I met Javafx; I preferred to study the construction of these components at hand…
-
11
votes1
answer336
viewsWhy serialize object to send in another Activity?
What is the explanation for serializing the object both using the implementation serializable or Parcelable. I know this serves to create a new instance of the object in the other activity, but why…
-
11
votes4
answers634
viewsJPA List<Map mapping.. >
I have the following problem and I would like some advice on the best approach: Let’s assume you have a system that manages a school and would like to have the option for the system administrator in…
-
11
votes2
answers3004
viewsWhat’s the difference between using Fileinputstream and Fileoutputstream or Scanner and Printstream?
Is there any big difference between using these classes?
-
11
votes2
answers3445
viewsHow to create a program in C and use Java/C#GUI?
I’m studying graphic interface in C, and I realized it’s very complex and tiring. So I wanted to know if there is how I create a program in C and use graphical interface of Java or C#. With use of…
-
11
votes3
answers527
viewsPrecedence of operators
I have a question regarding the precedence of operators in Java. I have the following code: int x = 2; long y = 1 + x * 4 - ++x; Viewing the Precedence Table here. In my view the expression should…
-
11
votes2
answers384
viewsGMT returns -0306 instead of -0300, what is the reason?
Locale ptBR = new Locale("pt", "BR"); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyy", ptBR); SimpleDateFormat iso = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.sssZ"); GregorianCalendar…
-
11
votes2
answers1260
viewsJava future in Chrome - possible complications
According to this news from Techtudo Chrome will no longer support the NPAPI protocol used by java to communicate between java and Chrome I have many web programs that need java running, I wonder if…
-
11
votes1
answer1648
viewsDifference between method and constructor?
Reading a friend’s notes I came across the following statement: "method does not allocate space in memory". This statement is correct? It may not be the main difference between them, but it is…
-
11
votes3
answers242
viewsWhy do I need to declare a guy inside the "foreach"?
Why in a foreach we always need to declare a variable. Example: for(Pessoa pessoa : pessoas) { //qualquer coisa } In other words, I want to know why it is not possible to do this: Pessoa pessoa;…
-
11
votes2
answers335
viewsSplit a String dynamically based on screen size
I’m working on an android app and at some point I get a string from a web-service that is quite large, and the client wants this String (which will be shown in a Edittext) be divided into multiple…
-
11
votes1
answer886
viewsMultiple Controllers with Javafx 2, as a reference to each other’s instance
UPDATED. I am creating a new Java application using Javafx, when programming with Swing I had the habit of creating multiple specialized controllers for the interface, and in Swing I use a…