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
-
8
votes4
answers688
viewsSuperclass can become subclass?
I have the classes Versao, that a general version, VersaoFirmware and VersaoSoftware. In practice the user can add one or more versions to an equipment. However, at first, it is not yet known what…
-
8
votes2
answers1484
viewsCompareto: Comparison method violates its general Contract!
I found many questions on this subject, and tried all the suggestions I found, however the problem persisted. If anyone can help me, there’s my problem: I have a list of requests, this list is…
-
8
votes2
answers2937
viewsBest Way to Use and Instantiate Entitymanagerfactory
My project has the following structure: Within the package br.mandacaru.DAO are the controllers. To instantiate an object JPAController I need an object EntityManagerFactory and for that reason I…
-
8
votes3
answers1511
viewsHow to send an object via SOAP web service
To send a primitive data is simple, but when it comes to complex data as shown below, an exception is thrown: java.lang.Runtimeexception: Cannot serialize: Person{name=given, address=given etc...}…
-
8
votes1
answer4948
viewsHow do I send a message to a Whatsapp group with the venomous0x or yowsup api?
I would like to know, with an example if possible, how to send a Whatsapp message to a group created by another person using venomous0x or yowsup? The shipping code is this: public String…
-
8
votes3
answers1408
viewsWorking with JPA+Hibernate cache
I doubt how I should work with the objects EntityManagerFactory and EntityManager. Currently I urge a EntityManagerFactory for the whole system, since I have only one bank, I create only one and use…
-
8
votes1
answer438
viewsReturn value processed in Javascript to the Managed bean
Is it possible to return processed value in Javascript to the Managed bean? What’s different in this process is that I run the JS method on the bean, like this:…
-
8
votes2
answers1714
viewsInvoking an object’s method - reflect
It is possible to invoke a method from the contents of a variable of type String? for (Object vlr : dados) { String metodo = "getCodigo()"; contato.setAttribute("codigo", vlr.metodo); }…
-
8
votes2
answers9610
viewsPick current date from machine
I need that when you execute the code it takes the current system date and assign to a Date. Example: Date x = new Date(now);
-
8
votes2
answers226
viewsWhy does Value in Spring MVC need an asterisk?
Why do I need to put * no value when there is nothing else? I mean, before using Spring MVC worked smoothly only as /planilha/. The getPlanilha works properly but if it has the same RequestMethod…
-
8
votes1
answer723
viewsCreating a Java Interpreter for android?
I am developing an android application where it will be possible to write a java code and run... something similar to the visualg. then I did something different than most tutorials on compilers and…
-
8
votes2
answers1558
viewsDoes the passage of objects in Java simulate passage by reference?
Everyone says that Java goes by value, including Objects. These are copied and cannot be reassigned to a new object within the method. The problem is that it is possible to change object values…
-
8
votes3
answers7156
viewsgenerate a json file with java
Iterative insertion: 7841910ns - 7ms Iterative selection: 2677762ns - 2ms Iterative merge: 708154ns - 0ms This algorithm was made in Java, in the java console is printed several values, being: name…
-
8
votes1
answer6420
viewsApache Tomcat (Production Setup)
Good morning, I’m doing a project and using Tomcat 8 as my server. The point is, I have a Linux server to host my application, but I would like to know if I need to do any different configuration…
-
8
votes2
answers621
viewsDynamic scheduling of tasks with spring batch + Quartz
I have a project in Spring Batch + Quartz, which loads a file and then processes the data from the file. Only that I wanted to implement a view with a form where I had the option to choose the start…
-
8
votes2
answers784
viewsprintf in Java - What is %3d for?
I’m seeing a java arrays exercises, but I can’t understand what the %3d, if it’s a int. for (i=0; i<n; i++) { System.out.printf("a[%d] = %3d b[%d] = %3d\n", i, a[i], i, b[i]); }…
-
8
votes3
answers11171
viewsHow to return the ID of a record right after it is inserted?
I am making a Java application in conjunction with a Mysql database and would like to know what would be the best command to return an auto database increment ID right after the record is inserted.…
-
8
votes1
answer5127
viewsConvert String to Float with Java comma
How do I convert in an elegant way String for float java? The strings are with the Brazilian localization, that is, the values come with comma as decimal separator ("12.345"). I find it so... "ugly"…
-
8
votes2
answers663
viewsHow to make 3 nested Selectonemenu?
I’m creating a page that has to be 3 SelectOneMenu of the first faces. In the first I will carry a center (of the university), the second will carry an edict and the third would carry the…
-
8
votes1
answer113
viewsMaintain background in Drawingview
I’m needing an application to draw on a specific background, the code is working all right, but when I’m going to delete/correct a wrong line, it erases the background and the background should be…
-
8
votes1
answer331
viewsJava Point 2d code, does not display the distance correctly
package OrientacaoObjetos; public class Ponto2D { //campos publicos: nao existem restricoes p/ valores de x e y public double x, y; //constr. default: ponto definido na origem(0, 0) public Ponto2D()…
-
8
votes2
answers456
viewsError in include JSP
I have the following situation: Servlet instantiated at the root /Minhaservlet Jsp instantiated in a folder inside the root: /folder/file.jsp Inside that file I have the following <img…
-
8
votes3
answers31605
viewsCheck if the element exists in Arraylist and, if not, add it
I created a state class with name, acronym and capital and a country with name, capital and states - an Arraylist of the type State. I want to create an input methodState(and status) that before…
-
8
votes1
answer2380
viewsLeave program done in Swing with Windows appearance
I am developing application with Java Swing, but the screens are not looking windows window. Example of screen. I wanted to look like Windows even, with the title bar with minimize, maximize and…
-
8
votes1
answer1990
viewsJava - Send Email Securely via Gmail API
I’m using a API e-mail Mail.jar of this tutorial for sending e-mail via Java, but I realized I have to, activate the permission for less secure apps. There is another way to send email Java, without…
-
8
votes2
answers1621
viewsDifference between AWT and Swing in component rendering
What are the main differences between the Swing and AWT interface construction libraries, regarding how to render the components of both and the performance?
-
8
votes3
answers1013
viewsContains in Java, how to search a text in an Arraylist?
In C# there is the method contains of System.Linq that searches text in a list, I did the tests in Java and I did not find a similar way even knowing that in Java 8 has expression, there is some way…
javaasked 7 years, 10 months ago Paula Martins 83 -
8
votes1
answer454
viewsIs it correct to say that encapsulation aims at cohesion? Why?
Based on the statement below, follow my question: Cohesion and Coupling are very software engineering principles used. When we want to have a mature and sustainable architecture, we must take these…
-
8
votes4
answers220
viewsHow many Strings are created in the codes below?
How many Strings the JVM actually creates during the execution time of the code snippets below? 1: String s1 = "s1"; 2: String s2 = new String("s2"); 3: String s3 = "s3"; String s4 = s3 + "s4"; 4:…
-
8
votes2
answers592
viewsBest practices regarding the use of access modifiers
How to restrict other classes from accessing certain members (methods, variables/fields, nested classes/interfaces) one-class? I would like to know the best practices for using the access modifiers…
-
8
votes1
answer2048
viewsWhat is the difference between replace() and replaceAll()?
I was reading the documentation to properly develop a mask and save without it. However I came across this doubt of methods replace and replaceAll for my string. What is the difference between the…
-
8
votes3
answers184
viewsSearch in String
I have a String of dynamic size and I need to search for the "#" cross to the next blank. I tried to use split, but without success. String texto = "oi tudo bem como vai #01?"; String[] t ; t =…
-
8
votes3
answers8112
viewsIs there any way to pass methods as a parameter?
In Java, I can pass methods as parameters? Example: public class Teste { public String metodoA(){ //faz alguma coisa } public void metodoB(double numero){ //faz alguma coisa } public void…
-
8
votes2
answers764
viewsHow to generate Thumbnail of a Video for Android?
I’m developing an app for android, one of the screens of the same should generate thumbnails videos and display them in a list. Like the image below. I was able to generate thumbnails of images, but…
-
8
votes1
answer81
viewsUser without access to resources mapped in the Security-role of the web.xml
What is the behavior of security-role of web.xml when the user does not have access to project resources? It is default for Weblogic to return a 404? This status is configurable? There is the…
-
8
votes1
answer808
viewsWhat is Event-Dispatching Thread (EDT) in graphical interfaces?
When learning to build graphical interfaces with swing/AWT, you hear a lot about the Event-Dispatching Thread (or EDT). Although I already have a certain coexistence with swing, I confess that I do…
-
8
votes2
answers248
viewsAlternative to Observable and Observer in Java 9
For testing purposes, I am porting an application from version 7 to version 9 of Java. This application has some features that use Observer and Observable. I realized that both became obsolete:…
java pattern-design characteristic-language observer-pattern java-9asked 7 years, 1 month ago Homer Simpson 3,001 -
8
votes1
answer176
viewsIs it possible to put 3 colors on a button?
I need to divide the button into 3 "equal pieces" and each piece has a different color. For example, a button with the colors Blue, Green and Red, each occupying 33.3% space. How to do this?…
-
8
votes2
answers168
viewsWhat makes an object eligible to be allocated in the stack?
Article link: http://www.vogella.com/tutorials/JavaPerformance/article.html#Escape%20Analysis "The Programming language(Java) does not Offer the possibility to Let the Programmer decides if an…
-
8
votes5
answers993
viewsWhat is the difference between referencing an attribute directly or by get/set
As an example I have a private String atributo, so I can have two ways of referencing the same, this internally in the class: this.atributo And also: this.getAtributo(); It’s correct to say it’s…
-
8
votes4
answers835
viewsAssembling updates at runtime
When riding SELECTS at runtime we always have the problem of knowing what may or may not be coming depending on the choices made by the user. When mounting the clause WHERE we come across the…
-
8
votes1
answer1056
viewsTransfer focus from a Jtable cell right after typing time
Hello, I’m using a JTable for typing time card. I need help with this, but I’ve already done a search and nothing helped me very much. I’ve tried to do it in many ways and I couldn’t. I have several…
-
8
votes1
answer83
viewsIs there a property in Maven to access the "Resources" directory value?
Issue-based https://stackoverflow.com/q/9216557/4438007 I know I can use ${project.build.sourceDirectory} to access my source file directory. If I want to access the resource files directory, the…
-
8
votes1
answer446
viewsWhat is the Graalvm?
What is it different from JVM? And why did you create it? What is the advantage of using it? Can use on mobile? Are you an official of Oracle? Are you ready to use? Do you have any restrictions?…
-
8
votes2
answers214
viewsWhy isn’t this "for" loop infinite?
public class Loop { public static void main(String[] a) { int cont=0; for (int i=0; i>=0; i+=2, cont++); System.out.println("cont:"+cont); }} Caught my attention the condition of the loop is…
-
8
votes1
answer725
viewsDifference between Hashmap and Treemap
What are the main differences between HashMap and TreeMap? Regarding use, in which situations it is recommended to use each one?
-
8
votes4
answers635
viewsWhy can objects other than the same class access private fields from each other?
Today while I was taking a course in Udacity (Intro to Java Programming) I thought about this in the exercise Update the class Person (lesson 3 29/45). In object-oriented modeling we have the…
-
8
votes1
answer93
viewsDoes Java misjudge memory usage values or is there something wrong with the algorithm?
I was studying GC and the doubt arose when I ran it below: public class Garbage { public static long carregarMemoria() { List<Integer> list = new ArrayList<>(); for (int i = 0; i <…
-
8
votes1
answer146
viewsHow do you create a "hidden" menu?
I have a Toolbar, and I want to make a settings bar on it. However, in order not to take up space, I would like it to be possible to hide/minimize it, something similar to teamviewer’s chat. My…
-
8
votes1
answer3889
viewsjava.lang.Unsupportedclassversionerror: Unsupported major.minor version 52.0 when running JAR
I have a project in Netbeans and I have to pass it to test for other users. I am running it on Ubuntu 14 and running the following command to run . jar: java -jar "TesteTableYasc.jar" However, when…
javaasked 8 years ago Renan Alboy 119