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
-
9
votes1
answer1858
viewsWhat are the differences between Hashmap and Hashtable?
What are the differences between HashMap and Hashtable in Java? Which is more efficient?
-
9
votes1
answer1492
viewsLibraries, interface, classes and methods
What’s the difference between libraries and interfaces? For example, on the line: import java.util.Scanner; The util would be the interface and Scanner the class? Or the util would be the library…
-
9
votes2
answers531
viewsDemoiselle Junit - Nullpointerexception
When running a unit test with br.gov.frameworkdemoiselle.junit.DemoiselleRunner, the following error is happening at the end of the test run: java.lang.NullPointerException at…
-
9
votes2
answers731
viewsPriority in progress
It is possible to prioritize a progressdialog before a Thread? In my app, after clicking a button, I need to freeze a progressdialog for 2 seconds. After that, generate a query to my webservice, and…
-
9
votes1
answer136
viewsArrayindexoutofboundsexception in Java 8 Parameter Reflection
I was making a code with Reflection in Java 8 when I came across a strange behavior - A ArrayIndexOutOfBoundsException unexpected. Based on this, I decided to create a minimal, complete and…
-
9
votes1
answer237
viewsKeyboard does not recognize Edittext
I have several EditText inside an item on my list ExpandleListView. Always by clicking on EditText appears the message below and is not typed text in the field: getSelectedText on inactive…
-
9
votes3
answers8723
viewsDifference between "Attribute" and "Instance Variable"
Reading some books and articles about introduction to Java and OO I realized that these terms are not well defined. Looking deeper I found different definitions in different sources on the subject.…
-
9
votes1
answer10051
viewsWhat is the difference between @Postconstruct and the constructor?
What’s the difference of using the annotation @PostConstruct instead of using constructor method and its advantages? I ask based on these two versions of the same class that only differ by this…
-
9
votes1
answer766
viewsWrite unit tests for the interface or for the implementation?
Given the following test scenario, where I have the interface: public interface UserService { /** * Registra um usuário no sistema. * * @param user * Usuário à ser registrado. Não deve ser {@code…
-
9
votes1
answer139
viewsHow does the data capture of a form work?
I have this code to get data from a form: @WebServlet(name = "computador", urlPatterns = {"/computador"}) public class computador extends HttpServlet { @Override protected void…
-
9
votes1
answer555
viewsLocation of specific points on maps
Hello I am developing an application that works with the Jxmapviewer library in the java language, one of the proposals is to find geolocation points (ex: stops/snack bars) in a certain street that…
-
9
votes2
answers1017
viewsAdd new fields dynamically
I’m creating a app calculating credits from a school report. DOUBT: How to add a new EditText when the user clicks on the "+" button next to it and sums up the values of each EditText.…
-
9
votes1
answer510
viewsHow to make Jtable values the same as Arraylist<Pessoa>?
I have an example program that adds objects of my class type Pessoa in a JTable and also in a ArrayList<T>, this program has three basic functionalities which are as follows:: Add Alter Erase…
-
9
votes2
answers2293
viewsWhat is the best (fastest) way to read a file from a web server?
I need to read a file on a web server, but when I need to store the content in an array of bytes it is taking too long. Does anyone know a faster way to do this? Follow my code. Thanks in advance.…
-
9
votes1
answer5620
viewsWhat is the difference between inner class, nested class and anonymous class?
I often read about these three types of classes when I’m researching something about java, but the truth is that it often causes some confusion about what each one of them really is and whether…
-
9
votes2
answers885
viewsDoubts about DAO, MVC, Multiple Tables and POJO
If anyone can help me, I have a question q has been consuming me a lot in recent days and is psychologically locking my studies (hehehehhe) MVC and DAO with multiple tables. I’m going to put here a…
-
9
votes2
answers521
viewsPerformance difference between multiple conditions in one IF or multiple IF’s separately?
During a change in a source code, I came across the following situation, developed by another developer: if ( booleano1 || booleano2 || booleano3 ) { if( booleano1 ) { //faz algo } if( booleano2 ) {…
-
9
votes2
answers450
viewsStatic blocks, heritage and constructors in Java
Hello, during my studies in Java I came across the following question Given the code below: class Foo extends Goo { static { System.out.println("1"); } { System.out.println("2"); } public Foo() {…
-
9
votes2
answers3664
viewsConnection to the Bank drops after a certain time
I have a server where I have several web applications connected to the database(Mysql). The problem is that if any system gets idle it loses the connection to the bank and I have to refresh the…
-
9
votes3
answers977
viewsHow to know the size of an object in memory?
I’m not after a method/operator sizeof because I already understand that JAVA doesn’t have it, but I need some way to measure at least on average how much memory an object spends, even if it is…
-
9
votes1
answer1218
viewsSort numeric vector without using Bubble Sort
We usually learn in college that, to sort integer vectors, we use a technique called Bubble Sort: int[] vetorOrdenado = new int[8]; vetorOrdenado[0] = 2; vetorOrdenado[1] = 41; vetorOrdenado[2] =…
-
9
votes1
answer690
viewsWhy is it better to use char[] than String for passwords?
Using Swing, the method getPassword() of JPasswordField returns a character array char[] instead of returning a String like the getText() (which by the way is discontinued). I should not use String…
-
9
votes1
answer207
viewsWhat is the difference between String name = "test" and String S4 = new String("Peter");
What’s the difference of assigning a value to a variable by creating an object and assigning Unboxing at a direct value? String s4 = new String("nome"); String nome = "nome";…
-
9
votes1
answer1020
viewsThe name of the dt_ultimo_access column was not found in this Resultset
I’m deploying a method passing an id parameter: @RequestMapping(method = RequestMethod.GET, value = "/entidadesUsuario/{id}", produces = MediaType.APPLICATION_JSON_VALUE) public…
-
9
votes1
answer1019
viewsEncrypt a phrase/word by reversing and switching vowels with the following vowels
I was given an exercise in which I have to write a program that reads a word in the interval [1-20] and encrypt this word using the steps: reverse the word where there is a vowel, replace with the…
-
9
votes1
answer264
viewsWhy does the compiler create repeated . class files?
I have noticed that when the java compiler compiles some class that has some swing/awt component, it creates another or even several classes of the same name, with a $ followed by a numbering. I…
-
9
votes2
answers1126
viewsWhat kind of data (double, float) should I use when representing a temperature?
My question is regarding the use of Double and of Float in Java exercises when having to declare a temperature (Celsius scale). Which one should I use in this case? I declared as Double, but the…
-
9
votes5
answers8188
viewsBest factor calculation algorithm
So I’m learning to develop in Java. The teacher asked me to develop a method for Factorial. And also show on the screen what is happening, for example: 3! = 3 X 2 X 1 = 6 In fact, I made it happen,…
-
9
votes2
answers128
viewsIf abstract classes and interfaces cannot be instantiated, what is happening here?
I discovered that interfaces and abstract classes cannot be instantiated, but my teacher gave me an example that left me in doubt, because it seems very an instance of interface ActionListener.…
-
9
votes1
answer503
viewsQuestions about Mysql integration with Java
I am creating a system in Netbeans, using the Java language and the Mysql database. I wrote the following code to make the connection between the program and the database: public class Conexao {…
-
9
votes3
answers1700
viewsEmbedded (Embedded) or external (traditional) application server?
There is currently a tendency to deploy Java applications as an executable jar on embedded server (Embedded server). There are very popular frameworks aimed at this approach as Spring Boot and Play.…
-
9
votes2
answers93
viewsMethod equivalent to Biginteger.and() in C#
I need to convert the java code below to C#: public static boolean verificaPermissao(BigInteger perm1, BigInteger perm) { if (perm1 == null || perm == null || (perm1.equals(BigInteger.ZERO) ||…
-
9
votes1
answer1343
viewsFullscreen Video on Android Webview
I have an application made on Android Studio using webview and runs a remote web application. The video is displayed perfectly on the webview. However, the option to fullscreen is not available in…
-
9
votes1
answer158
viewsHow to compare relative run time of fast algorithms?
The @Sorack asked the following questions about performance: What’s the most performative way to convert an int into the sum of its digits? What’s the most performative way to convert int[] to int?…
-
9
votes1
answer89
viewsCan the & (bitwise and) Java operator be used for interfaces?
Snippet source code from interface Comparator. Somebody explain to me how this is treated Comparator<T> & Serializable? public static <T, U extends Comparable<? super U>>…
-
9
votes4
answers11232
viewsJPA Object References an Unsaved Transient instance - save the Transient instance before Flushing :
When trying to save the "Addresses" of "Client" JPA/Spring returns me the following error in "main" Caused by: org.hibernate.Transientpropertyvalueexception: Object References an Unsaved Transient…
-
9
votes2
answers710
viewsSelect "maximum" elements given a certain criterion in a "stream"
I have a collection of elements that I’m going through in a stream. Suppose it is to take the highest value element (integer) given a classification (string). This class is enough to exemplify my…
-
8
votes3
answers2543
viewsUnit test with database
I have an application that uses JPA 2 with Hibernate behind and for unit testing, I use HSQLDB in memory with Junit 4.11. HSQLDB is configured in a persistence.xml file in a META-INF folder. My…
-
8
votes1
answer168
viewsProject that Imports Other Netbeans Projects
I have a project where is the whole part of Hibernate configuration. In the final project I will have some more projects (Personal Registration for example) that will need the project that has…
-
8
votes2
answers5688
viewsObject Comparison
The code below generates a false, but objects have the same attribute values, there is some method that compares objects, but their attributes, and not the object itself? Produto P5 = new Produto(1,…
-
8
votes3
answers2145
viewsHow to display the exception message(ex.getMessage()) launched by the server in a jquery ajax?
@GET @Path("boleto/{processo}/{resposta}") @Produces({ "application/pdf","application/json"}) public Response gerarBoletoDividaAtivaComCaptcha(@PathParam("processo") String…
-
8
votes2
answers17077
viewsConvert milliseconds to hh:mm java format
I’m making an Android game with a java engine where there is a Timer that runs all the time during the game... This timer is a millisecond counter and is added in a long. In the end I need to…
javaasked 10 years, 6 months ago felipe.rce 1,969 -
8
votes1
answer1324
viewsWhat do the security modules commonly used in bank websites do?
Most banks offer some kind of security module that acts on the client side for access to internet banking sites. They are usually made in Java and are usually quite boring to install. What exactly…
-
8
votes2
answers11631
viewsSubtract JAVA dates from picking the days difference
I need to calculate the day of pregnancy a woman is in, taking the information of the date when the woman became pregnant and the date of today. I have the following instruction: Date dtToday = new…
-
8
votes1
answer1111
viewsHow to ensure transactional atomicity in more than one concurrent Thread in a Java SE environment using the Spring framework?
A Java SE solution, using the Spring framework, is being developed in order to parallelize the execution of a Stored Procedure in Oracle 9i, Procedure which takes as parameter one or more lines of a…
-
8
votes1
answer606
viewsError Making Jar Build
I’m trying to do the build of my first JAR using the Intellij and Maven to manage dependencies. I created the artifact and executed build, but when I run the program I get the following exception:…
-
8
votes1
answer1127
views -
8
votes2
answers6768
viewsRun something after inserting a certain number of characters in an Edittext?
I wonder how to limit characters and run something then on Android. For example, in a EditText or a TextView type 5 characters, when typing the fifth character executes a command, for example, it…
-
8
votes1
answer4355
viewsHow to calculate the difference between two dates by ignoring weekends in Java without using a loop
I was looking for a solution to this problem but I did not find a satisfactory algorithm, so I decided to create the algorithm. I hope it fits someone. public int betweenDaysIgnoreWeekends(DateTime…
-
8
votes1
answer9291
viewsExecute cmd commands from Java
I wonder how I do to execute cmd commands in java. Well, I did that: import java.io.*; public class Commands { static final Runtime run = Runtime.getRuntime(); static Process pro; static…