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
-
6
votes2
answers305
viewsIs it possible to run Acrobat Reader without putting all the way of its executable?
I am opening files in PDF format by Java and for this I am running Acrobat by Java also, follows the path line to the Acrobat executable: String cmd = "C:\\Program Files (x86)\\Adobe\\Acrobat Reader…
-
6
votes1
answer863
viewsDeadlock concept in Java
I came across the term deadlock in Java. But, I can’t understand it. So I would like to ask these questions: What is a deadlock? Why and how to avoid a deadlock?
-
6
votes1
answer2476
viewsDraw route over the street on the map
I have a feature that captures the positions of gps every 10 seconds. Every 30 seconds or if there’s a 20 degree change in the Bearing (Compare the last position with the current one) store to send…
-
6
votes3
answers110
viewsDoes the File(String) constructor create a file?
When we use the constructor method File f = new File(aquiVemOEnderecoDoArquivo), if the file does not exist, it is created?
-
6
votes1
answer259
viewsSorting algorithm, Java stream
When working with Stream I currently use the Sorted method to sort, example: Stream<Integer> stream = Stream.of(3, 2, 1); stream.sorted(); // saida será 123 What is the sorting algorithm for…
-
6
votes1
answer328
viewsIt is possible to determine the access path to the file in Function
I have a Java WEB application where I am using a Function that opens the file .pdf which I determine, but it only opens the files .pdf that are in the same folder where this saved my project,…
-
6
votes2
answers207
viewsHow to apply Stylededitorkit to a Jtextpane without inheriting this class on my screen?
I have a problem with tabulation in JTextPane and I’m trying to reduce the default value assigned to it but it’s giving an error because I have to inherit two classes (one for the JFrame and the…
-
6
votes2
answers758
viewsWhat is Fat JAR?
In my daily studies on Java on the Internet, I found some references and comments from programmers using this name "Fat JAR", in the context of configuration and deployment of Java applications. As…
-
6
votes1
answer481
viewsHow to "limit" a Jcombobox according to the selected item?
I have a JComboBox, and I limit the size of it, with the following code: jcb.setPreferredSize(new Dimension(100, 21)); However, I would like to know if there is a way that after I choose an option,…
-
6
votes1
answer3084
viewsCall a method that calls another method of the same class?
Example have the class Metodo: public class Metodo { private String string; public String mostrar(String nome, String sobrenome){ this.string = "Nome: " + nome + "Sobrenome: " + sobrenome; return…
-
6
votes2
answers99
viewsDoubt about List that does not return the result
I have this method in Java, which queries in the database and returns me a list of students. The method is searching in the BD, but does not return the data correctly... public static…
-
6
votes1
answer822
viewsWhat is the difference between the orelse() and orElseGet() methods of java.util.Optional?
What is the difference between the methods orElse() and orElseGet(), class java.util.Optional?…
-
6
votes4
answers640
viewsJava abstract class exercise doubt
I would like to ask for your help again in this exercise. This time using the abstract class. Create an abstract class FuncionarioAbstract with the attribute String name and abstract method: public…
-
6
votes1
answer292
viewsShould we create an empty constructor in Java?
It is good practice to always declare a builder, even if it is empty, for the class? I find it unnecessary, because the compiler automatically creates. I have seen people who always create and…
-
6
votes2
answers119
viewsC# properties for those who know Java
What a Java programmer needs to know about basic properties (properties) in order to read code written in C#?
-
6
votes1
answer348
viewsHow to check if a year is leap in Java?
How to know if the current year - indeed, if any year - is leap? Since I can have only the numerical value of the year, or an object representing a date (i.e. Date, Calendar, LocalDate, etc), the…
-
6
votes4
answers2097
viewsPrint arraylist information on the screen
I have a ArrayList but I’m not being able to print the data on the screen. Follows class: public class Cachorro { private String Raca; private String cor; private String nome; private String…
-
6
votes1
answer68
viewsAre Java enumerations anti-performance?
In a project I thought of exchanging whole ones for enumbut a colleague told me that enums are anti performatic.
-
6
votes2
answers1536
viewsFormat Date Return with Date and Non-string Format
I’m trying to return a date that is recorded right in the bank (1986-04-30 17:02:00), I try to convert this date to appear only "30/04/1986", but no use. The most I can get back is Wed Apr 30…
-
6
votes1
answer242
viewsAre cloned objects not equal when comparing to Object.equals()?
I was doing some equality tests, and when comparing two objects, being a clone of the other, I noticed that the equals returns false, even though the objects are identical. The return should not be…
-
6
votes2
answers720
viewsCan memory leak occur in Java?
In the C language, for example, memory leaks are common because the responsibility for shifting memory lies with the programmer. In the example below (taken from Wikipedia) we can see a classic…
-
6
votes1
answer221
viewsDoubt about inserting Javascript object
Context I am trying to make the persistence in the database of a purchase as well as all of its items. For this I am using a file .jsp. But I need to send the data from a web page. The purchase data…
-
6
votes4
answers2358
viewsReturn day of week from date in dd/mm/yyy format
I have this function that brings me the day of the week: public static String getWeek(String date){ //ex 07/03/2017 String dayWeek = "---"; GregorianCalendar gc = new GregorianCalendar(); try {…
-
6
votes1
answer329
viewsHow are expressions evaluated in Java?
Reading some references it was possible to understand the basic, but not enough to decipher the following code: public class Expression { public static void main(String[] args) { int s = 5; s += s +…
-
6
votes3
answers1428
viewsHow to define the comparison of equality between two objects present in an Arraylist?
How can I define the equality comparison behavior between two objects whose class is defined by me that are stored in an Arraylist object? Java nomecor. public class NomeCor { private String nome;…
-
6
votes1
answer5630
viewsHow to generate an executable of a program made in Eclipse?
I did a program for the company in which I work entirely on JOptionPane, just so the program would work just by opening real system windows (I thought it would be easier to run officially after the…
-
6
votes1
answer7667
viewsAndroid - Datepicker in an editText
Next, I would like a date selector to appear as soon as I click on editText I have, but what I found automatically setting the current date, I want it to be chosen... Follow the code I’ve tried so…
-
6
votes1
answer500
viewsRefresh in Webview when rotating device
I created my application via WebView, but when I rotate the screen the site gives refresh, or is back to the login, my code: Mainactivity: package com.sirseni.simpleandroidwebviewexample; import…
-
6
votes4
answers829
viewsBest approach is to filter data in the database or application?
Suppose we have a table 'Vendas' with the following columns 'estado', 'cidade', 'vendedor', 'valor'. 'estado' and the 'cidade' would be where the sale was held and 'vendedor' would be what made this…
-
6
votes1
answer127
viewsPUT and DELETE methods with Httpstream?
Can anyone tell me if it’s possible to use the HttpStream with the methods PUT and/or DELETE? HttpStream.Options options = new HttpStream.Options();…
-
6
votes1
answer343
viewsDifference between using Sqliteconnection and Java Drivermanager
I am connecting to the Sqlite database with the following code: import org.sqlite.SQLiteConnection; public SQLiteConnection conn() throws SQLException{ String path = System.getProperty("user.dir");…
-
6
votes1
answer113
viewsWhy do constants in the File class not follow the constant convention?
The convention for Java constants says that a constant should be declared with uppercase letters only and words should be separated by underscore (_). The declaration of a constant is made by the…
-
6
votes3
answers1479
viewsWhat is this "Could not find method schedule(View) in" error?
I’m calling a method, when I click the button and this error appears, but I don’t know what it means: java.lang.Illegalstateexception: Could not find method to schedule(View) in a Parent or Ancestor…
-
6
votes1
answer1224
viewsWhat is the best implementation of 'Mergesort Algorithm'?
I know the Quick Sort algorithm, but at the moment I want to analyze Merge Sort. I found two types of Merge Sort implementation on the Internet. But when I compare them to the Insertion algorithm,…
-
6
votes1
answer844
viewsHow to define the order in which components will receive focus through TAB?
To organize the component focus selection order up to version 1.4 of java, we used the method setNextFocusableComponent(). However, it was discontinued from the aforementioned version. I would like…
-
6
votes2
answers593
viewsAND operator in regex
I have the following date/time format: 25/01/2017às11:53:37 And the following regex: REGX_DATAHORA_DISTRIBUICAO = "(?<data>\d{1,2}\/\d{1,2}\/\d{4})|(?<hora>\d{1,2}:\d{1,2}:\d{1,2})"…
-
6
votes1
answer204
viewsHow to make the arrow rotate several times until it stops by itself after clicking the button?
In the question "How to rotate an arrow inside a circle using Java2d?", i managed to learn how to make the arrow rotate within the circle. Only I need to make the arrow rotate like a casino…
-
6
votes5
answers2539
viewsRegex to check if string does not end with certain characters
I’m racking my brain on the website http://www.regexplanet.com/advanced/java/index.html I’m trying to make a regex that validates some .txt not containing the characters JJ or M3 at the end of the…
-
6
votes1
answer169
viewsIs it possible to inform the size of the VARCHAR in a Namedparameter?
I’m working with a tuning of an SQL Server database. Through the query below, I can see how the bank executed some of my heaviest queries. SELECT TOP 30 deqt.TEXT AS Query, last_execution_time FROM…
-
6
votes1
answer3429
viewsUse Bundle and/or only putExtra?
To pass data between activity, have 2 forms: 1. Using Bundle: public void teste(View v) { Intent i = new Intent(this,Teste.class); Bundle bd = new Bundle(); bd.putString("site","google.com");…
-
6
votes3
answers469
viewsHow to remove spaces from a string in Java?
I’m having a question about how to remove spaces from a Java string by doing this through the for. I’m making a letter diamond, and I use a variable to create the space between the letters. A B B C…
-
6
votes1
answer219
viewsError when adding value in array, repeated values
I have two arrays, A and B. I created 3 functions in which I take a value from the beginning of array A and array B, remove the values, compare the values and if the value of A is greater than that…
-
6
votes1
answer1086
viewsPassing a list of arguments to a Jasper Reports query
I’m redoing some reports on Jasper Reports here at the company. I am migrating to have a reporting service agnostic the SQL query structure of the report. Before, the system knew deeply how such a…
-
6
votes1
answer604
viewsIdentify JDK version from Java
I am creating an IDE and when the user presses to run the code I do the following: try { File file = new File(arquivoSelecionado.nome); try { FileWriter fw = new FileWriter(file);…
-
6
votes2
answers387
viewsHow to do concurrency control in Hibernate for INSERT in the database
I’m having a competition control problem in entering data in my web application. Context: I have 3 tables (ex: X, Y and Z) that record hospitalizations of patients (already registered). A patient…
-
6
votes1
answer58
viewsHow does an annonymous innerclass arrow a private instance variable?
Since Java does not actually have closures, but emulates behavior with a technique using Inner classes, the following code: class Test{ private int myField; private void doSomething(){…
-
6
votes3
answers425
viewsIs it mandatory to put the same attributes on different constructors?
I have these builders: //1st Constructor - Create bike with a new frame public Motociclo (String marca, String modelo, float peso, int robustez) { //Nivel 2 this.marca = validarMarca(marca);…
-
6
votes1
answer56
viewsIs it possible to access a shared variable with another thread without a competition problem?
I have that code List<Object> myList = new ArrayList<>(); public void RunOperation(){ myThread = new Thread() { @Override public void run() { for (int i = 0; i < ReallyHighNumber;…
-
6
votes1
answer1756
viewsIs it possible to create a certificate in PFX format and set an OID for some parameters?
I need to generate a certificate to simulate an e-CPF. I am creating an implementation to query and validate the digital certificate information e-CPF and e-CNPJ with my application. The extraction…
-
6
votes1
answer502
viewsManage transactions in Java EE @Transactional
I’m having trouble trying to "inherit" the transaction from Java EE of my layer of service to the layer of repository. My intention is for the transaction to target my service function. Enabling me…