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
-
2
votes1
answer166
viewsWhen will the object be eligible for the Garbagecollector?
From the code snippets below, in which the object created in new Pessoa("João") will be available for the Garbage Collector on the line: //outras instruções ? They are all independent codes. They…
-
2
votes2
answers3476
viewsGet the first letter of the last name and last name?
I am using the code below to get the first letter of the name and surname. It’s working, but I see the following problem for a longer name: Example: Carlos Eduardo Martins Dutra do Rego public…
javaasked 7 years, 8 months ago Marcia Pereira Reis 451 -
2
votes0
answers206
viewsGson Does Not Convert List to Json
Every time I try to pull all data from a database table and convert the result to json, using Gson, gives error. @GET @Path("todos") public String todos() { Gson g = new Gson(); UsuarioRepository…
-
2
votes1
answer351
viewsList files from a specific folder
I have the following code: public static final String PATH ="/Conceitos"; public static List<String> loadFilesName() throws IOException{ List<String> strings = new ArrayList<>(0);…
-
2
votes1
answer536
viewsOverloaded Constructors: Instance Initializer
From the perspective of compiler behavior and java class design what would be the justification for using the Instance Initializer block? Considering the following class: class Caneta { public…
-
2
votes0
answers162
viewsHow to generate XSD that requires sending the contents of an XML element using JAX-WS
I’m creating a web service with JAX-WS. In an operation, I receive an object that contains some attributes and I want these attributes to always come with value. @XmlRootElement…
-
2
votes1
answer1094
viewsHow do I login to Spring Security, JSF 2.2, and Managedbean?
Hello. I need some help. I am configuring Spring Security in a JSF Project 2.2. Using Annotation. I’ve been able to configure the filters. But I don’t understand how to configure login Managedbean…
-
2
votes1
answer659
viewsShow only hours in the Primefaces Legend component
How to display to the user the option to select only hours and minutes in the component <p:calendar> of Primefaces I have two fields with start and end times to select, but even putting the…
-
2
votes1
answer38
viewsCorrect creation of tables
Given my classes where Encomenda inherits from Objeto: @Entity @Table(name = "objeto") @XmlRootElement(name = "objeto") @XmlAccessorType(XmlAccessType.FIELD) @AllArgsConstructor @NoArgsConstructor…
-
2
votes1
answer650
viewsTest date at least one day earlier
System that controls Orders of Service, the moment I open a new service order I close the previous order. If the previous service order was opened on an earlier date (at least one day ago) I close…
-
2
votes1
answer915
viewsAdd it up to a firebase Child?
Hello, Would like to get the value of a Child at firebase, add a number and update Child with the result of summing up. Code on the Oncreate() uDataBase =…
-
2
votes0
answers201
viewsChange application background in "recent apps"
How to change the application background when you click the square button (recent apps)? I have already researched and some have indicated using the onPause and onStart to change the background…
-
2
votes4
answers1921
viewsHibernate does not create table automatically in mysql
I’m studying Spring with a little hibernate, where I stopped in a situation I can’t pass. I configured the code with Hibernate for creating tables in the database but when I run the application it…
-
2
votes1
answer1282
viewsChange label color according to screen state
I’m having trouble changing the color of a label’s content according to the state of my screen (enabled/disabled). I wonder how I do so I can make him change the color. I made a very simple example…
-
2
votes1
answer94
viewsHow to pass an algorithm as parameter in java?
I’m doing some time measurements on sorting algorithms and created this method that calculates the time it takes an algorithm to sort an array of disordered numbers public static double…
-
2
votes1
answer87
viewsValues are being sent nulls
For some reason the arrays are being sent null in setListGrades, but inside the log shows the normal arrays. The API is being consumed correctly, so it is null when sending this method? @Override…
-
2
votes1
answer1039
viewsSeparate address path from string
On my application JAVA, on a screen, I have fields referring to the address, I have two means of registering this address, I can pick up automatically searching for the zip code most of the…
-
2
votes2
answers590
viewsSaving result in txt file
Guys how would I save the output from the program to txt file ? in the example I call cmd and ask you to accomplish something, wanted to save the result in a text file. import…
-
2
votes1
answer1049
viewsPositioning components within a Jframe
I’m trying to position some components on a screen, but it’s not working very well. So I created a kind of simple example to illustrate the problem. I accept subjects to perfect the way I’m doing…
-
2
votes3
answers572
viewsHow to map an entity with a composite key using JPA?
@Entity @Table(name = "USUARIO") public class Usuario implements Serializable { @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column(name = "ID") private Long id; @Column(name = "USER_NAME",…
-
2
votes1
answer94
viewsHow to get the Listview reference of a Listfragment?
I’m with a ListFragment trying to access the ListView in which the Adapter inserted the objects, but the findViewById is returning null, anyone has any idea? The XML Fragment code: <?xml…
java android listview android-fragment android-adapterasked 7 years, 6 months ago Danilo Nadolny Vizentainer 23 -
2
votes0
answers340
viewsSelect * from Table and No Select * from Entityname - JPA JAVA
My query was built like this, but when it does the request: @Query(value = "SELECT CT.id FROM CursoTurno AS CT LEFT JOIN Curso AS C ON C.id = CT.curso_id INNER JOIN Turno AS T ON T.id = CT.turno_id…
-
2
votes1
answer64
viewsHow to call initLoader inside Onclicklistener
Hi, it is possible to call an initLoader inside an Onclicklistener? I need it to be started after the editText data entry, because the network request returns error 400, URL enters without the user…
-
2
votes0
answers148
viewsGradle build error in Secure Paging API - Java
I’m trying to implement the Secure Pag API on my system, I was looking at the step by step that it asks to download the repository on Github, then access the folder source and then execute the…
-
2
votes1
answer771
viewsFibonacci sequence
I need to do an exercise on the Fibonacci sequence: Each new term in the Fibonacci sequence is generated from the sum of the previous 2 terms. If we start with 1 and 2, the first ten numbers will…
-
2
votes1
answer193
viewsFileupload does not load the Listener into JSF 2.2
I am migrating a project to JEE7 from Primefaces 3.5 to 5.0 and I have a problem with Fileupload. Does not load the file into the JSF 2.2 Event Manager. Follow the xhtml code: <p:fileUpload…
-
2
votes0
answers306
views -
2
votes2
answers1982
viewsHow to call a method within a System.out.println?
It has how to call a method within a System.out.println(" ");? Follows my code: package ExerciciosReferenciaDeObjetos; public class Aluno { private String nome; private int matricula; private float…
-
2
votes1
answer531
viewsUpload and Donwload JSF + Primefaces + Mysql files
How to recover the file name saved as BLOB from the database and display on screen? I am using a loop, to recover, the value saved in the database column, but returns memory values ([B@2248bd40):…
-
2
votes0
answers192
viewsSend JPG via JSON
I need to send this image to my post api, private void onCaptureImageResult(Intent data) { Bitmap thumbnail = (Bitmap) data.getExtras().get("data"); ByteArrayOutputStream bytes = new…
-
2
votes2
answers85
viewsInclusion of data by the operator
I built the code below but when I insert the data the system shows error. package tarefaBD; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import…
-
2
votes0
answers158
viewsHow to return a MAP using JPA’s native Query?
I need to consult a bank that is already established, populated and maintained by another application. So I don’t have the entities in my project and I didn’t want to create. I am using Spring Boot…
-
2
votes1
answer65
viewsIs it correct to cast an exception within a Synchronized?
In my app there are some threads that access the database and control this competition using the totalcross Lock. My question is: Can I allow exceptions to be thrown into a Synchronized block ? or…
-
2
votes1
answer3277
viewsHow to change item in an Arraylist index?
I’m having trouble with this array exercise: a) Create the Blocodenotes class that has an attribute ArrayList<String> called notes. Create methods to insert, remove and fetch notes. Create a…
-
2
votes1
answer16499
viewsError: Could not find or load main class solved
I am training for OBI and am picking up the exercises on your website and sending to run on it too, but my code is giving error: Error: Could not find or load main class solved "Error: Unable to…
javaasked 7 years, 6 months ago Mr Minerin 31 -
2
votes1
answer455
viewsModifying a Jslider
I’d like to do two things: first: add a label, or anything, that allows me to put a "text" below the colors. Example in illustration: 2nd: Make the pointer/indicator of the slider, go to the color…
-
2
votes2
answers691
viewsCorrect use of Override and constructor
I was asked to create a current account class that had an attribute representing the fee charged for each transaction of two attributes of the superclass (credit/debit). And have been asked to…
-
2
votes1
answer179
viewsFinal local variable in Inner class in Java 8
There was a modification between Java 7 and 8 versions. Where in Java 7 for a local variable to be used within a inner class should be declared final. Now compiling with Java 8, this local variable…
-
2
votes2
answers629
viewsHow to capture CMC7 code with the Tesseract API?
To contextualize my problem, I am reading characters in images using the Tesseract API for Java, tess4j. More specifically, the images are of bank checks, where I need to capture the code CMC7. What…
-
2
votes1
answer393
viewsHow to access an object attribute within a stack of Objects
I have several objects of the Vehicle class with board, model and anoFabri as attributes, inside a stack I created (Stack.java). I need to apply a method in the Stack class, which removes objects…
-
2
votes1
answer1860
viewsWebview opens browser
I made an application via Webview on Androidstudio, everything quiet without errors but when I put the information to login in my webview opens the default browser, I would like it to open in…
-
2
votes2
answers40
viewsSearching and comparing java
I am preparing a program that must request the RA of a student, the RA must be greater than zero. Soon after I want to buy the second RA typed to verify that it has not already been registered. I…
-
2
votes1
answer494
viewsRepeated Elements Linked List
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TrabalhoFinal; import java.util.Collection; import java.util.Iterator; /** * * @author rjs */…
-
2
votes6
answers7179
viewsSimple Solution for Fibonacci Algorithm
I have this statement in hand: Given the Fibonacci sequence 1 1 2 3 5 8 13 ... n, write an algorithm to generate the sequence to the nth term, which must be provided by the user. For example, if the…
-
2
votes1
answer1001
viewsHow to open a Alertdialog?
Well, I’m learning now about Fragments. From what I understand, fragments are components, something you want to repeat on several screens, without having to keep creating several classes or…
-
2
votes1
answer121
viewsData persistence problem using JPA
I have a class that has two attributes, start time and end time, both Date type. @Temporal(TemporalType.TIME) private Date horarioInicio; @Temporal(TemporalType.TIME) private Date horarioFinal; In…
-
2
votes1
answer110
viewsCheck the arrayList object at runtime
I have an arraylist with three positions. I added to the array, objects like Manager, Seller and Technician, respectively. Using the getClass, would like to know how do I know which object is in…
-
2
votes1
answer115
viewsTrigger an event by pressing the 2x volume button?
I would like to trigger an event just by pressing the 2x volume button quickly. I have the following code, but it fires by pressing the button only once. How to make it fire only if pressed 2 times…
-
2
votes1
answer72
viewsEqual functions if
I have if and Else codes, but I don’t know very well,I’ll explain what I wanted to do , in my app, if I typed Right , posted in api as id - X ,if I typed Romance,posted with Id - Y , but he’s only…
-
2
votes2
answers83
viewsI don’t understand why it doesn’t work
I have a problem here, I don’t know why it doesn’t print anything. There are no compilation errors, but it doesn’t work. Class Students import java.io.PrintStream; public class Alunos { private…
javaasked 7 years, 5 months ago Pedro Gouveia 505