Posts by Math • 30,313 points
252 posts
-
6
votes5
answers18470
viewsA: delete repeated values java array
You can add all in one Set and then print the object: int[] ja={1,2,3,3,4,5,6,6,8,9}; Set<Integer> set = new HashSet<>(); for(int a: ja) { set.add(a); } System.out.println(set); The code…
-
9
votes8
answers5453
viewsA: Why in some if’s situations are considered bad?
Particularly, I found two interesting ways to eliminate unnecessary if’s. 1 - Polymorphism First an example using an outdated technique involving numerous if’s and difficult to maintain: public…
-
2
votes1
answer2686
views -
3
votes2
answers2753
viewsA: How to add two tables in the same Arraylist
For you to add all the elements of the return Arraylist of a single-time method in an existing Arraylist use the method addAll(). Example: import java.util.*; public class Teste { public static void…
-
1
votes4
answers6284
viewsA: How does an empty constructor work?
How the program makes this association which empty constructor means to set all attributes to default values? This is not true, the empty constructor does not mean that class attributes will be…
-
4
votes2
answers3607
viewsA: What is the difference between using GDS32.dll and fbclient.dll and using . fdb and . GDB in Firebird?
Firebird is an open source DBMS that emerged when Interbase version 6.0 was open source for the community under the IPL license, Interbase Public License. However the new versions of Interbase…
-
3
votes4
answers11775
viewsA: Dynamically set the Excel column size
Use the following command to automatically adjust the column width according to the texts that fill your lines: Columns("C:C").EntireColumn.AutoFit For example I adjusted the column size C only,…
-
4
votes1
answer967
viewsA: Count Scanner lines
You can transfer all Scanner content to an Arraylist, so you can easily have the amount of lines your Scanner has, then you can access or scroll through your Arraylist behind the data that interests…
-
2
votes1
answer591
viewsA: How to add subitens of a Listview to a Memo?
Take the list of all the items in your Listview, then take the fifth item in the list, and finally take your text. Example: Memo1.Lines.Add(LV1.Items.Item[4].Caption); //se quiser pegar o quinto…
-
4
votes2
answers445
viewsA: Pass the object as argument
this refers to esse objeto, as you are within a Customer class method you should pass only the this as an argument, because then you will be passing the current object, which is of the Client type,…
-
4
votes2
answers2098
viewsA: How to close a Jdialog after you finish running a Thread?
I haven’t seen your entire code, but if I understand your problem correctly you want a Thread to wait for another to be executed. Basically what you need is to understand the concepts of wait() and…
-
1
votes2
answers4938
viewsA: Point function in calculator (broken numbers)
When you do: import javax.swing.* It means that you will import all the classes in this package. There’s nothing wrong with that until you have class name conflicts, for example, if you want to use…
-
3
votes1
answer122
viewsA: Problem on Jcalendar-1.4 display
What happens is that when you are developing you have a preview of your screen, however when you run your program the Look and Feel is applied and some properties of the components are quite…
-
2
votes2
answers975
viewsA: Bad Operand types for Binary Operator
Compra is a class, and preco is a reference variable referencing an object of the class Compra. You can’t compare an object to a value like this: public void fazUmaCompra(Compra preco){ if (preco…
-
3
votes1
answer2624
viewsA: How to separate a PDF file line by line, in Java?
Just like the tip given by @Renan, you already have all your text in a String variable, instead of looking for the text you want in the PDF look for it in your String //aqui voce tem toda a pagina…
-
7
votes2
answers8155
viewsA: Push button by hotkey in Java
The solution you seek is the Keybinding. Keybinding is the act of overriding the operation of a keyboard key associating to it a method to be executed every time that key is pressed. To apply the…
-
7
votes2
answers464
viewsA: Portugol expecting a value of the "real" type
Your loop of repetition faça-enquanto is wrong, he’s like this: (cont< QTD) faca { leia(N1) leia(N2) leia(N3) } enquanto(cont< QTD) While he should be like this: faca { leia(N1) leia(N2)…
-
6
votes3
answers3755
viewsA: "Program scope not closed properly." in pseudocode
You have a fim para remaining, put him out programa { Var cont, somatoria: inteiro funcao inicio() { cont ← 0 para cont ← 1 Ate 100 Faca soma ← soma + cont cont ← cont + 1 fim para escreva "A…
-
19
votes3
answers4357
viewsA: Difference between Date, sql. Date and Calendar
java.util.Date - Date (Java SE7) It is a class representing date. It has some overloaded constructor versions, its not obsolete constructors are: public Date() { this(System.currentTimeMillis());…
-
5
votes2
answers11874
viewsA: How to create an infinite array?
Vectors always have to have a set size, you cannot create them with an undetermined size. To solve your problem, you can do this hand-in-hand by creating new vectors each time it reaches its limit…
-
0
votes3
answers210
viewsA: Undefined variable when updating Database
You are not using your variable value in your update, you have to change to read the variable value. It’s like this: $consulta2 = "UPDATE tb_trabalhador SET AcidenteAnexo='$AcidenteAnexo' WHERE…
-
6
votes2
answers359
viewsA: Mount screen on Android
This screen uses the class Fragments. You can combine several Fragments in just one Activity to build a graphical interface with multiple panels. What’s more, you can reuse your Fragments in…
-
29
votes1
answer13799
viewsA: What is the importance of implementing the hashcode method in Java?
The hashCode() is used for objects of the type Collection organize its elements, for example, in an academy that has the student cards separated by the first letter of the student name, those…
-
16
votes3
answers11642
viewsA: What is the definition of the term coupling?
Coupling is how much one class knows of another class. The ideal is that there is low coupling between classes because classes should be specialists for the service they have been designated. Low…
-
2
votes2
answers16347
viewsA: How to call a method when its parameter is an array?
In his method main() you make three mistakes: Uses undeclared variables: vetor and x Passes a argument of the type float for a method that has a vector of floats as a parameter (float[] is a vector…
-
22
votes2
answers6312
viewsA: Doubts about the toString() method of the Object class
According to the own documentation of the Object class, the method toString() returns a String representation of the object. Looking at the code, the implementation of the method toString() we see:…
-
4
votes3
answers2284
viewsA: Doubts binary search
if my vector is not ordered how much it would influence the speed in relation to sequential search in case I have to sort it? If you have to sort an array to then do a search for sure the process…
-
8
votes2
answers7686
viewsA: How the android:Ems attribute works (Textview)
The ems is used to define the width of the components with respect to the current source, thus its TextView will have the width needed to display the amount of characters you set using the ems. In…
-
2
votes1
answer1413
viewsA: Error - in such column
You create a class variable: public static final String NAME = "name1"; And use it in your code: public Cursor getCursor() { try { // select * from pessoas return db.query(TABLE_NAME,…
-
2
votes3
answers923
viewsA: Error ""AWT-Eventqueue-0" java.lang.Stringindexoutofboundsexception: String index out of range: 0" in Java when trying to do IF
The size of your String returned by the operation txtConteudo.getText() has such a size 0, and you try to access your first element through the command txtConteudo.getText().charAt(0), that is, you…
-
8
votes11
answers8299
viewsA: Should I write my program in English or Portuguese?
Use English (whenever possible) Portuguese is your native language, so you will have less doubts about the language to develop your projects. The moment you are developing is not the ideal time for…
-
5
votes3
answers12987
viewsA: Using a hashMap
Answering the question: I want to know how to access each element of that list in the map You must make two loops, one that goes through all the elements of your Map and another that goes through…
-
17
votes2
answers964
viewsQ: Why doesn’t polymorphism work with Generics?
When trying to compile the following code I got an error. import java.util.*; class Animal { } class Cachorro extends Animal { } public class TestePoli { public static void main(String[] args) {…
-
20
votes2
answers964
viewsA: Why doesn’t polymorphism work with Generics?
It is possible to make use of polymorphism with Generics, but not in the same way as with Arrays The reason you cannot create an object ArrayList<Cachorro> in a reference List<Animal> is…
-
5
votes4
answers1866
viewsA: How do Stringbuffer() and Stringbuilder() behave?
Just to add, you look in class StringBuilder is like this: /** * Constructs a string builder that contains the same characters * as the specified <code>CharSequence</code>. The initial…
-
156
votes7
answers20768
viewsQ: How 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…
-
5
votes4
answers3813
viewsA: How to check if one string is contained in another?
Whereas you’re wearing one ArrayList to store their Strings I would advise you to go through all the variables in your list and check if it contains the desired text. Example: List<String>…
-
5
votes2
answers241
viewsA: How to repurpose code in two similar projects
Configure your Build Path to use sources that are not within your project. Click on Link Source... and indicate the path. Do this in your two projects, so you’ll have a unique base, so every time…
-
2
votes2
answers345
viewsA: How to fix the problems reported with the Blackbox Debug plugin in Wordpress?
is_a() was retired in php 5.0 but was reintroduced in 5.3. To solve your problem do a PHP update. Reference: PHP Manual…
-
4
votes2
answers3255
viewsA: How to perform object persistence in Delphi database?
The diagrams of your BD and your class diagram will look very similar, but be careful not to make confusion when implementing them, each one works in a very different way from the other and the…
-
9
votes6
answers53653
viewsA: How to change PATH in Windows
Basically you have to access the environment variables, regardless of the Windows you are using. Right-click the Computer and choose Properties: Choose "Advanced System Settings" Will open the…
-
27
votes1
answer28962
viewsA: How to use debug in Eclipse?
First, mark a breakpoint in the code line you have the problem. In your case it is in the line 34, correct? :) To insert the breakpoint two clicks on the left side of the line number display: There…
-
4
votes2
answers5688
viewsA: Object Comparison
The result of comparing objects is done through the methods hashCode() and equals(), class Object. Therefore, to make the comparison your way you must write these methods in your class Produto.…
-
2
votes2
answers1144
viewsA: Change Arraylist nodes
When Voce does: List<Integer> listInt = new ArrayList<>(); int a = 2, b = 3, c = 4; listInt.add(a); //linha 5 listInt.add(b); //linha 6 listInt.add(c); //linha 7 On lines 5, 6 and 7 you…
-
74
votes8
answers5453
viewsQ: Why in some if’s situations are considered bad?
I read in some places that it is not recommended the exaggerated use of if, because it makes your code difficult to read and maintain, so it’s not a good practice. What would be the overuse of if in…
-
4
votes1
answer3825
viewsQ: How to color specific lines of a Jtable?
I’m developing a Java application that involves a JTable, i need to paint some red lines depending on the age and status of that line. I’m wearing a DefaultTableModel to popular my table. I don’t…
-
15
votes3
answers15299
viewsQ: Avoiding "!= null" comparison in Java
I work with Java and for countless times I have to take a test object != null on the object before accessing it to avoid Nullpointerexception However, I think this practice ends up making the code…
-
3
votes3
answers15299
viewsA: Avoiding "!= null" comparison in Java
This is a problem that developers without much experience often face: they either don’t know or don’t trust the contract they are participating in and the defensive end up exaggerating in null’s…
-
3
votes3
answers12003
viewsA: Toggle Jpanels within a single Jframe
Below your getContentPane() place an element of the type JPanel and define its type to CardLayout, as in the figure below: Your code looks something like this: private void initialize() { frmPrinc =…
-
59
votes4
answers106387
viewsQ: How to compare Strings in Java?
The operator == says that strings are different, they store the same literal value, see the example: public class TesteString { public static void main(String[] args) { String str1 = "teste"; String…