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
-
28
votes2
answers1906
viewsWhat is the View in the MVC standard?
I started in 2016 to wear pattern MVC, the concept of Model and Controller I fully understand, but the question of View intrigue me. What is the View on a model MVC? I know that’s what the customer…
-
28
votes2
answers3404
viewsHow do I migrate from Date and Calendar to the new Java 8 Date API?
Until Java 7, we had the classes Date and Calendar to represent dates. To convert them to Strings, the easiest way was with the use of SimpleDateFormat. Java 8 has introduced a new date API. How can…
-
28
votes5
answers1775
viewsWhy is it bad practice to have int attributes?
I saw in the answer to that question /questions/17015/qual-o-uso-de-uma-variável-estática-ou-final-em-java/17136#17136, that: It is bad practice to have int attributes, unless they are "constant" or…
-
28
votes2
answers2065
viewsWhat is "positive zero" and "negative zero" in float and double types?
In response of this link the operation of the atan2(), and its translation of documentation by Victor Stafusa, there are some excerpts that I highlight below: (...) If the first argument is positive…
-
27
votes4
answers3196
viewsWhat is good practice when casting an exception within if?
What is the best practice in this case, use the Else even knowing that the if will or will not make an exception? option 1 (with Else): if (condicao){ throw new RuntimeException("Mensagem"); }else{…
-
27
votes1
answer13799
viewsWhat is the importance of implementing the hashcode method in Java?
How important it is to implement the hashcode method in Java? How the hashcode method differentiates two objects?
javaasked 10 years, 7 months ago Geison Santos 4,428 -
27
votes3
answers1011
views@Override is required in Java?
If I have an abstract class Pessoa with an abstract method lerNome when I’m implementing this method in my class João I must make use of @Override in lerNome? The same happens when I use interfaces?…
-
26
votes3
answers1419
viewsComparison of integers in Java
Integer valor = 127; Integer valor2 = 127; System.out.printIn(valor == valor2); Output: true Integer valor = 128; Integer valor2 = 128; System.out.printIn(valor == valor2); Output: false Why does…
-
25
votes3
answers1989
viewsHow do I know if the first digit of a string is a number?
I have a form where I need to validate the taxpayer number. If you start with PT or if it is a number without an acronym I validated by the Portuguese finance algorithm, otherwise I do not validate.…
-
25
votes2
answers17812
viewsWhat is a Thread? How does it work?
I was confused as to what a thread is and what it represents. I found the following definition for the same: Thread is a small program that works as a subsystem, being a way for a process to split…
-
24
votes3
answers4153
viewsCommon encryption algorithm between Java and C#
Problem I am creating a Web Service in C# to be consumed by an Android application (Java), among other information I would like to pass the user credências to login offline on the app. But these…
-
24
votes4
answers1788
viewsAre Getters and Setters mandatory or facilitators?
Lately I have read some Java books, but there is a part that makes me confused in this type of methods accessors - gettters and setters. The point is: I am required to write in this type of methods,…
-
23
votes4
answers3497
viewsCapture the values of JSON that is Online
My problem: I need to read a JSON that is in a certain URL. I tried the following code, but it doesn’t work: JSONObject jsonObjeto; JSONParser parser = new JSONParser(); URL url = new…
-
23
votes3
answers8791
viewsWhat is the difference between checked (checked) and unchecked (unchecked) exceptions?
Hello! I have some questions about exceptions, which are they: What is the main difference between checked and unchecked exceptions? In which situations should I use each of them? What are good…
-
23
votes2
answers8037
viewsArraylist x List
What is the difference of declaring ArrayList and List for lists in Java? What are the advantages of using one or the other?
-
23
votes2
answers2818
viewsWhat is "Inversion of Dependency Principle" (DIP)?
I’m getting to know the beginning now SOLID: S Single Responsabilty Principle The Open/Closed L Liskov Substitution Principle I Interface Segregation D Dependency Inversion Principle However I could…
-
23
votes3
answers627
viewsOptimize Java method using the Scopes concept
Well some time ago, when I took some classes J2ME to Mobile (almost deceased ), where I was presented to a concept of scope hitherto unknown by me, that would be: { // cria um novo escopo } Where…
-
23
votes3
answers6210
viewsWhat is the purpose of the symbol :: in Java?
I implemented a method that sums all the numbers in a list of the kind List<Integer> as follows: int soma = 0; for (Integer num : numeros) soma += num; return soma; However, the Netbeans IDE…
-
23
votes2
answers885
viewsTo what extent should I follow the conventions, where can I apply specific style patterns of my own?
How far should I follow the conventions in Java codes, that is, how far the convention is a rule? I can develop and apply my own styles of coding patterns in my code, knowing that I will use this…
-
23
votes3
answers478
viewsCan Garbage Collector language be used for games?
I started learning C# and even Java for interest in game development. But I know that many are developed with C++, mainly because I don’t have one Garbage Collector. Of course I know that several…
-
22
votes1
answer28962
viewsHow to use debug in Eclipse?
I’m having a very annoying problem with a java.lang.Nullpointerexception error and I wonder if with debug it shows which element is null, rather than just which line is the error.
-
22
votes4
answers33277
viewsUsing the keywords Throws and Throw
How do I use the words Throws and Throw in a Java code?
-
22
votes1
answer1099
viewsWhat is the difference between Integer.valueOf() when using String or int parameters?
Why in the lines below the results of System.out are different? Integer teste = Integer.valueOf("0422"); Resultado: 422 Integer teste = Integer.valueOf(0422); Resultado: 274 If step one int it…
-
22
votes1
answer68862
viewsHow to generate a . apk file in Android Studio?
If it is already generated in which folder it is located?
-
22
votes2
answers574
viewsIs it possible to have month 13 on a date in Java?
I was looking at the class documentation Formatter java 7, this link from Oracle itself, when I noticed myself with the following example below: What intrigued me was the example given for the month…
-
22
votes2
answers14617
viewsWhat is the difference and what are operators & and && e | and || in Java for?
I was analyzing some possibilities for the implementation of an algorithm and I went to look up this & and |, and I read some topics in English but it’s not 100% clear to me what it’s for and…
-
21
votes2
answers378
viewsPerformance in creating strings in Java
What is the best way to create strings in Java to get better performance? Here are two examples of creating strings in Java: Ex. 1: String str = "string"; Ex. 2: String str = new String("string");…
-
21
votes2
answers15418
viewsDoesn’t Java have multiple inheritance?
I had seen somewhere now I don’t remember, I think it was in a course on object orientation, which Ruby possesses. But in Java I’ve never seen it. Is that why abstract classes are used? Or is this…
-
21
votes1
answer5221
viewsHow does Design Pattern Observer work and how does it implement it?
I am in doubt regarding Design Pattern Observer, when its working and how to use(present practical example).
-
21
votes4
answers4816
viewsCheck Old Play Winner
The algorithm teacher asked us to write a code to make a simple old game in Java. And I already have everything ready only I’m not very happy with the solution I found to validate who won the game.…
-
21
votes3
answers5317
viewsWhy use get and set in Java?
I learned in college a while back that you should always use getters and setters for access of values in an object and I heard that it is for security reasons. So I ended up always using and seeing…
-
21
votes1
answer1341
viewsHow to remove the edges of a Jframe?
I’d like to remove the edges of a JFrame. I used setUndecorated(true), however it removes completely and I would like to leave only the title bar of the JFrame.…
-
21
votes1
answer1446
viewsOrganizing packages in a java project
When creating a project on Android, the IDE itself suggests that the main package has its own naming type (with.example.namepackaging), and also creates a whole hierarchy of directories already…
-
21
votes4
answers1851
viewsInfer class type from a generic
In the following class I want to assign the attribute clazz class type inferring it from the list given in the constructor. class Foo<T> { private Class<T> clazz; Foo(List<T> list)…
-
21
votes5
answers1899
viewsIs dealing with business rules in the model bad practice?
This is something that may seem simple, but it is not. After all how to define whether a rule should be in the service layer or in the model itself? To illustrate, think of the following: We have an…
-
20
votes2
answers622
viewsWhat is the /** code for in the java language?
While I was stirring the netbeans using language java I didn’t understand what that command was for /** , I went in and something came up about Javadoc, I didn’t quite understand what that meant…
-
20
votes2
answers11031
viewsWhy can an inner class be Static and an outer class not?
It is possible to have an internal Static class: public class ClasseExterna{ public static class ClasseInterna(){ } } And it is not possible to have an external class Static: public static class…
javaasked 10 years, 4 months ago user3174 -
20
votes2
answers70450
viewsError trying to run Eclipse: Java was Started but Return Exit code =13
After having the hard drive changed, I downloaded and went to try to run the eclipse and it returned the error: Java was started but return exit code =13 What is causing this error?…
-
20
votes2
answers1978
viewsHow to use the Java scanner
I was doing an exercise for the university using the class Scanner and something unusual happened, watch the code. for(int i = 0; i < 11; i ++){ //problema(esta pulando a escolha de um dos…
-
20
votes3
answers14671
viewsWhat is the difference between Statement and Preparedstatement?
When I paid for the database chair, we worked with the bank alone, with no connection to an application that interacted externally with the DBMS. Only then was presented the JDBC(Java Database…
-
20
votes2
answers1468
views -
20
votes1
answer1876
viewsRequests for Rest API
The application uses Spring Rest in which the paths of a CRUD are automatically generated for each entity, I have the entities Vehicle, Contact and Agency and each one with its respective…
-
20
votes3
answers5013
viewsWhat is the difference between using Object.toString() and String.valueOf()?
I was doing some tests and I realized that using one or the other, the result turns out to be the same. I made this code to exemplify: public class ParseToStringTest { public static void…
javaasked 7 years, 5 months ago user28595 -
19
votes3
answers2369
viewsDefinition of the day of the week in the Gregoriancalendar
I have the following code which is responsible for creating a Gregoriancalendar for handling a date. TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo"); TimeZone.setDefault(tz); Calendar…
-
19
votes1
answer3428
viewsCommunication between Android and USB devices
I’m developing an application for Android that communicates with a USB device, a printer, an Arduino or another Android device. Is it possible to read and write on the Android USB port? How should I…
-
19
votes3
answers736
viewsWhat kind of treatment can be performed in this case?
At the moment I want to learn more about exception treatment, a topic that is very well commented by @Maniero. I read several of his answers about exceptions, but I still had a question. The method…
-
19
votes8
answers5853
viewsRecognize word repeats in String
I have a text inside a StringBuffer and I need to check and mark the words that appear more than once. At first I used a circular row of 10 positions, because I am interested only repeated words in…
-
19
votes2
answers982
viewsSelectonemenu is not loaded when selecting object for editing
I have a component SelectOneMenu (Primefaces) of cities, which is loaded according to the selected state. My component is with following behavior, right after saving the object and then selecting it…
-
19
votes2
answers8059
viewsWhat is upcasting and downcasting in the Java language?
What would be downcasting and upcasting in Java? Examples please.
-
19
votes1
answer739
viewsWhat is the difference between "Generics" (Java/C#) and "template" (C++)
In the question What are the differences between Generic Types in C# and Java? the difference between the Generics between Java and C#. We know that C++ does not have Generics, but uses templates…