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
-
4
votes2
answers184
viewsI cannot format date
I’m trying to format one date to look like another, the first comes straight from the bank but the other needs to be in the same format. Calendar cal = Calendar.getInstance(); SimpleDateFormat df =…
-
4
votes1
answer119
viewsError: in Builder cannot be Applied
I’m developing a simple calculator. I am checking if one of the fields is null open a Alertdialog, however I am with the error in Builder cannot be Applied, no this do Alertdialog.Builder. Can…
-
4
votes1
answer250
viewsAdd 1 minute to the hour
I have a problem solving an exercise. It may be easy but I’m not finding the right solution. I have the following class Time public final class Time { private final int hours; private final int…
-
4
votes1
answer101
viewsGet the least significant bit of an integer in Java
I’m trying to do a bit manipulation in java, but I have a certain problem. I’m storing any number in an int and trying to get the least significant bit of it, but I don’t know how to do that. For…
-
4
votes2
answers314
viewsNavigation Drawer customized and colorful
Hello, what I wanted to do was to be able to put colorful icons in the navigation, as I can do this? The images I have in my project are colorful but in navigation they only turn gray like this. I…
-
4
votes3
answers354
viewsClose() method in Try and catch blocks is necessary?
I am studying Java with database and after seeing a little more about this method close() and this protected block, I was a little confused, because in some codes and articles I see that was not…
-
4
votes2
answers378
viewsLibrary loading at runtime
Is there any contraindication in loading libraries .jar at runtime? I found this code that does this: URLClassLoader sysloader = (URLClassLoader) ClassLoader.getSystemClassLoader(); Class sysclass =…
-
4
votes3
answers681
viewsExtract date with Regex
I’m trying to extract a date from a string, but I’m not getting it. Example: String stringQualquer = "um teste qualquer12/02/1998 19/09/1880 Nulo"; I want to pick up the first date of this example…
-
4
votes1
answer438
viewsWhat is the Java Constant pool?
I am reading the Java Virtual Machine Specification to go a little deeper and I didn’t fully understand what the Constant pool table is. For example, when speaking da run-time Constant pool…
-
4
votes1
answer979
viewsHow to catch the date and minimum time of the day with Localdatetime
I have this dateHora in the database: 21/07/18 15:52:00,000000000 When the query passes by parameter one LocalDateTime, I want to list all the dates that start the day. How to get the minimum date…
-
4
votes4
answers430
viewsPrint variable inside a repeat structure
Not recognizing the variable soma because she’s inside the loop. What do I do to fix it? public static void main(String[] args) { int tipo; int restante = 0; int bim = 4; //double soma= 0; double[]…
-
4
votes1
answer582
viewsHow to find the class that called a method another class?
I wanted to know if there is any way to get the class that called a method within that method. For example: public class A { public void metodoA() { B.metodoB(); } } public static B { public void…
javaasked 6 years, 2 months ago Felipe Avelar 9,507 -
4
votes1
answer2803
viewsConvert Localdate to Localdatetime
I have in my Filter class the following attributes: private LocalDate periodoDe; private LocalDate periodoAte; However, the object in which the information is located the attribute that will be…
-
4
votes2
answers1950
viewsClose all the Activities
I own 3 activities: splash_screen MainActivity error_webview To Activity error_webview has two buttons, one to open the splash_screen and another to close (Exit), but wanted to click on "Exit" to…
-
4
votes1
answer309
viewsHow to handle a JSON format string?
Let’s say I receive the following content that is stored in a String: { "client_id": 1580, "videos": 4, "remote_urls": [{ "url": "rtsp://aniceurl.com" }, { "url": "rtsp://aniceurl.com" }, { "url":…
-
4
votes3
answers158
viewsDeclaration of Java variables
Is there any difference between the two statements: First: int a; int b; Second: int a, b; Which is the best? Are the variables closer in memory or is that just a myth? Is there any significant…
-
4
votes2
answers649
viewsDelete files created more than 10 days ago, saving the latest if everyone from the list has more than 10 days of creation
I did this question where doubt was how to delete files with more than 10 days of creation. I recover them from a directory and the code has already been implemented and is functional. However, I…
-
4
votes2
answers214
viewsTrying to understand the Java print
Watch the code right below; public class Dois { public static void main(String[] args) { int a = 3; int b = 4; System.out.print(" " + 7 + 2 + " "); } } The score is 72, but I thought the result was…
-
4
votes1
answer326
viewsCopy and write image launches java.lang.Illegalargumentexception: image == null!
I created an algorithm to traverse a directory tree and mirror its contents. The exception is when the program enters a directory with 400 images. It copies the images until it reaches an image…
javaasked 8 years, 3 months ago Vítor Marçal 172 -
4
votes1
answer1116
viewsChange title bar and window icon
I want to change the title bar icon of the Java window, as shown below: I’m going the method initComponents() and leaving as it is in the code below, but the line setIconImage(iconeTitulo); is left…
-
4
votes3
answers604
viewsHigh-box text button in Android API < 14
We see that at the launch of Android 5.0 Lolipop came Material Design that has indeed changed a lot on Android and along with this, the component of Dialogs which by default comes with the high text…
-
4
votes1
answer1091
viewsBest way to go through a Hashset
I’m used to programming in PHP and now I’m studying Java, and the Collections API is something new and very interesting for me. I searched the internet and easily found several ways to go through a…
-
4
votes1
answer1169
viewsCheck that the graph is connected
Can anyone tell me how I can implement a method that checks me if an undirected graph is connected and, if not, returns its related components? public void connectComps(){…
-
4
votes4
answers4853
viewsWhat kind of return of a select Count(*) in Spring JPA?
I need to know the type of return that Spring JPA returns to put in the Service package, because it is giving a NullPointerException: Dao: public interface PlaylistDao extends…
-
4
votes1
answer322
viewsWhat are the Jeps in Java?
I was watching the backlog of JDK 12 and saw that the amendments are all mentioned as Jeps. Inclusive, in the list of Features has "targeted Jeps for JDK 12 until then". From what I’ve seen, a JEP…
-
4
votes1
answer441
viewsPopulate Array args parameters without exiting Eclipse
I have parameters that are passed when running the . jar of my code, in args, as in this example: public static void main(String[] args) { final File diretorio = new File(args[0]); final String…
-
4
votes2
answers992
viewsIs it possible to pass a method as a parameter to run on a thread?
I have an application where each process is called by a single method and this process needs to run in a thread. The code of the threads is identical in all, changing only the content of the method…
-
4
votes2
answers525
viewsNullpointerexception in java. Save image in bin folder for the software to run error-free?
I’m developing a project in java and placing images in jLabels, however, every time I run the program, it appears a message "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException"…
-
4
votes1
answer90
viewsFormat Time using initBinder
I need to catch the time with the "hh:mm" format but it is not working, follow the error also to better specify: Whitelabel Error Page This application has no Explicit Mapping for /error, so you are…
-
4
votes1
answer153
viewsImages are repeating in Imageviews
I have 54 images need to show only 8, but have to have a random selection and can not repeat, I am programming on the platform of Android Studio. I use this code it works smoothly, shows the results…
-
4
votes1
answer715
viewsHow to pass parameters for IN clauses in Jasperreports?
I have a question in the passage of a parameter in Ireport. I need to pass a list as a parameter. Example: In SQL code the query looks like this: SELECT * FROM TABELA WHERE COD IN (1,2,3,4) In…
-
4
votes1
answer506
viewsI cannot insert into Mongodb using Java
I’m new in Mongo, I’m trying to make an Insert in the bank but it’s a problem when inserting import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBCollection; import…
-
4
votes1
answer57
views"illegal start of Expression" when compiling on CMD
I have the mini program, which I will show you next. When compiling at the command prompt, I got an error on line 47 which says: illegal start of Expression I have in the program a list of entries…
-
4
votes1
answer580
viewsLine break with <br> tag causes spacing in PDF generated
When converting html to pdf using Flying saucer in java, the following failure occurs in the pdf file; a spacing between the last sentences, before the line break of the paragraph. This gives the…
-
4
votes1
answer86
viewsError while Browsing Web Wervice
I am doing a query of customers in a web service, step the key to see what it returns me tells that I did not pass the key, what I may be doing wrong in the method? That’s the .xml of consultation…
-
4
votes1
answer306
viewsAdjust Alertdialog with Open Keyboard
I have the following problem I have a Alertdialog When the keyboard is opened, the dialog goes up, but part of the dialog is hidden.. it does not adjust the height as per keyboard XML dialog:…
-
4
votes1
answer303
viewsVariable that changes according to the button pressed
I have two different methods on two different buttons. the Method onE adding up 3 the variable and the Method onM that takes -1 variable. The problem is that when I put this variable to appear in…
-
4
votes1
answer1078
viewsDelay in Java
Is it possible to delay in Java? Like for example, I have two messages and I want the second one to appear just a few seconds later,?
-
4
votes1
answer131
viewsForeign key recording as null
Foreign key is writing as null. I have done several searches I could not find a solution. Could help me find my error. This is an example that I searched on the internet, if I can popular the…
-
4
votes1
answer88
viewsSparsearray vs Hashmap what’s the difference?
I was doing my daily refactoring and came across a warning. use new Sparsearray(...) to Instead for Better performance Okay, but what’s the difference between Map and SparseArray? This is my code:…
-
4
votes1
answer2052
viewsConvert Roman number to decimal
I’m doing an exercise where I need to convert a typed Roman number, and the program returns a decimal number. My algorithm: import java.util.Scanner; public class NumerosRomanos { public static void…
-
4
votes2
answers608
viewsHow do I know which Arraylist objects are being modified or deleted?
I own a ArrayList that this preloaded with some objects of the type of my class Person, see: ArrayList<Pessoa> listaDePessoas = new ArrayList<>(); listaDePessoas.add(new Pessoa("Joao",…
-
4
votes1
answer698
views -
4
votes1
answer96
viewsHow does provides...with and 'uses' work in modular Java?
In Java 9, as a result of the Jigsaw project, we gained the ability to define modules. The modules are very simple, but there are still two things that confuse me in them, which is the use of…
-
4
votes2
answers3140
views -
4
votes3
answers2837
viewsHow to rename a java file
Given my code below: import java.io.File; public class App { public static void main(String[] args) { File diretorio = new File("/home/douglas/roms"); File[] arquivos = diretorio.listFiles(); for…
-
4
votes1
answer75
viewsWhen to use local classes in Java?
I learned that it is possible to declare classes within blocks as methods, for example: void exemplo() { class teste { } } But when local classes come in handy?…
-
4
votes2
answers88
viewsWhen compiling the code, both numero1 and numero2 display the same value even having an increment
public class IncrementoDecremento{ public static void main(String[] args) { Integer numero1 = 10; Integer numero2 = ++numero1; System.out.println("numero: " + numero1 + ", numero2: " + numero2); } }…
-
4
votes2
answers466
viewsComparing words from a text to an Enum’s list
I have an Enum that contains a list of values. I have a method where I receive text as a parameter. This method, besides going through Enum, breaks the text by words. The main function of the method…
-
4
votes2
answers253
viewsCheck and edit a List
I own a List: private List<Geracao> lista; This list will be filled with data from a database: lista = dao.findAll(); The method findAll() : @SuppressWarnings("unchecked") @Override public…