I have an object that may contain several other objects (sub-object) and will compress those sub-objects.
My question is generally what is a good way to compare two objects, as described above, if they are equal (e.g. through equals() function)?
Intuitively there are two ways I can think of: 1. Compare each compressed bit
The disadvantage I think is it's not efficient if the object is very big. For instance, when it holds several gigabytes data, it may took too long for just comparing each bit.
2. Hash the sub-object before compressing it, and then compare all hashed values. This problem is I am not very sure if hashing is a good way to compare objects. And if collision may be the problem?
I have a JScrollPane with two coulmns. In the first column I have an image pane JTable, and in the second a list with names of sections. This second column I try to divide in two columns, one (the second column) to display the names of the sections (each row contains one name), and in the other column (the third) I want to show some values for every section in the row respectively. But, instead of displaying the desired values in the third column, I get the same names of the sections as in the second column. Here is a part of the code I have:
private Vector<Section>daten = new Vector<Section>(0); //These are the values for the first column in the Jscroll private String[] header = {"Section","calcGYR"}; // These are the values for the second and third column (in this case the header for the both columns public TrafficObserveModel(Vector<Section> daten) { setData(daten);
[code]....
But I don't know how to modify the methods in order to render the desired integer values in the third column.
I have an assignment that wants me to write a Java function based on induction to determine how many numbers in an array have a value greater than, or equal to, 100.
I have started with:
Java Code:
int recurseHundred (int [] A, int n) { //n is the number of elements in the array. //Base case: if (n == 1 && n >= 100) return A[0]; //Recurse int num = recurseHundred(A, n-1); if (n-1 >= 100) return A[n-1]; else return num; } mh_sh_highlight_all('java');
I read this tutorial about overriding equal and hashcode method. [URL] ....
I understand how to override equal method, by overriding it, We can custom our compare. I also understand How to override hashcode, To make custom hash.
But still I can not understand why we do it? why if equal method override, we must override hashcode method too?If we don't what is the problem?
To honor the above contract we should always override hashCode() method whenever we override equals() method. If not, what will happen? If we use hashtables in our application, it will not behave as expected. As the hashCode is used in determining the equality of values stored, it will not return the right corresponding value for a key.
Is it the right reason in order to override:
Because when we customize equal method so it focus on special variables,We must change the hash code too in order to match with it, so hashcode also focus on those special variable.
I am working on an assignment covering exception handling and am stuck on part of the assignment. How can you test for array length = 0?
When I try something like: if (array.length == 0) on a null array, naturally I get a NullPointerException. I would try something like if (array != null) but both array length of 0 and null array are supposed to throw different expressions.
i know that int [][] x = new int[2][2] will generate a 2x2 array but I'm looking at a certification mock question and I see double [][] da = new double [3][]. What is the empty [] on the right hand side of the equal sign trying to tell me? Is there some default value?
I'm suppose to create a program that will check if one statement is equal to another but it doesnt display the message if its equal to the inputted String
import java.util.Scanner;
public class sup { public static void main (String args[]) { Scanner in = new Scanner (System.in); String one;
[code]...
thats just an example I was able to do it in C++ but it doesnt do what I want in Java
I would like to create a program that takes some files and modifies them in this way: The files should contain text formatted in this way:
############## #various comments# ############## something{ identifier=1234 anotherIdentifier=1235 anotherOne=12345 //and so on... }//I need only this
#Comments are sometimes made this way
somethingAgain{ #comments that explains what's below them I:dentifier:something, I, do, not, need #see ^that A:notherIdentifier:boolean //and so on.. }
And I have to make so that the numbers contained in something{} in all the files don't match. I could ask to make so that the input file is only one, and it is formatted this way:
identifier=1234 anotherIdentifier=1235 anotherOne=12345 //and so on...
but I don't know how to do the rest of the program... That's what I've done (the names of the classes, package etc. are in Italian and there's some useless code that NetBeans prevents me from deleting):
package confronto; import java.awt.Color; import java.io.*; import javax.swing.*; public class confrontoTesti extends javax.swing.JFrame {
I need comparing two array lists. For this program i am comparing 2 array lists. The list is integers entered by the user the second is random generated numbers. So far in my program i am able to compare the 2 arrays together and output if they are equal or not however i need the program to output even if atleast one if the integers match,
EXAMPLE list one: 1, 2 ,3 ,4, 5. LIST TWO: 1, 3, 3, 3, 3.
Since the first number matches i want it to out put there is one match, so on and so forth with if there are 3 or 4 matching integers. here is my code so far.
public static void main(String[] args) { final int NbrsEntered = 5; //Number of guessed numbers entered final int LOTTOnbr = 5; int[] numbers = new int[NbrsEntered]; int[] randomNum = new int[LOTTOnbr]; //int[] TestArrayOne = { 1, 2, 3, 4, 5 }; //int[] TestArrayTwo = { 1, 2, 3, 3, 5 }; boolean arraysEqual = true; int index = 0;
Write java program using table that stores celsius and farenheit values that are equal to one another using a loop. use C 0-20 and convert to farenheit.
I have to use doubles for Celsius and Fahrenheit and in the formula. I get a runtime error with the following displayed:
I will display a table of temperatures in their Celsius and Farenheit equivalents.
celsiusfarenheit
import java.util.*; import java.lang.*; import java.io.*; class TemperatureConversion { public static void main (String[] args) throws java.lang.Exception { double celsius;// Temperature in degrees Celsius minimum double farenheit;// Temperature in degrees Fahrenheit
public static void main(String[]args) { Scanner input = new Scanner(System.in); System.out.print("Type your text: "); String text = input.nextLine(); int counter = text.length(); if(text.length()> 16)
[Code] ....
And input is: abcdefghijklm
output is:
Java Code:
a b c d e f g h i j k l m x x x mh_sh_highlight_all('java');
So all i want is, if i type: abcdefghijklm
I want this output:
Java Code:
a e i m b f j x c g k x d h l x mh_sh_highlight_all('java');
when we create another variable and set it equal to the first : Car c2 = c1;
we're pointing c2 at the same car object that c1 points to (as opposed to pointing c2 at c1, which in turn points at the car). So if we have code like,
Car c1 = new Car(); Car[] cA = {c1, c1, c1, c1};
are we doing the same? Are we creating four *new* reference variables, each of which points at the same car (again as opposed to pointing them at c1 itself)? I think so, but want to make sure I'm understanding this correctly.
I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?
I'am trying to converting string data into xml data using xml beans and StringEscapeUtils.This is work fine but in one case it if the data contains special characters.
Code snippet -------------------- import org.apache.commons.lang3.StringEscapeUtils; import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; public class ParseXMLData { public static XmlObject parseXML(String stringXML) { XmlObject xmlObject = null;
[Code] ....
success case --------------------------- i/p------<aaa><bbb>This converts string to xml</bbb></aaa> o/p---<aaa><bbb>This converts string to xml</bbb></aaa>
Failer case ----------------- i/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa> expected o/p----<aaa><bbb>This fails if it contains < symbols</bbb></aaa>
Observed that it converts < to '<' but as per xml rules, if data contains '< ' it fails. I want to convert staring and end tags to xml format and if data in b/w middle of starting and ending tags do'n need to convert it. How to do it.
Is there a way to inform the Entity Manager or force the JPA provider to reload data from the database? The scenario could be data being updated by a store procedure or direct SQLPlus maintenance, without restarting the Application Server, the JPA need to load the newly updated data from the database.
I think the current JPA API is not enough. The void refresh(java.lang.Object entity) from EntityManager need to pass in the Entity object, I will like to know how to refresh the entire JPA Entity data after the physical table data being update from backend.
By using FileReader, FileWriter and their constituents, I am creating a file to contain employee information ( name, age, hours, etc. ). The user is to input all of the data on a single line and we were asked to implement StringTokenizer to assign that data to the file. I have never used the StringTokenizer before, but I have a rough idea how it is to function. I used pw.println to test what I have so far, now I would like to let the user build the initial file with the "first employees" of the company, and then view the file, and then go back and append new employee data to that same file. My question is, how can I take the user input as a StringTokenizer and add that to the file?
In the for loop below, I thought I would see if it would work, but it does not. The loop only executes once and does not allow me to enter data.
public class Records { public static void main(String [] args) throws IOException { Scanner input = new Scanner(System.in); FileWriter fw = new FileWriter("dbs3.java"); BufferedWriter bw = new BufferedWriter(fw); PrintWriter pw = new PrintWriter(bw); System.out.println("NEW EMPLOYEE DATA SHEET"); System.out.print("Number of new employees: "); int number = input.nextInt();
I am able to upload the file to the server, but I am not able to get the value of text1 in the servlet (I am getting null value of text1 in the servlet), I need this textfield in the form to submit some additional information while uploading it to the server.
--> Is enctype="multipart/form-data" option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additional textfield to the server.
I have written several simple data classes that I serialized manually by converting to text. At this point I need to serialize a more complex data structure. which will include lists of the simpler elements. Can serialize store and reconstitute this type of structure automatically or do I need to do this one manually as well? Consider the pseudocode below for a clarification of my question;
Class Recipie{ String Name; CList HopList; CList MaltList; };
CList RecipieList; mh_sh_highlight_all('java');
I read the article on Serialization presented at tutorial point, but the example only showed a simple class, not lists of class members. What I want to do is serialize RecipieList, which consists of a CList of Recipies, which in turn consist of CLists of various ingredients.
I have a program which consist of several classes. The program reads a pom file and parses the data and then writes the data to a static table. The issue I'm having is with writing my LIB file data to my table. In the HtmlDataTable Class Im trying to write the files that are read in the lib directory to the table. My table currently consist of 3 columns (missing jar files,Lib Directory files, and POM file data) currently Im only able to write the missing jar files data to my table. In the HtmlDataTable class there is a for statement where I write the missing jar file data to my table. Im also trying to write the contents of the Lib directory within this statement as well. This is where I'm having my issue. My other classes consist of a SAX parser which parses the xml file, a class that creates my static table and a class that compares the jar files in my lib directory to the jar files in my pom file. . Theres a lot of code so I included the parts I felt were useful. If needed I can include the other classes as well.
public class ReadPomFile extends DefaultHandler { public static void main(String[] args) { try { // obtain a SAX based parser to parse XML document
I am creating a program where it reads the data inside a file and then places this data into arrays. The file I created has numbers 1-30 in it, file named, testing1.txt .