Simple Data Classes - Serialize More Complex Data Structure

Oct 6, 2014

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;

Java Code:

Class Hops{
String Name;
float Alpha Acid;
float Beta Acid;
};

Class Malt{
String Name;
float extract;
};

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.

View Replies


ADVERTISEMENT

Defining Map Data Structure

May 27, 2014

I want to define this data structure , I show you an example

"first street",{{1,40},{43,45},{34,26}},
"second street",{{14,41},{42,5},{3,46}},
............

I wrote in this way but it doesnt work :

Map<String,ArrayList<int[]>> Street=new HashMap<String, ArrayList<int[2]>>();

View Replies View Related

Data Structure Construction

Feb 27, 2014

I'm trying to fill a List<String>, named overlappedGrid, from another List<String>, named listGrid. I'm facing an exception:Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - unexpected type

required: variable
found: value
at arab2004_d.ProcessingLayer.printShape(Arab2004_D.j ava:101)
at arab2004_d.Arab2004_D.main(Arab2004_D.java:30)

Java Result: 1

Here is my source code (the exception line is commented "here is the exception"):

package arab2004_d;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;

[code]....

I tried to copy listGrid in another List<String> but the exception remain the same.

View Replies View Related

Trie Data Structure In Java

Sep 27, 2014

Problem in inserting,removing and searching in trie data structure.

View Replies View Related

Checking Parentheses Using Stack Data Structure

May 4, 2015

I am trying to Implement a method matchBracket(String exp), which should take a String expression consisting of only symbols (,[,{,<,),],},> , and checks if the brackets in the expression are matching using stack data structure.

I know how the methods of stack class like push,pop,peek are for however how to do the checking for opening and closing brackets iteratively ?

public static void matchBracket(String str){
// creating a stack of character at first
Stack <Character> stack = new Stack<Character>() ;
// starting loop to scan the expression below inside main method
for(int i = 0; i<str.length(); i++){

[Code] ....

/**Expected Output:
*The parentheses are not matching
*The parentheses are matching

View Replies View Related

Java Calculator Using Stack Data Structure

May 21, 2014

My assignment is to design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. But i having error while i press the action there.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.Stack;
public class JCalculator implements ActionListener {

[Code] ...

View Replies View Related

Display Data Structure With JTree In A Swing Application

Aug 28, 2014

I have a tree-based data structure that looks somewhat like this:image1.png..Every tree always has a height of no more then 3, and each of these classes has a very specific use, generalization is not possible between them.Now, I want to display my data structure with a JTree in a Swing application. A JTree needs a TreeModel and so I created a custom TreeModel for my classes, it looks like this:

public class CustomTreeModel implements TreeModel {
private Root root;
public Object getRoot() {
return root;

[code]....

But then I would introduce this interface to my Model classes just for the purpose of writing the View. So my data model has to be altered to make the View work, this sounds completely against MVC to me and also like something I dont really like.On the other hand, the CustomTreeModel would be much simpler, easier to understand, easier to maintain and just in general more pleasing to the eye.Should I change my Model to improve the View? Is instanceof okay to be used in View classes?

View Replies View Related

Peterson Lock Implemented For N Threads Using Binary Tree Data Structure

Feb 8, 2014

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
public class tree_lock_test{
int total_instances;
int thread_instances = 0;
int N;

[Code] .....

this is compiled with another Peterson class which has implemeted peterson lock for two threads ...

View Replies View Related

Design Calculator Using Stack Data Structure To Perform Additions / Subtractions / Multiplications And Divisions

Jul 18, 2014

I've beginning a new assignment and would like some feedback on my outline for the program. You are to design a simple calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. The user may enter an arithmetic expression in infix using numbers, parentheses and arithmetic operations (+, -, *, /). After an expression is entered, its postfix or prefix notation is displayed and then the result of the expression. You are required to design your own infix to postfix and infix to prefix conversions.

The professors example includes: SinglyLinkedList implementation, a Stack that implements Stack interface and extends SinglyLinkedList, a Node class, and StackApp -- in addition to the main class and the prefix/post-fix classes.

(The equation is entered/stored as a string variable)
System.out.println("Enter equation: ");
equation = input.next();
equation.trim();

(1.) Get the user input:
- evaluate the user input and use a stack to determine the correct prefix/post-fix notation.
- from the stack, pop each item:
a. account for '(' and ')' to push all operators and write all operands until ')', then pop/write
b. store new equation into a list (in prefix/postfix notation)

(2.) Display the list in both notations to the user.

(3.) Perform the calculation.Do you think it will be alright to calculate the original equation that was entered? It seems too much to then design a class that will then cycle through the polish notation and calculate according to that format.

View Replies View Related

Complex Math Functions With A Simple Web Page?

Feb 4, 2015

I am a 3rd year electrical engineer and I am working on a project on solar cell design in the developing world.For my project I am looking to create a very simple web page which can be used by people in the developing world to determine whether a photo voltaic system is suitable to their needs.

For this I want to have simple boxes where a user can input numbers and I used complex calculations to return values (a lot of trigonometric functions etc.), the values then should have the opportunity to be altered to the users digression. This will create a solar model.

For the load aspect of it I am looking to have drop down boxes for a number of components which the user can select and will have a numerical value in Watts which will sum to give total load on system. Ideally I would like to show this graphically in a pie chart showing how much energy each component is taking to give the option to remove.

I am also creating a statistical model which determines the likelihood of having no sunlight on a given day which looks at the solar output, battery capacity and load on the system and will return reliability of the system - this has not been completed but should be shortly.

Aim is to keep web page as simple as possible as unskilled computer users may want to use it.

View Replies View Related

ArrayList Of Interface - Does It Rip Away Data From Child Classes?

Nov 29, 2014

If I lets say have an interface Animal, and I create a lot of classes with a different animal name that implement the interface Animal. Then I create an ArrayList of Animal. Then I would put in lets say Dog class into the ArrayList, which has custom methods and data that the Animal Interface doesn't have, is this data ripped away except for the methods that are put in the Animal interface? So if I would cast the Animal back to Dog, would it retain all the data that existed before it was placed in the ArrayList?

View Replies View Related

Understanding Classes And Objects In Terms Of Data Types

May 8, 2015

I have seen many ways of describing what objects are, one being that objects are a user-defined datatype. However, if objects are datatypes, then what does that make classes? To me, it seems as though classes should be the "types" of data defined by the programmer, and objects should be the specific "values" of that user defined data type. As an example, an integer would be a class, while 1 would be a "value" of that class, i.e. an object. From this point of view, I don't see why a specific number would be a data type... Therefore, why do we say that objects are user defined data types rather than classes?

View Replies View Related

How To Structure Simple Java Programs

May 8, 2015

how to structure simple programs (i.e. one-method algorithms for a simple purpose). There are a few different ways that I have been doing it, but I want to be consistent. Should I put both the one-method algorithm (e.g. a factorial function) and the main method that executes the algorithm into the same class and then export it to an executable .jar file for use? Or should I create one class for the algorithm and another for the main method that executes the algorithm? In addition, is there any reason that I should out these classes in a package before I export it?

As another similar question, if I have constructed two distinct classes with two separate purposes, and they are both used in the construction of a single program, then would it be best to just put the main method in a third, separate class or should I put it in one of the two classes?

View Replies View Related

Creating New Data Type VeryLargeInteger With / Without Premade Java Classes

Jan 22, 2014

What I'm doing about it: googling the shit out of my problems, consulting you fine readers, consulting my friends, and yesterday I signed up for Lynda.com. I'm hoping 30hrs+ or so of watching, rewatching, and analyzing the example code will catch me up before I get too behind in CS302

** Assignment Prompt **

Integer types are very convenient, but their limited width and precision makes them unsuitable for some applications where precision is more important than speed. Develop a class VeryLargeInteger that can handle arbitrary long integer numbers (both negative and positive) and the basic arith- metic operations (addition, subtraction, multiplication, division, and remainder).

Hint: The number could be represented as string, the sign could be represented either as boolean or as part of the string.

Note: Implementations of addition/subtraction through repeated use of a constant incremen- t/decrement will not be accepted. Implementations of multiplication and division that rely only on addition and subtraction will not be accepted.

I know I'm going to have to create a separate tester to call on the VeryLargeInteger class and it's math methods. For the new data type, should I convert the integer/string into an array in order to handle the large length of the number? I know he wants us to use recursion for the math methods. My gut tells me addition and subtraction will be slightly easier than multiplication and division. I know I'll have to reference the other methods for division. We aren't allowed to use the BigInteger class.

How I should construct any of the methods.

Java Code:

import java.util.ArrayList;
/**
∗ VeryLargeInteger (VLI) is a class for arbitrary precision integer computation
*/
public class VeryLargeInteger {
private int[] num1;
private int[] num2;
private int[] num3;

[code]....

View Replies View Related

ASCII Animation Program - Accessing Data Members From Different Classes

Nov 12, 2014

I have a problem with this ascii animation program I am working on. I declared a method inside of my class AsciiAnimation extends JFrame implements ActionListener, called

package AsciiAnimation;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
 import javax.swing.*;
 public class AsciiAnimation extends JFrame implements ActionListener{
int currentFrame = 0;
ArrayList<String> frameList = new ArrayList<String>();

[Code] ....

Basically I just am trying to figure out how java works with me accessing those 2 data members, currentFrame and frameList inside of my first class ALL in the same package.

View Replies View Related

Servlets :: How Does Multipart / Form-data Send Data Over Network During File Upload

Apr 9, 2015

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 ?

View Replies View Related

How To Get Data Button To Display User Inputted (numbers) To Data Label

May 25, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayFinal_Panel extends JPanel {
private JLabel label1, label2, label3;
private JTextField box;

[code]....

I only want Listener 1 to work right now. Also, user input is in TextField.

View Replies View Related

How To Escape unwanted Special Characters In String Data While Converting Into XML Data

Mar 7, 2014

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.

View Replies View Related

Enterprise JavaBeans :: How To Refresh JPA Data When Table Data Is Updated From Backend

Nov 27, 2012

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.

View Replies View Related

User Input All Of Data On A Single Line And Implement StringTokenizer To Assign That Data To File

Mar 21, 2015

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();

[Code] ....

View Replies View Related

Servlets :: Multipart Form Data - Sending Additional Data?

Feb 21, 2014

I am using apache-commons-fileupload to get file from client to the server.(using JSP and Servlet).

JSP/HTML

<form method="POST" action="GetFile" enctype="multipart/form-data">
<input type="file" name="datafile">
<input type="text" name="text1">
<input type="submit" value="Next">
</form>

Servlet: GetFile

System.out.println(request.getParameter("text1"));

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.

--> Or is there any other problem in my code?

View Replies View Related

Writing Data To A Static Table - Can't Populate All Fields With Data

Jun 24, 2015

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

[Code].....

View Replies View Related

Reading Data From A File And Putting That Data In Arrays

Feb 8, 2015

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 .

Java Code:

public static void main(String[] args) {
// TODO Auto-generated method stub
// Variables Declaration Section
//******************************
BufferedReader br;
String sCurrentLine;
String str;

[Code] ....

My issue is that the 'str' value is not initialized, but if I initialize it, it ruins the code. I'm not sure what to do in the situation.

View Replies View Related

Simple Averaging Program Using Two Different Classes?

Apr 9, 2014

This is a simple project that i was using to test my current java knowledge (kinda like revision) and for that i used two classes to make a simple averaging program. i know i0m making it more difficult but like i said i'm testing myself but i come up with an unexpected error. Here's the code:

- 1st Class

import java.util.Scanner;
public class Main {
public static int num;
public static int total = 0;
public static int average;

[Code].....

Now the problem is after inputing the numbers it doesn't give me the average but the value of 0.

View Replies View Related

Serialize Array And Deserialize

Feb 10, 2014

I am trying to serialize an array and deserialize, I believe the serialization is working but I have been able to read the file.I am getting this

run:
Before serialization
arrays_serialize2.Account@9931f5
arrays_serialize2.Account@19ee1ac
arrays_serialize2.Account@9931f5
arrays_serialize2.Account@19ee1ac
After serialization
null
BUILD SUCCESSFUL (total time: 0 seconds)

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Serialize Java Components

Mar 9, 2015

I am trying to send a JPanel object to the server. While doing so I get the error -

java.io.NotSerializableException: javax.swing.filechooser.WindowsFileSystemView
at java.io.ObjectOutputStream.writeObject0(Unknown Source)
at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)

[code]....

How to fix this error?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved