Posts by Victor Stafusa • 63,338 points
1,321 posts
-
0
votes1
answer39
viewsA: Method to check three objects at a time
You’ll need to put in some Managed bean annotated with PageScoped or SessionScoped, a variable of type int (let’s call it indice) which account from which object should start the verification. The…
-
1
votes2
answers100
viewsA: Delete sectors and their descendants - PHP
Another possibility is to solve this with a trigger. This approach is harder to maintain, but dispenses with the need to have the self-relationship table (but you can choose to have it anyway).…
-
4
votes2
answers100
viewsA: Delete sectors and their descendants - PHP
One idea is to use the ON DELETE CASCADE on the foreign key (from the table to itself): CREATE TABLE IF NOT EXISTS `setores` ( `set_cod` int(10) NOT NULL AUTO_INCREMENT, `set_base` int(10) NOT NULL,…
-
25
votes2
answers31712
viewsA: What is the difference between " n" and " r n" (special characters for line breaks)?
The \n means "new line" or "line-feed", or "new line". The \r means "Carriage Return", or "car return". When the ASCII table was standardized, the \n received code 10 and \r received the code 13.…
-
-1
votes9
answers10435
viewsA: My city zip code, where can I find open, updated and reliable source?
Following the suggestion of colleague Jackson Emmerich, one idea is to use the API of the viacep.com.br. Their API can be used in these two ways, depending on the format desired for the output:…
-
3
votes2
answers378
viewsA: Library loading at runtime
This code is good, as it is versatile, simple, useful and flexible. You can make it a little better this way: public static void adicionarAoClasspath(String caminho) throws IOException {…
-
6
votes1
answer1328
viewsA: How to restrict dates in Mysql and SQL Server?
SQL Server - Check constraints SQL Server provides the check constraints. To add a check Constraint, you do the following: ALTER TABLE sua_tabela ADD CONSTRAINT CK_nome_da_sua_constraint CHECK…
-
2
votes6
answers3210
viewsA: How to remove this black border in this presentation by iframe?
This black edge occurs because the game is centered on the screen both vertically and horizontally and it maintains a fixed aspect ratio between width and height. Leftovers in width or height appear…
-
4
votes1
answer350
viewsA: Problem in C language, issue with prime numbers
Well, first I recommend you to learn how to code properly. Another point is that you exaggerate the use of blank lines. But as for the mistakes, the first is in the case 1: for(x=0; x<=5; x++){…
-
3
votes1
answer817
viewsA: Java threaded timer
I noticed your class temporizador contains all static methods and attributes, which means that the same timer is shared across all clients. However, you seem to want each customer to have their own…
-
1
votes1
answer235
viewsA: Transaction control between two different applications
Well, the most obvious suggestion would be to add a column to make an optimistic lock (see examples of this here and here, it’s also easy to find more examples on google). However, since this is a…
-
1
votes1
answer1321
viewsA: How to identify the button that was clicked?
How about using ((JButton) evento.getSource()).getText()?
-
2
votes2
answers175
viewsA: Nullpointerexception error, where is the error?
Its main problem is that in the method PreencherComboBox, you do not initialize the connection. The simplest solution would be to do this: public void PrencherComboBox(){ String sql = "Select * from…
-
2
votes1
answer827
viewsA: How to adjust the gun so it always shoots where the aim is
I haven’t touched Unity3d in a while, but I think you can do it using the function Physics.Raycast. The solution would be to make the weapon always aim for the point that lies right in front of the…
-
1
votes1
answer82
viewsA: Getresponse - Httpurlconnection
Look at your while: String inputLine = ""; while ((inputLine = in.readLine()) != null) System.out.println(inputLine); lblStatus.setText(inputLine); String respostaenvio = SomenteNumeros(lastLine);…
javaanswered Victor Stafusa 63,338 -
15
votes2
answers353
viewsA: Is that a polymorphism?
Yes, this is inclusion polymorphism (also called subtype polymorphism). Note that the OutputStream can be implemented concretely by several different classes, such as the FileOutputStream or the…
-
1
votes1
answer39
viewsA: Error in this repeat loop. It is only taking the first value of the database
The reason to go wrong is the structure of your for. Let’s take a look: for (Usuario usuario : usuariosCadastrados) { // Várias linhas de código... if (validacao == true) { return new…
-
3
votes1
answer911
viewsA: Mysql Does Not Connect by getConnection() Netbeans Java
Try adding this to your code at the very beginning of main: try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { throw new AssertionError(e); } If that solves the…
-
2
votes2
answers121
viewsA: I can’t remember some concepts about class arrays
First, leave the class name in the singular. So "Cartoes" should be exchanged for "Cartao". Second, don’t forget the modifier private or public if you are not interested in package visibility…
-
2
votes1
answer960
viewsA: How to sort an array of objects in java
Try to use the method Arrays.sort(T[], Comparator<? super T>) thus: Time[] times = ...; Arrays.sort(times, (a, b) -> { int pa = a.getPontos(); int pb = b.getPontos(); return pa == pb ?…
-
0
votes2
answers470
viewsA: Problems opening connection to JSF and JPA
Try to add the following to your persistence.xml: <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> Add that before the <properties>. Also, if that doesn’t…
-
1
votes1
answer334
viewsA: Problems with binary search tree in C
Look at this: Politico* p = NULL; p->id = 1; If p is NULL, it is obvious that p->id = 1; will give a crash. Let’s see what you try to do: In the main you try to create (incorrectly) a…
-
26
votes2
answers4666
viewsA: foo and bar - Does it have any special meaning?
The origin of the term foo is obscure. The connection with bar is usually taken as a term used by American troops in World War II, coming from the acronym FUBAR which means "Fucked Up Beyond All…
terminologyanswered Victor Stafusa 63,338 -
0
votes1
answer188
viewsA: nome.exe has stopped working. I can’t fix this
Let’s look at these two lines: no->nomeCompleto = malloc(sizeof(char)); no->nomeCompleto = "sSASs"; That is, you have allocated a character in memory for the nomeCompleto and placed 5…
-
1
votes1
answer981
viewsA: Doubt about how to fill two-dimensional array in Java
Come on. First: String[] meses = { "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" }; // Vamos dizer que fevereiro tem 29…
-
3
votes2
answers261
viewsA: Help in Java: Arrays
Your algorithm has some little problems. The first is the following: String [] lista1 = new String []; When you create the array, you must specify its length. Something like this: String[] lista1 =…
-
24
votes1
answer77173
viewsA: Is every HTTPS and HTTP connection always linked to port 443 and 80 respectively?
Not necessarily. Doors 80 and 443 are the doors pattern for HTTP and HTTPS respectively. However, in many situations, you can use other. For example, my Tomcat goes up at port 8080. When I put two…
-
14
votes1
answer609
viewsA: CSS animation does not work on Mozilla
Your problem is a Firefox bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1036761 - The problem is that Firefox cannot animate the CSS property background adequately. So let’s come up with a…
-
2
votes1
answer1191
viewsA: Dynamically Create Jlabels
Well, I managed to do what follows. By clicking the button, Abels are added to the screen. import java.swing.List; import java.awt.EventQueue; import java.util.ArrayList; import java.util.List;…
-
8
votes2
answers1002
viewsA: Bogosort - what is this?
The bogosort is an algorithm consisting of the following: O array está ordenado? Se sim, então excelente, fim do algoritmo. Se não, embaralhe ele aleatoriamente e volte para o começo. This algorithm…
-
12
votes2
answers5108
viewsA: What is the difference between Logical Implication and Logical Equivalence?
Logical implication Starting from the my answer in your other question. We have a logical implication is a clause in the following form: p → q And she means: If p is true, then q is also true. But…
-
19
votes1
answer27783
viewsA: What’s the difference between Modus Ponens and Modus Tollens?
Modus Ponens and modus Tollens are ways of solving logical implications. A logical implication is a clause in the following form: p → q And she means: If p is true, then q is also true. Modus Ponens…
-
17
votes2
answers540
viewsA: + 3 overloads - What would that be?
Why overloads have no cost of performance? Complementing the response of Maniero, the compiler or virtual machine is able to solve the overloads statically, identifying only the methods not only by…
-
5
votes2
answers138
viewsA: Is hibernate considered white box or black box?
Well, I doubt any framework purely black box exists for two simple reasons. The first is due to law of Leaky abstractions and the second is that to use the framework, you need to know at least…
-
1
votes1
answer90
viewsA: Space spent by variables
Well, if it’s a double-chained list, then you must have something like this: typedef struct NO { struct NO *prox; struct NO *anterior; int dados; } NO; And let’s assume you have that too: int…
canswered Victor Stafusa 63,338 -
1
votes1
answer39
viewsA: Treenode properties search using C++
Try to do so: void FindRecursive2(TreeNode ^treeNode) { System::Collections::IEnumerator^ myNodes = (safe_cast<System::Collections::IEnumerable^>(treeNode->Nodes))->GetEnumerator();…
-
5
votes1
answer1056
viewsA: Transfer focus from a Jtable cell right after typing time
It was really hard to do, but I did it. :D The following code is complete, compileable, testable and executable. It includes, among the necessary explanations, the complete code of all classes (even…
-
3
votes1
answer382
viewsA: Take a class that has a certain interface implemented in Generics
In Generics, you always use the keywords extends or super. It doesn’t matter if it’s a class that implements an interface or what extends another class. They are totally different concepts, they…
-
3
votes1
answer3048
viewsA: Rotate PPM image by 90 degrees in C
First, this struct that you called imagem and IMAGEM, actually it’s just a pixel. So let’s rename it: typedef struct pixel PIXEL; struct pixel { int r, g, b; }; Better yet, match the struct and the…
-
3
votes1
answer72
viewsA: Compiler accuses typing error when there is no typing error
First of all, look at this: if(raiz->nome.at(i)=='A' || (raiz->nome.at(i)='a')) In particular that: raiz->nome.at(i)='a' Note that you used = instead of ==. That must not be what you want.…
-
2
votes1
answer1715
viewsA: How to read page by page from a PDF with Pdfbox
That’s how it works? import java.io.File; import java.io.IOException; import org.apache.pdfbox.cos.COSDocument; import org.apache.pdfbox.io.RandomAccessBufferedFileInputStream; import…
javaanswered Victor Stafusa 63,338 -
2
votes3
answers18768
viewsA: Regular Expression - Numbers only, no space
Regular expressions serve to recognize characters within a string. With them you can also obtain which substring has been recognized. It turns out that 123456 is not substring of teste 12 345 6…
regexanswered Victor Stafusa 63,338 -
2
votes2
answers9251
viewsA: How to check a null position in the vector
Considering what you said in this comment: the vector is of type int - Dr.G The problem is this: The type of the array is int[]. Which means that array[i] is the type int. The problem is to compare…
-
1
votes1
answer470
viewsA: Jasper does not open outside the IDE
This is clearly some Classpath problem. Netbeans runs the JAR under the table as well. Then you’d have to see how he does. I recommend you start by trying to manually run the JAR generated by…
-
2
votes2
answers104
viewsA: How to check with binary operations?
Well, first than in Java (and also C#, Javascript, C++, Python, among others), using error codes is considered a bad practice of programming. This is why the exception mechanism was invented, so…
-
10
votes4
answers2216
viewsA: Is there a problem using Java for commercial automation application in dektop? Or is it better to do it for the web using PHP?
Well, that’s an opinionated question, but come on. First: but I started reading about Java and found many cons about this programming language What cons did you think? There are several cons in…
-
1
votes3
answers818
viewsA: Modify array elements
Well, whereas you know the dangers of SQL injection and make sure that this is not a risk for you, and that you necessarily need to generate a String large well containing all the Inserts, I would…
-
7
votes2
answers1829
viewsA: How to print a decimal number with a dot, not a comma?
Maybe this will help you: import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; import java.util.Locale; public class Teste { public static…
-
2
votes3
answers818
viewsA: Modify array elements
First, what to concatenate Strings to create SQL queries this way is very dangerous as it opens your system to a security issue known as injection of SQL. Doing this is a bad programming practice,…
-
6
votes1
answer684
viewsA: Is it recommended to use IDE for C++ programming?
When using a good IDE, you will see several errors and warnings more easily: The IDE may suggest functions and parameters, showing you the appropriate formats of these: In addition, the IDE will…