Questions tagged as 'java'

1
answer

What is the difference between printf and print?

I was doing some simple algorithms in Java and most of the time using System.out.println() or System.out.print() , but to do the definition of the number of decimal places I'm using System.out.printf() . I know there is a diff...
asked by 16.01.2015 / 00:28
3
answers

Operator Precedence

I have a question regarding the precedence of operators in JAVA. I have the following code: int x = 2; long y = 1 + x * 4 - ++x; Viewing the precedence table here . In my view the expression should be resolved as follows: 1 + x * 4 -...
asked by 16.11.2015 / 23:47
1
answer

How to create directory with a path that works for any OS?

I'm doing a job in Java and I need my program to create a directory in the user's home folder, but it needs to be able to create both Linux and Windows. Is it possible to create a "generic" path for this?     
asked by 02.12.2014 / 23:58
2
answers

Inner Class in Java, when to use?

Sometimes I find class codes with inner class , such as: class ClasseExterna { private int a = 10; // ... class InnerClass { public void accessOuter() { System.out.println("Outra classe " + a); }...
asked by 22.04.2015 / 21:02
3
answers

Is there any way to generalize library imports into Java?

I created within a same package called Banco , two classes in Java: ContaSalario and ContaPoupanca . When I'm going to import these two classes into my main class, I do: import Banco.ContaSalario; import Banco.ContaPoupa...
asked by 22.09.2015 / 19:00
2
answers

What is syntax sugar and how does it work?

I have seen in some blogs the use of this term and would like to know: 1) The real meaning of this expression e; 2) How does a syntax work like the example below in java ? for (Foo foo : listFoo) { //CÓDIGO AQUI }     
asked by 15.04.2014 / 03:01
2
answers

What is the function of super in a Java constructor?

I have a child class that inherits from another abstract class, and the one in the class constructor has the following: Public aluno(String nome, int idade){ super(nome,idade); } What is the "super" function in the class constructor?  ...
asked by 24.12.2014 / 12:34
2
answers

What is and how to implement a Listener in Java?

Although you have already asked the Differences between listeners and adapters in the swing and also Listeners are an implementation of Observer? , I would like a more detailed explanation. What are listeners in java? How to implement one?...
asked by 10.09.2017 / 22:01
2
answers

How to get the last working day of the month?

Is there a reliable holiday library in Brazil that we can integrate and get on the last business day of any month? Anyway, if there is no such library, how could I get the last weekday of any month? (Formatted in a Calendar or a Date.) Sam...
asked by 30.04.2014 / 15:27
1
answer

Is it correct to throw the same exception for two different reasons?

I'm practicing TDD simulating a central alarm. Alarm centrals work connected to sensors that detect intrusion (opening a door or window, or moving inside a room, for example). They have a fixed number of logical partitions (representing differen...
asked by 03.07.2016 / 00:44