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
-
19
votes1
answer782
viewsCreate classes taking advantage of lambda
After reading this question made by utluiz, I could understand, even if in a more superficial way, a little of the usefulness of the expressions lambda added to JDK 8. However, in addition to the…
-
19
votes2
answers1128
viewsWhat is the difference of use between Keypressed and Actionperformed?
I ran some tests to see the difference in use, and apparently they both go off under pressure ENTER on the keyboard, as can be seen in the example below: import java.awt.*; import java.awt.event.*;…
-
18
votes2
answers6312
viewsDoubts about the toString() method of the Object class
I’ve been doing some tests with the method toString() class java.lang.Object and found that the obtained result changes with each execution, as the example below: Excerpt from the tested code public…
-
18
votes2
answers929
viewsOperator " | " in Java
I can’t find any material over the internet explaining the usefulness of the "|" operator in Java. I know there is "||" (or) used to test conditions. if(foo == 'a' || foo == 'b') But what about the…
-
18
votes1
answer6209
viewsDifferences between getClass(). getResourceAsStream() and getClass(). getClassLoader(). getResourceAsStream()
In the need to load a resource in my project I came across these two methods. From the choice between one of the two arose some doubts about which I would like to share here. What is the motivation…
-
18
votes2
answers994
viewsWhy use a generic return?
I was looking at the signature of the class methods Optional and I don’t understand what that means <T> in front of the return of the method empty(): public static <T> Optional<T>…
-
18
votes3
answers1132
viewsWhen to use finalizers and garbage collection in Java?
When to use the methods System.gc() and finalize()? I read that it is very useful in object orientation to destroy memory objects that are not being referenced and to finish tasks, but I see few…
-
18
votes8
answers2184
viewsHow to know all possible combinations of 0 and 1 in Java?
What possible combinations can I get only with numbers 0 and 1 using 5 digits (digits)? For example: 00000 00001 00011 ... 11111. I wanted to keep all the combinations, but I don’t know how to find…
-
17
votes3
answers506
viewsHow to instantiate a Gridview or a Listview for the same Activity?
In my app I am presenting a list of items. I would like in certain situations to be presented with a ListView and others like GridView. Situations are: Smartphone(Portrait) - ListView…
-
17
votes4
answers8554
viewsHow do LTRIM() and RTRIM() in Java?
I need to process some strings in Java. I know the method exists trim(), but I need a Left Trim and of a Right Trim. How do I do this? For now I’m walking the string with a loop and removing all…
-
17
votes2
answers964
viewsWhy doesn’t polymorphism work with Generics?
When trying to compile the following code I got an error. import java.util.*; class Animal { } class Cachorro extends Animal { } public class TestePoli { public static void main(String[] args) {…
-
17
votes2
answers3267
viewsWhen and why should we use polymorphism?
When and why should we use polymorphism in Java, because so far I’ve only used it to make multiple windows based on a model. The polymorphism the way I’m applying is better than making one window…
-
17
votes2
answers4679
viewsHow to get the list of devices connected to the network
I need to find the devices connected to the network on which my program runs. It is a network via Wifi (I do not know if this changes the difficulty of the thing), where I know that there are at…
-
17
votes1
answer5399
viewsWhat types of collections and their differences in java?
There are many types of java collections and I have difficulty knowing the following questions presented below: What are the differences between them? What situations and/or cases should I use each…
javaasked 10 years, 2 months ago Pedro Rangel 2,747 -
17
votes2
answers6315
viewsHeap of Java memory
I would like a simple explanation of what heap memory of JVM? I searched on Google but had no clear enough answer.
-
17
votes3
answers5444
viewsHow to calculate mathematical expressions in a string?
I’m making an application picks up an expression. How do I calculate the result of an expression? For example: 3(-9)+50/2. This expression is typed in TextView.
-
17
votes2
answers1806
viewsWhy does a calculation with positive numbers give a negative result?
Why does this one count (100 * 22118400) / 44954676 in Java gives a negative number? -46 /* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import…
-
17
votes1
answer2508
viewsHow to develop two versions of the same application, one free and the other paid?
I’m starting the development of an application for Android using Android Studio, I intend to make it available in two versions, one paid, with more features, and one free, more basic. I thought…
-
17
votes1
answer2610
viewsWhat is the Adapter standard?
What is and how the Adapter standard works in Java, I am trying to understand this pattern because I will use it in a project.
-
17
votes1
answer616
viewsDesigning the Top Gear
I’m trying to make a game like Top Gear (SNES) to acquire some knowledge about 2D games, only I came to a question about the tracks: they are straight, curved or images? I am using Javafx. If I try…
-
17
votes2
answers13314
views -
17
votes3
answers959
viewsWhy does calling System.gc not guarantee running the Garbage Collector?
Why the developer does not have full control over the Garbage Collector? I understand that the role of GC is to automatically manage the memory but why even using some method like the System.gc…
-
17
votes3
answers2390
viewsFind the center of each circle in the image
I have this image and wanted to catch the x and y of the center of each circle. I have tried several ways, but in none have I succeeded. My question is if there is any java lib to do this or any…
-
17
votes2
answers560
viewsWhy shouldn’t I change the "getter" s and "Setter"s?
I recently came across a friend saying that it is not advisable to change getters and Setters. I had made the modification of a Setter of a List. In it I did not receive a list by parameter, but an…
-
17
votes2
answers1267
viewsWhat is the difference between String[] args and String args[]?
What is the difference between the statements String[] args and String args[] in Java?
-
16
votes1
answer1315
viewsHow does Spliterator work in Java 8?
In Java 8 (which was released in March 2014), there is a new interface called Splitter. She has a purpose similar to Iterator, but is designed to perform parallel iterations. However, even after…
-
16
votes1
answer776
viewsHTTP cache headers in Servlets
I would like to know if there are libraries or solutions to treat requests containing headers as Last-Modified, If-Modified-Since, If-Range (for download summary), If-None-Match, Cache-Control,…
-
16
votes6
answers14835
viewsAndroid app development: what are the tools and language to start a project?
I would like to venture into creating apps for Android. At first I would make one just for own use. What tools would I need to build my development environment? My application would use database,…
-
16
votes3
answers2459
viewsHow useful are Java Annotations?
When I first studied Java, when I saw about Annotations I only saw that they are useful for generating metadata, but I didn’t see anything that influenced the behavior of the program. Basically, I…
-
16
votes2
answers3148
viewsWhy does everyone hate multiple inheritance in C++ and what’s your difference to mixins?
I’ve always heard that multiple inheritance in C++ is chaos. Why? It wouldn’t be technically the same thing as using mixins in languages such as Ruby? And what is this abstract class of Java? It’s a…
-
16
votes3
answers29267
viewsBarcode Converter - Convert Barcode to Digitized Line
I’m reading the bank note barcode, but found that the barcode does not exactly match (numerically) the digitable line (also called line code, numeric code or IPTE). According to a document from…
-
16
votes4
answers930
viewsBehavior of different ways of comparison in Java
If for example I have the code below, I am comparing the reference of the objects in the case ex1 and ex2 and not the object itself, correct? Pessoa ex1 = new Pessoa(); Pessoa ex2 = new Pessoa();…
-
16
votes1
answer24414
viewsWhat is Maven for?
I often find large projects that have the pom.xml file, but I never understood the usefulness of it, I just found out it’s something related to Maven. Finally: What is Maven for? What is the pom.xml…
-
16
votes4
answers14217
viewsHow to create/maintain "global variable" in java? To log in
I’m making a desktop application in Java. This application has a login screen (Jlogin) and one with the main application (Jprincipal) and I have a Login class with methods for database query and…
-
16
votes1
answer1022
viewsThe use of immutability
Immutability What are the advantages and benefits, when to use and why to use immutability in my projects? The complexity of the implementation x time, worth it? When I should not use immutability…
-
16
votes4
answers4276
viewsShould I initialize strings (or objects in general) with null?
I have noticed that a common practice among programmers is to initialize an attribute of a class with null. Is this good practice or not? Is there a difference between initializing with null or not…
-
16
votes2
answers1619
viewsMulti-core Cpus - Why doesn’t my application use all the processor cores?
I have a doubt I can’t find a convincing answer. There is an application developed in Delphi 7, and in an extremely complex routine (it takes about 2 hours) we notice that it is only used for the…
-
16
votes2
answers418
viewsHow does a Java Virtual Machine written in Java work?
Seeing the Jikes RVM I was curious to know how this works (in theory), but only found material in English. I am correct in assuming that the JVM today is done in C/C++, which in turn is done in…
-
16
votes4
answers1876
viewsWhat is the sense of an attribute being private and Static at the same time in a class?
I’m studying about the design pattern singleton, and in a code snippet on java, I came across a situation where I was in doubt. Below is the excerpt of the code: public class Conexao { private…
-
16
votes1
answer2540
viewsWhat is the difference between Javajdk and Openjdk?
I have been researching and from what I have seen both are kept Oracle skin... But if java is also open source, what is the need of Openjdk? Or I’m wrong about Java if open source?
javaasked 7 years, 6 months ago Marcos Rai Alves da Cunha 372 -
16
votes3
answers582
viewsMaven Module vs Java 9 Module
Besides the fact that Maven works with jars and Java 9 with "modules", what is the difference between the modularization system of the two? Why would I stop modularizing my systems with Maven to…
-
16
votes2
answers11683
viewsWhat is the difference between Arrays.asList and List.of?
Studying Java 9, I saw a new method that works with collections: List.of, example: List<String> frutas = List.of("maça", "laranja"); I’ve used it before Arrays.asList, example:…
-
16
votes1
answer1422
viewsListeners are an Observer implementation?
I’m trying to understand the concept of Observer and its implementation, and I ended up finding this example where it is used listeners instead of classes observable and observer: This graph has…
-
16
votes4
answers724
viewsJava: When to use Interrupt vs flags?
To indicate to a thread that it must "interrupt" its work Java provides a mechanism known as Interrupts: public void run() { while(!Thread.interrupted()) { // Fazer algo } } // para interromper…
-
16
votes3
answers2012
viewsWhy does Scanner return error on something that is within the expected?
Note that I have typed a number, a text and a number, as you ask there. import java.util.Scanner; class Ideone { public static void main (String[] args) { Scanner entrada = new Scanner(System.in);…
-
16
votes2
answers596
viewsWhy is there such a difference in performance between stream and normal loops?
I was reading a article related to the performance of streams/loops, and was startled by the difference in performance between the use of loops for large quantities of data. I decided to perform a…
-
16
votes2
answers437
viewsWhat is the difference between using @Transient and Transient in an attribute of a JPA entity?
Studying some third-party codes, I came across different ways to define that a particular attribute of an Entity will not be related to a column in the database. Among the shapes I found, the first…
-
15
votes4
answers805
viewsHow to use Simpledateformat in concurrent environments?
The class SimpleDateFormat is not thread safe. I recently had problems with class instances SimpleDateFormat in static context being used by multiple threads concurrently in a web application.…
-
15
votes3
answers1353
viewsArchitecture for a JSF Application with Android APP
I am in the planning part of a web application that I will develop for a Client. It will be Cruds and some report, nothing too complicated. At the moment I’m designing an architecture so that this…
-
15
votes4
answers3728
viewsJava client library for REST web services
I am in a project in which it is necessary to access a web service REST and I would like to know which is the most used Java library to access this type of resource in an easy way. I know it is even…