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
-
156
votes7
answers20768
viewsHow to protect source code?
I am thinking of making an application to sell, I would like to know how to protect my source code to keep my software safe. I saw the Java bytecodes, stored in the file .class are easily converted…
-
81
votes5
answers3667
viewsIs there any downside to always capturing Exception and not something more specific?
When I write code in Java and try to treat exceptions I usually simply use the superclass Exception, not linking to the specific class and it usually works. There is some inconvenience in doing…
-
71
votes6
answers56799
viewsWhat is Nullpointerexception and what are its main causes?
What are the exceptions NullPointerException? What are its main causes? What methods/practices can be used to prevent?
-
69
votes3
answers21607
viewsWhat are the concepts of cohesion and coupling?
What are the characteristics of a code with cohesion or coupling? To what extent can this generate future problems?
-
59
votes4
answers106387
viewsHow to compare Strings in Java?
The operator == says that strings are different, they store the same literal value, see the example: public class TesteString { public static void main(String[] args) { String str1 = "teste"; String…
-
56
votes4
answers107040
viewsWhat is the difference between public, default, protected and private modifiers?
What are the differences between modifiers public, default, protected and private when working with inheritance? There are rules of how and when I should use them when I’m working with heritage and…
-
55
votes2
answers39510
viewsHow to remove accents and other graphic signals from a Java String?
How to remove accents and other graphic signals from a Java String? Ex.: String s = "maçã"; String semAcento = ???; // resultado: "maca"…
-
52
votes4
answers12597
viewsWhat are the advantages of Lambda Expressions in Java 8?
Java 8 will be released soon (March 2014) and the main Feature of this version are the Lambda expressions. One could describe, as the question says, what this feature will add in practice to…
-
50
votes4
answers58057
viewsWhat is the purpose of @Override?
I’m having some doubts about @override, read somewhere and remember vaguely on the question of rewriting, but what is it? And what is it for? How does it apply in a code JAVA. Exists in some other…
javaasked 10 years, 4 months ago Rogers Corrêa 2,596 -
48
votes3
answers24523
views -
48
votes4
answers3512
viewsWhat do reticence in the parameters of a method mean?
I was looking at some methods of the package classes javax and some of them have signature similar to this: protected void doInBackground(String... params){} What does that mean " ... " ?…
javaasked 9 years, 10 months ago Renan Gomes 19,011 -
47
votes3
answers12951
viewsJava += operator
I always thought the operator += functioned only as a shorter form for the traditional increment, for example: i += j; Instead of: i = i + j; But when performing the following experiment: int i = 3;…
-
46
votes2
answers11298
viewsHow does Try-with-Resources work?
In Java 7, the concept of Try-with-Resources was added in the language. What is the Try-with-Resources? How does it work? What does it serve? How is it used? What problem does it aim to solve?…
java exception try-catch try-finally try-with-resourcesasked 7 years, 10 months ago Victor Stafusa 63,338 -
42
votes1
answer27667
viewsWhy and when to use Enum in Java?
Someone who is learning the language, novice or experienced, may never have crossed paths with Java enumerations. I have read several times that they are useful, for example, to implement the…
-
41
votes5
answers32714
viewsJava Library for Brazilian Electronic Invoice (Nfe)
I’ve been developing an enterprise management system for some time. I need to add to it the electronic invoice issuance functionality in the Brazilian standard. Is there a well tested and preferably…
-
40
votes3
answers15467
viewsWhat is Boilerplate code?
I have noticed the frequent use of the term in some forums and I was wondering what its meaning and where it came from.
-
39
votes3
answers23304
viewsWhat is the difference between "passing by value" and "passing by reference"?
I know that in the first the object passed as an argument to a function is copied, and in the second not. I also know that it is extremely unusual in modern languages to pass complex objects by…
-
39
votes2
answers1301
viewsHow does the G1 (Garbage First Collector) work?
In the JEP-248 the definition of G1 has been discussed (Garbage First Collector) as the standard Garbage Collector on Java 9. In this period, I have heard many quotes about the G1, but very little…
java performance memory-management jvm garbage-collectorasked 9 years, 3 months ago Reginaldo Soares 2,256 -
39
votes2
answers3085
viewsWhat are the main differences between Kotlin and Java?
I have long been aware of the existence of the Kotlin language. I know that you need JVM to run and that it is completely interoperable with Java. At the time I did not give her much attention but…
-
38
votes3
answers96047
viewsWhat is the use of a static or final variable in java?
What is the difference of the declaration private static int var_nome for private final int var_nome for private int var_nome? How these statements can influence my algorithm?…
-
38
votes3
answers1568
viewsHow does the licensing of Open-Source programs work?
I’ve searched a lot on Google but never found a good explanation for how to make open-source programs. I like programming a lot in Java and Python and I wanted to develop some open program with…
-
38
votes2
answers2228
viewsWhat is the difference between a lambda expression, a closure and a delegate?
From what I’ve been reading the three concepts are quite similar, but I was confused as to the clear and exact definition of them. As far as I know, a lambda expression for being understood as a…
-
38
votes3
answers53541
viewsHow does the DAO Standard work?
I researched and read about DAO (Data Access Object Standard), but I’m not getting to understand how it works and how is its structure, it is also responsible for the business rules of an…
-
37
votes5
answers22775
viewsWhat is the best way to iterate objects on a Hashmap?
What is the best way to iterate objects into one HashMap in Java to gain access to the key and value of each entry?
-
37
votes4
answers1166
viewsWhat are the differences between Generic Types in C# and Java?
I have studied Java for quite some time and am well acquainted with the functioning of generic types in that language: I know that only exist at compile time, that suffer type Erasure at the end of…
-
37
votes1
answer28542
viewsWhat are the most relevant differences between C# and Java?
I wanted to know the most relevant differences that I should know exist between these two languages. Why am I asking this here? Because normally in my day-to-day when I ask this question, my…
-
35
votes2
answers3305
viewsHow to best treat exceptions in Java?
Who has created great programs in Java knows of a very common headache: Do not know where to play the flow of Exceptions. Many decide to do things like: Treat everything as Exception (the superclass…
-
35
votes1
answer1899
viewsAccess to the DLL library made in Delphi from Java
I am developing a tool for biometric recognition using the SDK provided in DLL format, developed in Delphi. For DLL access from Java, I am using JNA. The digital template (the most important part)…
-
35
votes2
answers48974
viewsWhat does public Static void main(String[] args) mean?
I want to understand what each item of public static void main(String[] args) in Java and when to use.
javaasked 9 years ago Tiago Oliveira de Freitas 1,798 -
35
votes3
answers881
viewsIs there a difference between reporting the size in the loop condition or outside it?
If I have an array or collection in a Arraylist and need to go through its elements, occasionally need to make use of loop repetition. Ex.: for(int i = 0; i < arrayList.size(); i++){…
-
34
votes1
answer4521
viewsDifferences between <T> and <?>
What is the difference among the ratings <T> and <?> in Java? What motivation in the use of these resources and where each one is fundamental?…
-
34
votes3
answers30862
viewsWhen to use Stateful or Stateless
I would like to know the difference and when to use. Stateful Stateless
-
33
votes3
answers3113
viewsWhy is it mandatory to implement "public Static void main (String [] args)"?
Why it is mandatory to implement this method in a Java application?
-
32
votes5
answers10820
viewsHow to Reverse a String?
A user will enter a sentence and I must display this inverted sentence in upper case. How can I do this? import javax.swing.JOptionPane; public class ExerLar01 { public static void main(String…
-
31
votes6
answers36799
viewsHow to read a text file in Java?
I have the file called dados.txt and I want to put it on String. For example: String texto = lerArquivo("conteudo.txt"); Question How to write this method lerArquivo()?…
-
31
votes3
answers4357
viewsDifference between Date, sql. Date and Calendar
What is the difference between the classes java.util.Date, java.sql.Date and java.util.Calendar and in which situations the use of one or the other is recommended?…
-
31
votes3
answers25678
viewsWhat is a Java Bean and what is it for?
I’m starting to read about development java layered, and read something about the bean, an encapsulated class. But I couldn’t find any content that would really explain the purpose and an example.…
-
31
votes3
answers21968
viewsWhat is the purpose of the Serializable interface?
Example of implementation: public class MyClass implements Serializable{ private static final long serialVersionUID = 1L; }
-
31
votes3
answers1336
viewsIs it ideal to use primitive types in Java?
Java has several wrapper’s who help us (Integer, Double, BigDecimal), and also gives us the possibility to use primitive types (int, float, char). A teacher told my college class that Java should…
-
30
votes1
answer10018
viewsWhat is the difference between Javabean and POJO?
I’m new to Java, and I have that question. I searched several places on the internet and asked several friends JAVA programmers but none could explain to me clearly what the difference between the…
-
30
votes3
answers13425
viewsWhat is an interpreted language? Is Java interpreted?
In this question here I quote that Java is an interpreted language, because I always understood it that way. But I was corrected in this comment that Java is no longer interpreted. So I got some…
-
30
votes1
answer46121
viewsWhat is a DTO?
I’ve been dealing with Java for a little while and I always hear the expression DTO related to pulling something from a bank, but I never really understood what it is. Is it just a name to reference…
-
29
votes3
answers13164
viewsWhat are the default sizes of android images?
I’m creating my first app on the Android platform and as far as I know one of the negatives of this platform is that existing devices on the market have different screen sizes. I created a project…
-
29
votes3
answers1131
viewsString and its efficiency
Doubt I would like to know what design patterns or other "nerdy" things have been applied to this class StringBuffer. Why does String create new objects in a concatenation? As far as I know, String…
-
29
votes1
answer10807
viewsWhen and how to implement Parcelable vs Serializable?
After a long time using the Serializable implementation in my classes on the Java platform (Android), I discovered Parcelable, but I was in doubt regarding the following questions below: 1. When to…
-
29
votes1
answer7393
viewsWhy does Java consume so much memory?
I wrote this little program in Java to download images of a thread in a imageboard: public class FourChanThreadImageDownloader { private static void usage() { System.out.println("java…
-
29
votes2
answers11436
viewsWhat is the difference between Boolean and Boolean?
I performed some tests using Boolean and boolean and apparently returned the same result. See below: Boolean bool = true; boolean bool2 = true; if(bool) Log.wtf(TAG, "Funciona!"); if(bool2)…
-
28
votes2
answers1666
viewsWhy should the main method dispatch the creation of the GUI to the EDT in a swing application?
According to the Java specification, much of the Swing API is not Thread-Safe and shall rotate in the Event Dispatch Thread. Like, after initializing the GUI events are fired from within of the EDT…
-
28
votes4
answers6985
viewsHow to add times in Java?
I am working on a report that makes a sum of the data and part of the data is times, example: ----------------------- | Atividade | Tempo | ----------------------- | 1 | 11:00:00 |…
-
28
votes3
answers17504
viewsWhat is the purpose of Transient and Volatile in Java?
Sometimes when I declare my attributes I notice the transient and the volatile. I have the following doubts The transient and volatile are access modifiers? What is the purpose of using them?…