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
-
14
votes4
answers1231
viewsVery interesting switch/case on Swift - What other languages support this?
The Swift language presents a very interesting and very intuitive way to work with intervals using switch-case, with "partial matching" techniques, "Pattern-matching" etc, look at these examples:…
-
14
votes2
answers1053
viewsProblem of the Byzantine Generals. How to implement a solution?
Initial considerations I’m conducting a survey on Bitcoin and bumped into the concept of Problem of the Byzantine Generals, where the creator of Bitcoin - Satoshi Nakamoto - wrote "Bitcoin: A…
-
13
votes3
answers514
viewsJava / Android: how to view Stacktrace log
How can I display the whole exception error code (Fullstacktrace) in Android Log? try { //CODE }catch (Exception e){ Log.e(TAG,e.getStackTrace()); }…
-
13
votes1
answer443
viewsIs an immutable Enummap thread safe?
An immutable map built on top of a EnumMap could be used in multi-thread environment or there is some risk of competition problems? public enum MyEnum { VALUE1, VALUE2, VALUE3, VALUE4; } private…
-
13
votes1
answer1462
viewsUse Resultset without knowing the column type
I need to use a Resultset that returned the data of a query in the database. I’m making a very generic class, it can be used in any table, so I don’t know what kind of data it’s returning. For…
-
13
votes2
answers1894
viewsHow to align strings to use in a listview?
In my Android project I need to create a table with a listview but the data always comes misaligned. I place each record of my database in a position of a string array to use it in listview. The…
-
13
votes2
answers2267
viewsWhat is the best way to run a java application as a Service on Windows (32 or 64 bit)?
What you need to do to run a Java application (no visual interface) as a Windows service. The program basically uses the Filesystem API and the network API (java.net, java.io and java.nio.) If it is…
-
13
votes3
answers6699
viewsConversion of JSON string to Java object
I am trying to convert a JSON string into a Java object used by Gson. This is the json I get from the webservice: {"concurso": { "numero":1499, "data_sorteio":"01\/06\/2013",…
-
13
votes3
answers711
viewsExtend classes with private constructor
Because I can’t extend classes with private builder? Consindo the classes To: public class A { private A(){} public static void limao(){} } and B: public class B extends A { private B(){} public…
-
13
votes3
answers3561
viewsJava and Offline Databases
I need some help with a Java database. I want to make a database that the program generates a file, such as "database.db" and this file I can access without any internet connection, using only the…
-
13
votes6
answers1170
viewsWhy is it not possible to define an interface with static methods?
I would like to force some of my classes to be implemented in Singleton, but I came across the following situation. interface ICharacterSingleton{ static Characters getInstancia(); } public static…
-
13
votes1
answer5489
viewsHow to create directory with a path that works for any OS?
I am doing a job in Java and I need my program to create a directory in the user’s "home" folder, but it needs to be able to create both in Linux and Windows. It is possible to create a "generic"…
-
13
votes1
answer369
viewsWhat tags can I use to document my code?
I’m looking for better ways to document my code in Netbeans. Besides the tags known and used in Javadoc something caught my attention and aroused my curiosity. When typing {@ some suggestions of…
-
13
votes2
answers477
viewsJava Performance of methods-filled and empty classes
If I create a class whose goal is to group a number of related methods. Suppose a Class Boi{} and it has several methods but no element. For example: public class Ruminante{ public String…
-
13
votes1
answer593
viewsAnti-aliasing algorithm in Java
I’m using the method setRenderingHints from the awt library to do anti-aliasing. The method provides a significant improvement in the rounded 2D objects. How does the algorithm work? What are the…
-
13
votes1
answer796
viewsHow to treat exception in a Webview?
I wanted to know how to treat exceptions in my Webview, because sometimes the site ta off, and the page does not load, and sometimes even crashes the application. I tried a try catch no load, but…
-
13
votes2
answers668
viewsWhy is a Fibonacci faster in Java than in C?
Not exactly like this, but I noticed that when the function needs more time to compute Fibonacci, Java actually does better than C. Here are the implementations: C: #include<stdio.h> unsigned…
-
13
votes4
answers570
viewsExtend x Superscript, what’s the difference?
Researching on concepts of Object Orientation, I came across the following comparative, Extend (Heritage) versus Superscript. I found the following statement for this comparative: Extend: When we…
-
13
votes3
answers753
viewsDoes Java have a class to work with command line arguments?
I need to create a Java desktop app, and with it pass several parameters of the type: java meuapp.jar -DB c: base.db -user admin -password admin Is there an easy way to get these parameters?…
-
13
votes1
answer755
viewsDifference between casting and Promotion
What is casting? What is Promotion? What is the basic difference between these Java conversion types?
-
13
votes1
answer487
viewsChange the scroll of spring-security by bean
I’m using the spring-security to authenticate my user, until then beauty, now I want to be able to exchange the user’s role for managed bean, someone has an idea? Type I have several modules and…
-
13
votes3
answers600
viewsWhat does this() do alone in the builder?
In the code: public Livro(Autor autor) { this(); this.autor = autor; } public Livro() { this.isbn = "000-00-00000-00-0"; }
-
13
votes1
answer568
viewsWould it be right to leave the attributes of the abstract class as private or protected?
I don’t know how I should leave these attributes.
-
13
votes2
answers13163
viewsHow to make the Genericdao class using Hibernate?
I wanted to know how to make a generic Dao of a project, using Hibernate and JPA in java. All this to not be mounting a DAO as follows for each object that will persist in the bank: public class…
-
13
votes1
answer1010
viewsAndroid Studio does not open new project (stay transpatente)
when I installed and tried to open for the first time, it worked perfectly, however, when I tried to open again later, when I click on "Start a new Android Studio project", the window opens, but is…
-
13
votes2
answers791
viewsApprove or refuse a request through Handlerinterceptoradapter
It is known that all requisitions by @RequestMapping are "public", where any user can access them through the browser. The question is, how to approve Requests where only the system can request and…
-
13
votes3
answers1684
viewsWhy Arrays start at 0 and not 1
Why arrays start at 0 and not 1 ? There is no 0 people, 0 animals, 0 nothing...(do not cling to this part) What is the point of doing this? I believe that it should not be just me who does not…
-
13
votes1
answer1046
viewsWhat are the differences between Treeset, Hashset and Linkedhashset?
The idea of Set is to not allow repeated elements, in java there are three implementations TreeSet, HashSet and LinkedHashSet found some differences in that reply, would like to know in detail if…
-
13
votes1
answer333
viewsWhy are arrays covariant and generic are invariant?
Arrays in Java are covariant, that is, it’s perfectly cool to do something like: Number[] meuArray = new Integer[10]; Generic types are invariant. The line below does not compile: List<Number>…
-
13
votes1
answer1056
viewsWhat are layout managers and why should they be used?
When a graphical interface with the API is being developed swing of java, end up having to mess with the positioning of components on the screen, which induces us to learn about layout managers so…
-
13
votes1
answer87
viewsHow does the compiler know the difference between the type I’m using in downcasting?
The classes Felino and Ave inherit from Criatura, the values are hypothetical only to inform the difference between specialized attributes. Criatura c1 = new Felino("Preto", true); Criatura c2 = new…
-
12
votes2
answers4872
viewsWith the output of Viewscoped from the new JSF specification, what scope do I use now in my managed Beans that used it using JSF 2.2?
I have a big question now with the appearance of JSF 2.2: What to do with my views and my old Beans Managed? How to do it now (what scope to use) since I can no longer use view scoped in a view that…
-
12
votes2
answers372
viewsHow to create regexReplace for a delimiter?
I have the following content: 123|321|1234\|56\|teste\||123 I’d like to make a regex replace to replace all | by line break and ignore the | escaped with \, this way I would like to get the…
-
12
votes2
answers235
viewsHow to avoid an Illegalstateexception: The content of the Adapter has changed but Listview Did not receive a notification?
I have a Activity that displays a ListView, to which a Adapter "backed by" a ArrayList global. If I add an element to that ArrayList, ideal is to do it in the main thread and immediately call…
-
12
votes2
answers294
viewsCuriosity about equality of Integers
Why System.out.println(Integer.valueOf("0")==Integer.valueOf("0")); System.out.println(Integer.valueOf("1000")==Integer.valueOf("1000")); returns true false ? ps. I know that == is different from…
-
12
votes2
answers4725
viewsImage rotation in java
I need an algorithm to rotate an image in java. On the Internet I found a promising algorithm at this link, and I tidied it up and adapted it to use angles in degrees. It was like this: public…
-
12
votes4
answers77025
viewsHow to run . jar with prompt?
I’ve managed the jar file for Netbeans, but I’m unable to run the program at the command prompt. What command to run it in Windows environment?
-
12
votes2
answers7355
viewsIs it better to parameterize your Preparedstatement even if the value is fixed?
I always read the blog Java Revisited and I’ve been reading the article today Why use Preparedstatement in Java JDBC - Example Tutorial. At a certain point the author talks about parameterization of…
-
12
votes2
answers2282
viewsHow to do binary search in a txt file?
I am with a txt file that stores data from several books (example below) I would like to make a binary research that returns the line that is with the first field (ISBN of the book) equivalent to…
-
12
votes2
answers13989
viewsWhat is the function of the super in a Java constructor?
I have a daughter class that inherits from another abstract class, and in the class builder I have the following: Public aluno(String nome, int idade){ super(nome,idade); } What is the function of…
-
12
votes1
answer1866
viewsWhat is the difference between printf() and print()?
I was doing some simple algorithms in Java and most of the time it is used System.out.println() or System.out.print(), but to make the definition of the number of decimal places I am using…
-
12
votes2
answers2347
viewsWhy does my Try/catch only accept "Exception and" (Generic)?
I want to specify the exceptions, not in this general way but the item.write only accepted Exception e public File saveFile(FileItem item, File dirFile, String filename) { dirFile.mkdirs(); File…
-
12
votes3
answers10773
viewsIs it possible to use Java pointers?
In the C language we can use ponteiros as follows: int *ponteiro, teste; ponteiro = &teste; And in Java there is some alternative?
-
12
votes2
answers1221
viewsSpring Security with Java EE
Hello, I am developing a Maven Enterprise Application EAR project and am currently implementing the authorization part using Spring Security with Annotation instead of xml. Structure of the Project:…
-
12
votes3
answers637
viewsIs it correct to state which interface solves the multiple inheritance problem in Java?
It is known that Java does not support multiple heritages. Is it correct to say that the interface concept solves the multiple inheritance problem in Java? If so, why?
-
12
votes1
answer950
viewsJava Interface 8
Java 8 allows you to implement methods in the interface itself. So I’d like to know what an abstract class can do that an interface cannot. Source:…
-
12
votes3
answers490
viewsHow is a Framework developed?
I’ve used a few frameworks they really streamlined the development of my project, helped me, I didn’t have to waste time building the common part of my problem that other people had already…
-
12
votes3
answers16185
viewsCalculate difference between dates
I need to calculate the difference between the registration date and the current date, if it is greater than 6 months, return boolean. I am registering at the bank the registration date as follows:…
-
12
votes1
answer2480
viewsDifferences between Java application servers
I would like to know the main differences between Glassfish, Jboss and Apache Tomcat application servers. Is there any specific aspect I should check before choosing one to start development? Are…
-
12
votes2
answers381
viewsJava 8 "default method" versus C# "extend method"
Java 8 introduces the concept of "standard method" to allow adding new features to an interface. C# provides "extension methods" that allow "adding" methods(features) to existing types. Taking into…