Questions tagged as 'java'

3
answers

Where should I put a calculation method? In the entity itself or in the business class?

I have an architectural doubt, I believe. I need to create a method that receives a date range and an entity on which to perform a search in the period quoted. In fact, to ask this question it matters little what the parameters of this method...
asked by 27.04.2016 / 21:52
2
answers

Kotlin for creation and APIs: is it only for Android?

I saw some features offered by the Kotlin tool, even more so when it comes to saving lines of code and verbosity generated in Java. How is the tool for generating services and consumed by Web applications? Like Angular 2+, for example ... Wou...
asked by 12.11.2018 / 04:38
1
answer

Adding an object to a collection returns "can not be cast to java.lang.Comparable"

The code is this: public class Catalogo { SortedSet<Produto> lProdutos = new TreeSet(); public void addProduto(int cod, String desc, float preco){ try{ Produto p = new Produto(cod, desc, preco); lProdutos.add(p); } catch...
asked by 19.11.2018 / 16:40
2
answers

Instantiate an object through the interface and access methods not present in it

I have the following interface: interface something { void doSomething(); } And I have a class that implements this interface and adds another method that does not contain the interface: public class Whatever implements something {...
asked by 26.01.2017 / 00:30
1
answer

What are the options for initializing a final variable in a Java class?

Given the class below, what are the initialization options of the variable ANGLE , since final can be initialized only once? class Triangle { public int base; public int height; private final double ANGLE; }     
asked by 24.02.2017 / 05:01
4
answers

Is there performance gain using .replace () instead of .put () in a Map?

There is some performance gain using the .replace() method instead of using .put() in a Map . Studying Maps I noticed that the .put() and .replace() method have practically the same function. I made a...
asked by 31.07.2018 / 20:26
2
answers

Why is the condition of j never satisfied with "||", and why is i satisfied with "&&"?

package aulas; public class Aula{ public static void main(String[] args){ for(int i = 0, j = 0; i < 100 || j < 50; ++i); //Quando troco o operador lógico para && é impresso até 99, porém //quando u...
asked by 20.08.2017 / 03:54
1
answer

Could anyone tell me what happens in this method?

I have a method that does some things that I would like to know what it is ... just explain me out loud please? private static byte[] readFully(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream()...
asked by 25.01.2017 / 15:32
3
answers

Format String

I have the following sample code: String _randomTag = "pvp"; String _randomTag2 = "otherName"; String _format = "{tag} {player} {" + _randomTag + "} {" + _randomTag + "} > {msg}" String _result = _format.replace("{tag}", "MODERADOR").replac...
asked by 04.01.2017 / 16:06
2
answers

How can I set the address as a street and a neighborhood corresponding to latitude and longitude?

I have this code: protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == MAPA_REQUEST_BAIRRO){ if(resultCode == RESULT_OK){ try { Place place = PlacePicker....
asked by 26.12.2016 / 19:11