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
-
10
votes3
answers2338
viewsSplash Screen loading with application
My application, when starting, does the first search in the database. How I use the Hibernate, this first connection is a little more time consuming as it assembles the entire bank mapping. I’m…
-
10
votes3
answers694
viewsWhat best practices when implementing requests?
When implementing calls to a webservice I have been working with the following scheme: I implement a class that extends AsynkTask and within the method doInBackground() make the call to my service.…
-
10
votes1
answer470
viewsDLL’s communication with Java
I am layman on the subject of how to communicate with DLL’s using the JAVA platform. Would you like to know where to start studying, if there is any framework? I’ve heard of JNI but I don’t know if…
-
10
votes1
answer732
viewsHelp with Javafx form
Hello, I imagine my doubt is simple but I haven’t found anything in the forums of life (probably because I don’t use the correct terms in the search). I am creating a form for students in Javafx…
-
10
votes1
answer227
viewsDifference between printf and format
Is there any difference between using the printf and the format? Example 01: float nota = 5.3f System.out.printf ("Sua nota: %.2f", nota) Example 02: float nota = 5.3f System.out.format ("Sua nota:…
-
10
votes0
answers558
viewsFacebook Login button has no action
I’m testing the Facebook Login API, but by clicking the button Log in with Facebook nothing happens, only the bar where it has the time turns black for a moment and then comes back with the color of…
java android facebook facebook-sdk facebook-apiasked 8 years, 11 months ago Giancarlo Abel Giulian 3,999 -
10
votes1
answer112
viewsWhat is the purpose of "&" in the generic type statement?
In that code, the author creates a class as follows: public abstract class GlyphIcon<T extends Enum<T> & GlyphIcons> extends Text { /* ... */ } My question is to understand the…
-
10
votes4
answers6957
viewsWhat is the difference between i++ and ++i?
I found an excerpt of code in an application that I’m continuing that I hadn’t seen before (or never noticed). Casually I always used i++ in a loop of repetition, for example, however this passage…
-
10
votes1
answer181
viewsWhat is the use of underline in numerical literals?
What is the use of underline (_) in the situations below: float pi = 3.14159_26535_89793_23846; long bytes = 00101001_00100110_01100001; int n = 1____________________1;…
-
10
votes4
answers2204
viewsHow to check if a Localdate is a weekend?
I have the following date of type LocalDate 2017-12-21 How to check if it’s a weekend? I tried to use the Calendar, but it seems to only work with Date.…
-
10
votes4
answers14893
viewsAdvantage and advantage between onClick and setOnClickListener
I have a certain situation where we see that it is possible to create in the XML file a property called onClick: onClick: XML: <Button android:layout_height="@dimen/edittext_min_height"…
-
10
votes3
answers6900
viewsWhat’s the difference between Return and break in a switch case?
In some situations it is necessary to practice the switch case for optimization and improvement of code. I have an application developed for Android using Java, which in case is used of both…
-
10
votes2
answers1800
viewsWhat is the relationship between encapsulation and polymorphism?
A few days ago, I was talking to a friend about Java, and asked what part of the story they were studying. Then he replied that they were starting inheritance studies. As they were too late, I asked…
-
10
votes1
answer2621
viewsWhy use Class.forName when connecting to the database?
For database connection, in addition to the inclusion of the JDBC driver, most articles and examples use the static method Class.forName(String). See the example with Mysql:…
-
10
votes2
answers1420
viewsHow to split a String that contains white spaces at the beginning?
For the problem in question, I need to remove all the special characters and spaces and count the new possible outputs. My intention is to separate the string with the method split(). For this,…
-
10
votes3
answers341
viewsWhy am I calling the subclass method?
public class A { public String imprimir() { return "A"; } } public class B extends A { public String imprimir() { return "B"; } } public class C extends B { public String imprimir() { return "C"; }…
-
10
votes2
answers97
viewsIs it correct to program returning exceptions to the expected event?
When we are developing a software we can go through situations where something happens that we are not expecting and usually when it happens in many programming languages we can treat it within…
-
9
votes2
answers3152
viewsBuild generation in the Maven project
I would like to generate a Java build using Maven, where the generated file name . jar was the same number as the last revision of the SVN repository. Example: My last build generated has the…
-
9
votes1
answer1077
viewsHow to run a group of suites in Junit?
I have the following suites below: @RunWith(Suite.class) // this other matters @Suite.SuiteClasses({ TestC.class, TestB.class, TestA.class }) public class MySuiteA {} @RunWith(Suite.class) // this…
-
9
votes5
answers10429
viewsHow to exchange the value of two variables in Java?
You can create a Java function that changes the value of two variables without having to declare a temporary variable? For example: int a = 8, b = 3; if(a > b) { // algo aqui, sem declarar uma…
-
9
votes1
answer5562
viewsCreating timer with JAVA
Guys in need of a help here want to make a timer with Jframe more not being able to make it repeat until it reaches zero, and if I leave the setRepeats in true I can’t make it stop when it reaches…
-
9
votes3
answers949
viewsScrypt, Bcrypt or anything else
I’m choosing a hash algorithm for passwords from a system I develop. At the beginning of my "programmatic" I used the MD5, the SHA-1 and its derivantes. After a while I preferred the Whirlpool and…
-
9
votes2
answers185
viewsHow to make an IO "equivalence" in Java and C++?
I made the following code in C++: #include <iostream> template <typename type> class Foo { public: Foo(type FooTest) { std::cout << "Foo " << FooTest; } }; int main { new…
-
9
votes2
answers6704
views -
9
votes4
answers243
viewsWithin a decision structure, does the order of terms change the outcome?
Is there any difference between: if (variavelA == variavelB) and if (variavelB == variavelA) In Java and C#, is there a difference between the examples? I stress that the question is not limited to…
-
9
votes4
answers47343
viewsRemove element from an Arraylist in Java
I’m having trouble removing an element from my Arraylist, someone can help me as? public String remover(Pessoa umaPessoa) { String mensagem = "\n******** Pessoa removida com Sucesso! ********\n";…
-
9
votes1
answer536
viewsWhy do we have to use mplements?
What’s the difference between using btn.setOnClickListener(new OnClickListener() { and public class MainActivity extends Activity implements OnClickListener{ I’ve been doing an Android course and my…
-
9
votes1
answer304
viewsRead message from USSD Android code
Using the API on Android is possible to communicate via USSD? It is possible otherwise? If yes how can I get, in Java, the reply message when entering a USSD code?
-
9
votes2
answers4470
viewsConvert date dd/mm/yyyy to yyyy-mm-dd’T'HH:mm:ss
How do I convert a date into format dd/mm/yyyy for the format supported by Sqlite yyyy-MM-dd'T'HH:mm:ss? Example: public static String converteStringEmData(String stringData) throws ParseException {…
-
9
votes2
answers7414
viewsManipulating String in Java
I have a text inside a String. I will go through this String. Going through it I need to pick up every word it contains. I thought I’d use string.split(" "); but I need to treat "." ;" "," ":" "!"…
-
9
votes1
answer5156
viewsWhat is the difference between @Inject and @EJB when injecting an EJB?
I have an EJB that relies on another EJB, so I’m going to use dependency injection to satisfy that dependency. My question is: what is the difference, advantage or disadvantage between @Inject and…
-
9
votes2
answers2765
viewsWhat is the concept and how to implement an Anemic Domain Model?
I would like to resolve the following doubts about the Anemic Model: What is the The Anemic Domain Model? What are the differences of implementation of that model compared to Object-Oriented Model?…
-
9
votes1
answer5915
viewsGeneric Tree, how to do?
I’m trying to assemble a Generic Tree in java to assemble a Boolean expression within a gene expression algorithm, this tree would hold several types of variables, I’m not sure which is the most…
-
9
votes3
answers407
viewsGenerate setters only in class constructor or generate outside constructor
In Java classes, it is common (At least in college I only see it that way) create private attributes and generate getters and setters for these attributes. But I read that you can do something a…
-
9
votes1
answer1038
viewsIs there a data structure like an associative array in Java?
Well, I’m wanting to name an Array of Strings in Java, but I wanted it to be, for example: String[] symbols; And could be declared so: symbols["name"] = "Tiago"; I know there’s no such Array, but…
-
9
votes1
answer2783
viewsHow to pass a number in scientific notation in Java?
I’m using a method not to display scientific notation DecimalFormat dfor = new DecimalFormat("#"); dfor.setMaximumFractionDigits(10); txtTexto.setText(df.format(valorDouble)); But when you press a…
-
9
votes3
answers388
viewsRefactoring of a java class
I have a Java class that contains 1756 lines (obviously not all code, has blank lines, many comments and some commented code in case it is needed in the future) I’m implementing the structure MVC…
-
9
votes2
answers3184
viewsblock "erasing" the screen for downtime
My application works as a guide for a professional illuminator, it works passively(responds via Bluetooth to user commands in your work tool) or offline where the user can operate it manually in…
-
9
votes1
answer234
viewsEncapsulation and Java Access Modifiers
A very simple question: Given that class: public class User { private String nome; //get/set public boolean fazQualquerCoisa(){ **duvida**.equals("algumacoisa"); } } Within the method did All() I…
-
9
votes1
answer27206
viewsDatabase connection - Mysql and Java
I already have a local server on my machine (localhost) with Mysql running normally. From there, I would like to connect my database with Java, but... how do I do that? Is there any Swing component…
-
9
votes2
answers3391
viewsWebbrowser/Java Browser
How I put a kind of a 'Webbrowser[. NET]' in a Java project? I know that there are free rendering engines like Gecko, which is used in Firefox. But I don’t even know where to start, even getting a…
javaasked 9 years, 5 months ago Nickolas Carlos 632 -
9
votes1
answer519
viewsSynchronized in static methods, and in nonstatic methods
If I have a class, where I have two methods one static and the other not. Is the lock the same or not? How to do for the two sharing methods, the same synchronization mechanism, ie the same lock?…
-
9
votes1
answer1656
viewsYoutube on Webview for Android app
Does anyone know how to view a Youtube video or any streaming video through a WebView? In the code below, there are three buttons. The first takes the user to the link he typed, the second is fixed…
-
9
votes1
answer6033
viewsUsing @Supresswarnings in Java
Good morning. Until when it is recommended to use the annotation @SuppressWarnings to hide a Warning of a certain problem that the compiler finds in your code and show that you know what you’re…
-
9
votes1
answer261
viewsMirroring of Database
I am developing an application in Java using database PostgreSQL, locally. I would like to know if there is a way to mirror my local database to an external server? Is there an API on Java for that…
-
9
votes2
answers1683
viewsConvert a collection from Set to List type
I have a class that has an attribute of the type of Set, because I want repeated values to be ignored, however I need to return this in the form of a List to fill in a ListView, so what is the best…
-
9
votes1
answer817
viewsSpring Security, display message when log out
I am controlling the session of my application with Spring Security, I have two rules to end the session, max-Session <session-management> <concurrency-control max-sessions="1"…
-
9
votes1
answer197
viewsif with a Matches or multiple comparisons?
Whereas I have a variable of the type String tipoResidencia that will never be null, and that I need to run a test, the default solution is this: if (tipoResidencia.equals("CASA") ||…
-
9
votes7
answers91443
viewsError: Unable to find or load the main class in Java (Eclipse or CMD)?
If you ever came across the error message: Erro: não é possível localizar nem carregar a classe principal you probably won’t be able to run your code in Java. In the eclipse I came across this…
javaasked 9 years, 3 months ago Maicon Herverton 877 -
9
votes3
answers4676
viewsIs the Finally block always run in Java?
In this code there is a block of Try/catch with a Return within it. try { alguma_coisa(); return successo; } catch (Exception e) { return falha; } finally { System.out.println("Eu não sei se será…