Most anwered "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
-
11
votes8
answers2292
viewsWhy create an object using the superclass?
Given the following code: public class Musico { public void tocaInstrumento() { // faz algo } } . public class Baterista extends Musico { public void giraBaqueta() { // faz algo } } . public class…
-
19
votes8
answers5853
viewsRecognize word repeats in String
I have a text inside a StringBuffer and I need to check and mark the words that appear more than once. At first I used a circular row of 10 positions, because I am interested only repeated words in…
-
18
votes8
answers2184
viewsHow to know all possible combinations of 0 and 1 in Java?
What possible combinations can I get only with numbers 0 and 1 using 5 digits (digits)? For example: 00000 00001 00011 ... 11111. I wanted to keep all the combinations, but I don’t know how to find…
-
156
votes7
answers20768
viewsHow to protect source code?
I am thinking of making an application to sell, I would like to know how to protect my source code to keep my software safe. I saw the Java bytecodes, stored in the file .class are easily converted…
-
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, 8 months ago Maicon Herverton 877 -
4
votes7
answers10560
viewsHow to test if an Edittext is empty?
I would like to know how I do to test whether a Edittext is empty or filled on Android. For example, I want to make an app that will perform a registration, but there are fields that cannot be empty…
-
31
votes6
answers36799
viewsHow to read a text file in Java?
I have the file called dados.txt and I want to put it on String. For example: String texto = lerArquivo("conteudo.txt"); Question How to write this method lerArquivo()?…
-
16
votes6
answers14835
viewsAndroid app development: what are the tools and language to start a project?
I would like to venture into creating apps for Android. At first I would make one just for own use. What tools would I need to build my development environment? My application would use database,…
-
13
votes6
answers1170
viewsWhy is it not possible to define an interface with static methods?
I would like to force some of my classes to be implemented in Singleton, but I came across the following situation. interface ICharacterSingleton{ static Characters getInstancia(); } public static…
-
71
votes6
answers56799
viewsWhat is Nullpointerexception and what are its main causes?
What are the exceptions NullPointerException? What are its main causes? What methods/practices can be used to prevent?
-
4
votes6
answers201
viewsHow to remove 2 digits from each item in the list?
I have a list/array: var lista['01.um','02.dois','03.tres'] I need to create a new list like this: lista['01','02','03'] I know little of Groovy and Java, which is the correct way to create the…
-
14
votes6
answers1655
viewsHeritage and Polymorphism
I have the class Funcionario. private String nome; private int idade; public function vender (Funcionario f) { ... } I have the subclasses Gerente and Professor that inherit (extend) from…
-
2
votes6
answers615
viewsRegular Expressions with Java Patterns
I need to do a college exercise, which is this: Validate with regular expressions any word that contains exactly two characters 'a' and two characters 'b' or more. I made the following expression in…
-
2
votes6
answers2011
views -
5
votes6
answers12886
viewsDoubt about logical operators && e || in Java
I have the following code in my app: if (aquaName != null && !aquaName.getText().toString().isEmpty()){ values.put(NAME_COLUMN, aquaName.getText().toString().trim()); } else {…
-
2
votes6
answers3996
viewsCheck if Edittext is empty
Hello guys I’m making an app on android studio but I don’t know exactly how to check if the text fields are empty, I tried the following solution in the code below : public class MainActivity…
-
8
votes6
answers422
viewsHow to "call" this correctly?
When the Elements are inside the onCreate, use the (this) it’s very easy... Example 1 : that works from within onCreate itself protected void onCreate(Bundle savedInstanceState) { Spinner spinner =…
-
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…
-
5
votes6
answers8998
viewsSum of multiples of 3 or 5
I’m trying to build a program that finds and adds the multiples of 3 or 5 below 1000. The problem is that is returning a result of the sum that does not match what I asked. package basicojava;…
-
4
votes6
answers2089
viewsCheck if a String contains two words
I have a problem with this exercise here: Write a class that validates data (Validacao), with a method to validate a given name (ehNomeValido(nome)). The method must return true pass the following…
-
37
votes5
answers22775
viewsWhat is the best way to iterate objects on a Hashmap?
What is the best way to iterate objects into one HashMap in Java to gain access to the key and value of each entry?
-
41
votes5
answers32714
viewsJava Library for Brazilian Electronic Invoice (Nfe)
I’ve been developing an enterprise management system for some time. I need to add to it the electronic invoice issuance functionality in the Brazilian standard. Is there a well tested and preferably…
-
10
votes5
answers2222
viewsWhich libraries to develop a Restful API in JAVA?
I’m a beginner in java and would like to create a RESTFUL API but I don’t know which library to use or how to use it. Can someone refer me good tutorials or some libraries for study. I would like to…
-
1
votes5
answers4549
viewsHow to pick up images on the internet through Java?
I am very beginner in Java and need to get some images from the internet to insert in my project (there are 5 images). Follow example links: www.tempoagr/tempo/Irati/temp1…
-
4
votes5
answers6040
viewsWhat tool to use to convert a visually developed UML to code?
I need an Eclipse tool/plugin that allows me to develop diagrams of classes, activities and sequence in UML and that manages the code. I usually use Eclipse with Omondo plugin, but it seems to be…
-
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…
-
2
votes5
answers1154
viewsMap does not load, showing error
I’m starting to develop on Android, only I came across a problem to generate a simple map, I’ve seen and reviewed the documentation of Google Developer and other internet tutorials that show how…
-
3
votes5
answers411
viewsHow to avoid a comparison by brute force?
Possessing a class of any kind ClassA which has an attribute value and that, depending on the type of value i need to perform an operation differently, as I would avoid a gross comparison, as in the…
-
11
votes5
answers61683
viewsUsing line break " n" in Java
What problem can a Java programmer have when using "\n" to jump line? Observing: I’ve used it for N reasons, record a file TXT and others.
-
2
votes5
answers18470
viewsdelete repeated values java array
I’m trying to print an Array without repeats, which means I have: ja={1,2,3,3,4,5,6,6,8,9}; and the result will be: jaresul={1,2,3,4,5,6,8,9} ideas?…
-
5
votes5
answers13518
viewsHide the keyboard
As soon as the user clicks on one of EditText from my Android app, the keyboard appears, however, it does not disappear when you finish typing and click off it. I would like to know which method…
-
81
votes5
answers3667
viewsIs there any downside to always capturing Exception and not something more specific?
When I write code in Java and try to treat exceptions I usually simply use the superclass Exception, not linking to the specific class and it usually works. There is some inconvenience in doing…
-
14
votes5
answers1721
viewsIs it possible to change the type of the variable in Java?
Is it possible to change the type of my variable in Java? For example, I created a variable x, she being a Double: double x; I want to continue using my variable x but she is now a int: int x;…
-
4
votes5
answers26088
viewsRegistration problem (Column Count doesn’t match value Count at Row 1)
I am having the error "Column Count doesn’t match value Count at Row 1" when I try to register. I already checked my comic book and everything seems to be in order but nothing to solve this mistake.…
-
6
votes5
answers1382
viewsNo return on method?
I have a method where its function is to read a file and store the value written in the file in a variable and return the variable,: public String addItemCreative(File f){ String line = null; try{…
-
15
votes5
answers1643
viewsDifference between private and final methods
Studying methods and final classes in Deitel’s book "How to program in Java 6 ed." I came across the following proposition: The declared private methods are implicitly final because it is impossible…
-
4
votes5
answers5903
viewsCapture filename in directory
The following method takes the name of the files of a given directory and displays them on the screen, the problem is that the .listfiles() returns the number of bytes and not the number of files,…
-
32
votes5
answers10820
viewsHow to Reverse a String?
A user will enter a sentence and I must display this inverted sentence in upper case. How can I do this? import javax.swing.JOptionPane; public class ExerLar01 { public static void main(String…
-
10
votes5
answers12645
viewsHow to create a vector without determining its size in Java?
I have a class TesteAplicacao that is to test and a class Teste with attributes and methods. When creating a vector in Java: Teste[] t = new Teste[10];// veja que teve definir um tamanho It would be…
-
2
votes5
answers1896
viewsChange Button Background
How can I change the background of a Button click on it? For example: I have the shape01 and the shape02, for default the Button this with the shape01, when clicking on it I need to change to the…
-
21
votes5
answers1899
viewsIs dealing with business rules in the model bad practice?
This is something that may seem simple, but it is not. After all how to define whether a rule should be in the service layer or in the model itself? To illustrate, think of the following: We have an…
-
2
votes5
answers3766
viewsJava - simple program (finding cousins) - does not run
I’m starting to learn java, I’m using the Java book to Beguinners Guide and this little problem appeared to find the primes of 1 - 100 and print on the screen. I made the following code. class…
-
4
votes5
answers1088
viewsDigits in a java string
How do I find out how many digits a java string has ? For example, user entered with "exemplo123", the string has 3 digits. I’m using this function but it’s not working: private static int…
-
3
votes5
answers23968
viewsHow to get and format current date and time?
I would like to know how to get the current date and time and then format them in JAVA. For example, I have these two values: 23062017 212010 I want to store each value in a variable, and then I…
-
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…
-
28
votes5
answers1775
viewsWhy is it bad practice to have int attributes?
I saw in the answer to that question /questions/17015/qual-o-uso-de-uma-variável-estática-ou-final-em-java/17136#17136, that: It is bad practice to have int attributes, unless they are "constant" or…
-
9
votes5
answers8188
viewsBest factor calculation algorithm
So I’m learning to develop in Java. The teacher asked me to develop a method for Factorial. And also show on the screen what is happening, for example: 3! = 3 X 2 X 1 = 6 In fact, I made it happen,…
-
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…
-
0
votes5
answers153
viewsCall the Java method
I’m doing some POO exercises and I can’t call the method ligar of my code. public class Telefone { public String modelo; public int numeros; public boolean antena; void status(){…
-
1
votes5
answers578
viewsHow to validate when Resultset does not find any value?
I’m trying to build a Java function pesquisarCliente where it must be consulted in the Database whether it exists or not. If there is more than one result you should return all records, if you do…