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
-
5
votes0
answers417
viewsHow to move the object to where I click the mouse?
My problem is this: I have an Opengl program with Java. I made an animation for the drawing to move, increase and decrease in size, so far so good. When I went to create a function where the mouse…
-
5
votes1
answer264
viewsIs it possible to compare numerical values in strings without casting to Number type?
I have two numeric values that are recovered in strings and I wonder if there is a way to compare them to see which numerical value is higher, but without having to keep converting to type Number…
-
5
votes2
answers396
viewsHow to play relationship in Objects?
According to the definition of this website: CARDINALITY Is the maximum and minimum number of occurrences of an entity that are associated with the occurrences of another participating entity…
-
5
votes1
answer186
viewsMethods that require return even having Void in "signature"
I am doing some tests to understand in practice the functioning of the classSwingWorker in the swing, and I noticed that the method doInBackground demands a return null, even starting the form…
-
5
votes1
answer425
viewsWhy does the image get distorted (doesn’t maintain the proportions) in Imageview?
I have some images inside the folder drawable and call them via code: public void inserindoImage(ImageView image,int rid,LinearLayout linear ) { image.setBackgroundResource(rid);…
-
5
votes1
answer64
views -
5
votes1
answer9357
viewsRun JNLP Ubuntu
My current version of java is as follows: openjdk version "1.8.0_131" OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11) OpenJDK 64-Bit Server VM (build 25.131-b11, mixed…
-
5
votes2
answers127
viewsReplaceall() does not remove "|"
I have a following string "|" and I would like to replace it with a simple "", my java code is like this: String teste = "|A|B|C"; teste.replaceAll("|",""); Exit: "|A|B|C" I would like the output to…
-
5
votes2
answers84
viewsWhy does the new instance of Actionlistener receive a parenthesis and a ;(semicolon) at the end?
I’ve never seen this kind of code structure in the instance, what does it do? The class ActionListener To instantiate it, you have to put it like this: ActionListener trataEventos = new…
-
5
votes2
answers439
viewsJava financial math equation
How can I encode this equation in Java? 750=(1-(1+j)^(-10))/j*86…
javaasked 7 years ago Weriky Alphazero 37 -
5
votes2
answers191
viewsReload script whenever the event happens
Hi. I was looking and I couldn’t find anything related around here, so I’m coming to ask. I’m working with the one plugin 'http://tympanus.net/codrops/2014/10/30/resizing-cropping-images-canvas/',…
-
5
votes1
answer106
viewsI don’t understand the order to execute a code
public class Rope { static String result = ""; {result += "c";} static {result += "u";} {result += "r";} public static void main(String[] args) { System.out.print(Rope.result + " ");…
-
5
votes1
answer566
viewsCreate inputs for images dynamically and move to Servlet without redirecting the page?
I would like to create a button that brings up a input for sending images. This button can be used multiple times. When the user(a) click the Submit, these images should be sent to the server…
-
5
votes2
answers340
viewsHow to create an array whose indices are characters from an informed string?
I wanted to create a vector in java in which each input of the vector was a character of a string that I informed public static void main(String[] args) { String[] words = {"java"};…
-
5
votes2
answers989
viewsProblems comparing dates with Calendar
I am developing a system for hotel and reservation I need the date of entry is greater than or equal to that of the reservation, and the exit is greater than that of the entrance. I made these…
-
5
votes1
answer167
viewsTemplated Method - Is it possible to implement with composition rather than inheritance?
To create a Thread we can both extend the class Thread and overwrite the method run(), how to have a class that implements the interface Runnable, implement the method run() and pass the reference…
-
5
votes1
answer423
viewsRedirect jsp page using Springframework
Hello! I have the following problem in redirecting the index.jsp page to the.jsp login page, in Tomcat it only appears that this page was not found, ERROR 404. If anyone can help, I’m using and…
-
5
votes2
answers6061
viewsQuery specified Join fetching, but the Owner of the fetched Association was not present in the select list
I have a scenario with the following entities:Treinamento, Curso and Aulas. A Treinamento has a relationship ManyToOne for Curso. And Aula has a relationship ManyToOne for a Curso. I want to perform…
-
5
votes1
answer259
viewsWhy not iterate a hashmap?
I was doing a project and one of my colleagues mentioned that iterate hashmaps is something to avoid and instead of using hashmap should wear Linked lists. However I think the versatility of the…
-
5
votes1
answer1167
viewsHow to get a random number in Kotlin?
How can I get a random number between two values? Like ruby does with rand(0..n)
-
5
votes3
answers629
viewsWhy does my Actionbar due to an error stay inside my Statusbar?
I started a new default project on Android, I did like this reply to my ActionBar stay on top of the standard menu NavigationDrawer, now, my ActionBar enters into the StatusBar and the source gets…
-
5
votes2
answers1026
viewsCan a subclass have two superclasses?
Suppose I have a superclass Pessoa and another Funcionário, with its certain attributes and methods. My class Professor may be "daughter" of Pessoa and Funcionário, once it fits both? If yes how is…
-
5
votes1
answer311
viewsHow to order hours
I have the following method to sort a ArrayList String of Hours: public static void ordenaHoras() { ArrayList<String> horasList = new ArrayList<String>(); horasList.add("23:45");…
javaasked 8 years, 5 months ago Vitor Mendanha 595 -
5
votes1
answer587
viewsConvert String from Jtextfield to Calendar
How to perform input conversion via Swing’s Jtextfield via JDBC ? public class DadosPessoais { private Calendar dataNascimento; public Calendar getDataNascimento() { return dataNascimento; } public…
-
5
votes3
answers4373
viewsIf H = 1 + ½ +1/3 + ¼ + ... + 1/N, make an algorithm to calculate H, where N is typed by the user
The program is only printing 1, it’s like it doesn’t keep the value of the variable h, can anyone help? Follow the code: public class MainUmSobreH { public static void main(String[] args) { double h…
-
5
votes1
answer452
viewsIs it possible to compile an app using Java and Kotlin together?
Can I be part of the code in Java and another part with Kotlin? Can anyone tell me?
-
5
votes0
answers148
viewsMojofailureexception caused by charsetName in Maven Archetype
A WAR project I’m trying to use as a base to run mvn archetype:create-from-project causes the following Exception stack after trying to read one of the files .java: [ERROR] Failed to execute goal…
-
5
votes1
answer9780
viewsHow to make application running in the background all the time
I tried to use the Service as they said but it’s not working yet. I don’t know if I got it right, the method onStartCommand() will run all the time? Because I debug and the application only enters…
-
5
votes2
answers133
viewsHow to filter a Hashmap by returning another Hashmap using Java 8 lambda?
The following code traverses a Set and filters only the objects that the isActive() is true. public Set<InvoiceLineDocument> getActiveLines() { Set<InvoiceLineDocument> activeLines = new…
-
5
votes1
answer375
viewsWhat is the best way to generate Push notification using Firebase?
I have the following problem: I have a system where it is possible to register a series of tasks to be accomplished by a team or person. What I need is that whenever an order is finalized by a user,…
-
5
votes6
answers12886
viewsDoubt about logical operators && e || in Java
I have the following code in my app: if (aquaName != null && !aquaName.getText().toString().isEmpty()){ values.put(NAME_COLUMN, aquaName.getText().toString().trim()); } else {…
-
5
votes0
answers263
viewsCreate Tables with Hibernate
Good afternoon !! I’m new with Hibernate and I’m two days trying to implement the creation of tables with it, I’ve already followed several tutorials, but it doesn’t work. Can someone help me ?…
-
5
votes2
answers771
viewsHow to hide menu items using spring security?
I am using spring security to control access to my web application. I have already managed to implement the control that each type of user will have in relation to the urls, now I would like to hide…
-
5
votes1
answer127
viewsCode Review: Simple MVC
Hello world! I tried to make a very simple MVC in Javafx. My template is a class Pessoa who owns nome and idade (the field idade in case it is not used). Two text Fields represent two views. For…
-
5
votes4
answers1605
viewsTurn Messagedigest MD5 into a string
I am trying to generate an MD5 hash using the class MessageDigest, however, I cannot correctly display the hash as a string on the screen. The result is a string of unknown characters. Below is the…
-
5
votes1
answer186
viewsProblems with graphs in Java
I’m making a URI issue and in the lobby they ask so. Input: The input ends in EOF. For each test case, the first line contains two positive integers C and P that represent respectively the number of…
-
5
votes3
answers3023
viewsCompilation and execution error difference
A build error would be the one the IDE already warns about even before compiling, such as missing a semicolon, correct? But what about the error of execution? It would be for example a Exception?…
-
5
votes1
answer155
viewsHow to modify/evolve a distributed Infinispan cache "hot" without losing entries?
Context I have a cluster with some nodes of the Jboss EAP 6.4. Applications in this node cluster share a cache embedded mode infinispan with UDP synchronous distribution (Jgroups):…
-
5
votes3
answers914
viewsExpand or Minimize code snippet in eclipse
It would be possible to minimize or expand only a code snippet inside a block {...}, example below: using the IDE eclipse?…
-
5
votes1
answer122
viewsInheritance at compilation time?
I was reviewing some codes and some concepts when I find the following assertive: The legacy mechanism in Java occurs at compile time, i.e., every reuse of code accomplished by inheritance is…
-
5
votes1
answer334
viewsRaw String Literals Java
I saw that in JDK 12 it is possible to make raw string literals similar to some programming languages like C#, JS, R etc. Ex in C#: "Essa não é uma \n raw string"; Exit: Essa não é uma raw string…
-
5
votes1
answer707
viewsNotification icon in Android 5.0
I’m creating a push notification system with firebase in my project. The code that generates the push is like this: notificationBuilder = new NotificationCompat.Builder(this)…
-
5
votes2
answers197
viewsGet JSON from the URL properly
I have the following method that gives me one String: public static final String jsonClientes = " {\"clientes\": " + " [" + " { \"idClientesT\": 1," + " \"tipo\":\"s\"," + " \"nome\":\"Carlos\"" + "…
-
5
votes2
answers1202
viewsJava Runtime could not be Located in Visual Studio Code
I already have JDK installed, but Visual Studio Code does not recognize and presents the following message: What must I do for him to recognize? For I have the Language Support For Java(TM),…
-
5
votes2
answers4293
viewsBreak and Continue on foreach Java 8
How to give a break or a continue in an iteration using forEach, in the example below, I could use the same forEach for the execution of the validation? List<Contratos> contratos= /* populando…
-
5
votes1
answer351
viewsSIP connection - Softphone Java Android
My intention is to create a Softphone, for this I am consulting the libraries of google and doing some tests only that I have enclosed in a part. I don’t want to do start functions, or multiple…
-
5
votes1
answer158
viewsHas some real use when implementing non-abstract methods in an abstract class
Have some real use when implementing a method that has a field, (implemented code) in an abstract class that cannot be instantiated, since no compilation error occurs? public abstract class…
-
5
votes1
answer142
viewsWhy do local variables not receive default values from the Java compiler or JVM?
Why the compiler assigns values default for attributes but not for local variables? public class Teste{ int a; public void metodo() { int b; System.out.println(a); System.out.println(b); } }…
-
5
votes3
answers1866
viewsFormatting date in Java web with Primefaces
Speak guys, I need to format a date in Java. I’m using Java web, Primefaces, MVC, TDD, JSF, Hibernate. I am an intern and I am doing a Project Manager project for my company. My date input view…
-
5
votes2
answers426
viewsSave photo via URL to database
I’m making an application that needs the login Facebook. I was able to get all the right data, but I’m not able to save the profile photo in the database. I was able to display the photo on…