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
-
7
votes1
answer1729
viewsWhat are the modules?
Whenever I read about Java 9, I see assertions that the big change in the next version of Java will be native module support through Jigsaw Project. Then comes the criticism of adopting a new…
-
7
votes0
answers188
viewsHow to get all methods a class is using
I need to find a way to find all the methods a class is using (watch out, it’s not the methods stated in it). EX: public class Bondia{ public static void main(String[] args){…
-
7
votes4
answers865
viewsHow to separate a string when the string does not have a separator?
I have a string: String texto = "1234"; String split[] = texto.split(?); I need to separate the characters, 1-2-3-4, each number being 1 character only.
javaasked 7 years, 2 months ago Mateus Silveira 95 -
7
votes2
answers515
viewsAre Ltenatives for complex conditions in a lambda expression?
With lambda expressions it is possible to filter elements from a collection of objects, creating a data stream according to the criterion passed in the expression for the method filter(), This…
-
7
votes4
answers2291
viewsHow to do a search inside this vector of objects?
How would I search for a record within my object? The program is a schedule of contacts, and I wanted him to do the search by the name I type in a Jpane and return the contact data searched. Here is…
-
7
votes3
answers701
viewsWhat to do when the argument passed in the constructor is invalid?
I’m playing a card game in Java, and one of the classes is responsible for starting the game. In the builder, I get the number of players who will participate. I am doing the validation of the…
-
7
votes2
answers1329
viewsJAVA: What is the difference between Outputstream and getOutputStream()?
I’m studying java and came across several classes of input and output data, but I had a doubt in the difference between OutputStream and getOutputStream(). From what I understand, the…
-
7
votes2
answers70
viewsWhy does the return of the linear search for the element not found have to be -1?
Why should I return -1 at the end of a linear search if the element was not found? int linearSearch(int[] list, int size, int key){ for(int index=0; index<size; index++) if(list[index]==key)…
-
7
votes1
answer149
viewsWhat happens if a binary search does not find the element?
What happens if a binary search does not find the element? It goes into loop? What is the best way to finish the execution?
-
7
votes1
answer535
viewsHow does atan2 function?
I have the following scenario: The angle should be chosen so that it always points directly to the mouse. Find the angle relative to the X axis (then 0 is straight to the right and PI/2 is straight…
-
7
votes2
answers327
viewsAfter all, is Java a platform or a programming language?
I see various materials referring to Java as a technology (platform) and others as a programming language.
-
7
votes2
answers534
viewsIs it possible to change the value of an annotation at runtime?
Considering the following annotation: @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface MinhaAnotacao { String valor(); } Defined in a class: @MinhaAnotacao(valor =…
-
7
votes1
answer1040
viewsHow to restrict so that you do not set a longer date and then a shorter date using Calendar Restrict?
Good night! Here’s my problem: I’m making a screen that has two calendars: The program will return me a list that comprises the interval between two dates. One date is from the first calendar, and…
-
7
votes1
answer5110
viewsWhat is Flyway and when to use it?
The system recently drew attention to this issue, and it talks about Flyway. So I’d like to know: what is Flyway? what problems he proposes to remedy? when to use it? what are the competing…
-
7
votes1
answer171
viewsAndroid - What is the difference between String and Editable?
When using the Edittext view, I saw that it returns an Editable data type and not a String. And it has different methods like getEditableText(). What is the main difference between String and this…
-
7
votes2
answers406
viewsWhy doesn’t Java add up the numbers in expression?
public class Teste { public static void main(String[] args) { int x = 0; int y = 1; int z = 2; System.out.print(x + y + z); } } This returns: 3 public class Teste { public static void main(String[]…
-
7
votes2
answers339
viewsWhy does String hashcode() in Java use 31 as a multiplier?
In Java, the code hash for an object String is computed as s[0]*31^(n-1) + s[1]*31^(n-2) + ... + s[n-1] using integer arithmetic, where s[i] is the i-nth character of the string, n is the string…
-
7
votes1
answer105
viewsIs there an alternative to multiple while loops?
I have a method alterar() that change the data of a particular element of my XML Person, however, this routine uses several whiles one for each element, see below the routine: public void alterar()…
-
7
votes1
answer475
viewsWhat are application and domain services in Onion Architecture?
In Onion Architecture there is the core (application that includes domain objects, Domain Services and Application Services): I am in doubt about what the last two are (Domain services and…
-
7
votes2
answers6860
viewsHow to number the alphabet and add its letters getting a result for each written word?
Wanted to get the result of words with their letters summed... Example: a=1 b=2 c=3 if I type the word "bac" the result would be "6". Because you added up the three letters a+b+c=6. I tried that…
javaasked 8 years, 2 months ago Rafaelzinho 85 -
7
votes1
answer309
viewsJava how to compare "float" to "null"?
public class NuloOuNao { public static boolean isZero(float num) { if(num == null) { return true; }else { return false; } } public static void main(String[] args) { isZero(10); } } Row 5: The…
-
7
votes1
answer170
viewsDoes DDD restrict code writing based on the client’s language?
My little knowledge about DDD has been subpoenaed and would like to know more about. The DDD restricts code writing based on the client’s language because of the ubiquitous language?
java c# software-engineering software-architecture dddasked 5 years, 8 months ago Thiago Cunha 1,356 -
7
votes1
answer8513
viewsHow to do Localdatetime(Datetimezone.forID("America/Sao_paulo")) in Java.time
I wonder if there’s any way to mimic that code on java.time: LocalDateTime(DateTimeZone.forID("America/Sao_Paulo")) I don’t work very well with date in Java, if you can also explain to me what this…
-
7
votes1
answer4956
viewsHow do I open the android camera and take the photo and upload the photo to the server?
I have a problem in the application it opens the camera but does not upload hold can see where I am missing follows the code public class MainActivity extends Activity{ //chamar quando a atividade é…
-
7
votes1
answer689
viewsDifference between @Deprecated and @deprecated
What’s the difference between @Deprecated as an annotation in the class and @deprecated in the documentation of the same? When to use one and when to use the other? /** * Combo box that shows the…
-
7
votes3
answers189
viewsIs it better to have a kind of exception for each case or a more general exception?
A project from my college was asked to create a class called RepositorioException which is a subclass of Exception to be used for handling exceptions in repository classes, where:…
-
7
votes1
answer223
viewshow to center tabs of a Tabbedpane?
I have been doing some research, but I did not find it. I would like to know, how to center the tabs of a Tabbedpane. They always start from the left, but since they are only two tabs, I wanted them…
-
7
votes1
answer2011
viewsCascadetype.ALL doesn’t work. Am I using it wrong?
In my code, I have the classes Author and Book, with the relationship Many To One, as below: Java author. import javax.persistence.CascadeType; import javax.persistence.Column; import…
-
7
votes1
answer1682
viewsInput type file does not work in webview
I have an HTML page that has a form of upload imaging in Chrome on pc or any browser works but in my app that has a WebView that opens this page then click on Choose file he does nothing. It is…
-
7
votes1
answer1030
viewsBest practices with Java exception handling
How best to work with more than one exception in Java? In the code below, I see the possibility of giving two errors NullPointer or SQLException. If I put one catch for every exception is the best…
-
7
votes1
answer1549
viewsDaily notifications at a specific user-defined time
I created a method to send a notification to the user with the name sendNotification() using NotificationCompat.Builder and NotificationManager. I need this notification launched every day at…
-
7
votes2
answers837
viewsHow to implement a class to use Preparedstatement through it?
I have the following class Connect.java package util; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.SQLException; import…
-
7
votes1
answer311
viewsWhen to use Supertype or Subtype when returning the method?
Suppose I have a method called "meuMetodo()" that returns an Object of Type ArrayList<String>, i can make this method declare that returns more concrete or more abstract types: public…
-
7
votes2
answers227
viewsHow to convert byte to Boolean[8] and convert back?
I need to record some booleans in a File, and then retrieve them. I can record and read one or more bytes with the Classes java.io.FileInputStream and java.io.FileOutputStream, so I need to convert…
-
7
votes2
answers284
viewsHow to perform the correct flow deviation in an integration with multiple systems?
We have a system, which I will call A, which serves some customers. We are now performing the first integrations with the internal systems (ERP) of these customers. When we make, for example, a…
-
7
votes1
answer223
viewsWhy hide the implementation of a class?
This is the concept I’ve worked hard to understand, but I’ve never fully achieved. I’ll take this excerpt from a Deitel book to illustrate: It is a better software engineering define member…
-
7
votes2
answers88
viewsHow do I detect that the headset has been plugged in?
I’ve been watching that every time I "plug" the headset in my smarphone, a notification from Deezer (a stream music) already telling to click and to open the application. According to the…
-
7
votes1
answer5651
viewsInfinite recursion (Stackoverflowerror): Error when listing products with categories and unit of measures
Good afternoon! I am trying to list the registered products, but the error happens below: Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not…
-
7
votes1
answer219
viewsHow to know the number of possible occurrences found by the group() method of the Matcher class?
After the question "Why does the Matcher class not return the number of groups correctly?", it was explained that the groupCount() actually returns the number of filter groups in the regular…
-
7
votes1
answer612
viewsHow to draw an arrow using Java2d?
I’m trying to draw an arrow inside a circle (similar to a clock pointer), but I’m not able to align the arrowhead with the rest of the line. I made the "arrow" based in this reply by Soen, but I’m…
-
7
votes1
answer3469
viewsConsume Pje web service
I need to consume the progress of a process using the web service provided by Pje. I am following the guidelines described in: http://www.pje.jus.br/wiki/index.php/Tutorial_MNI According to the…
-
7
votes1
answer678
viewsHow to know which Activity prior to the current Activity was called?
I have several activities, which can call a special activity. I’d like to know how to identify which Activity called. It would be something like this: I need this because I have a user registration…
-
7
votes2
answers972
viewsHow to use Stream.reduce() appropriately
My problem: I have an Arraylist of the type of Routes (first value is the name of the city, second value is the destination city and the third value at distance), I want to create a new map…
-
7
votes1
answer99
viewsPersistent Hibernate Resource Return
Good afternoon. I would like to understand how to resolve the following issue: In the project I’m working on, Backend and Frontend are separated. To persist the data I am using Hibernate and to…
-
7
votes2
answers118
viewsMany "if" in an old game for android
When checking if someone won, I need to use the IF several times. I wonder if there’s a way to simplify the code a little bit and maybe even replace the IFs. //left, top, right, bottom are int…
-
7
votes1
answer282
viewsHashmap sorting by value and assigning to a dto using java 8
I currently have the following scenario functional: A list of the Studios class with id and name: List<Studios> studios; I count the names repeated on List thus: Map<String, Integer>…
-
7
votes1
answer1853
viewsWhat does the number returned by System.currentTimeMillis represent?
I went to read the documentation, made available by IDE and came across this: It is said that the method System.currentTimeMillis returns: the Difference, measured in milliseconds, between the…
-
7
votes1
answer65
viewsA client class that registers clients in itself would be a cohesive class?
Studying cohesion. Since a cohesive class is one that has unique responsibility, it would make sense for the class Cliente own these methods? If we think in the real world, a customer cannot…
-
6
votes1
answer394
viewsEfficient data structure for high color concurrent problem
As part of a test I was asked to develop an application to manage high Scores in environments with high competition. This application should not persist on disk or use libraries and frameworks…
-
6
votes2
answers3727
viewsConfigure Jenkins to build each commit?
I have Jenkins installed correctly and building every 30 minutes, but I’d like to build every commit in the svn repository. I tried to configure the option: Check the SCM periodically, but I was…