Quintin Stephenson

Ranch Hand
+ Follow
since Nov 16, 2006
Quintin likes ...
Oracle Spring Java
Cows and Likes
Cows
Total received
1
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Quintin Stephenson

Hi Linwood

If your try with resource example was


Then your resource is InputStream is will close at the end of the try block because it has the Closable and AutoCloseable interfaces.

However in your example you have not stated what "myResource" is.  Is it a class, or and instance of a class.  Does the getInputStream method return a new InputStream everytime or merely return an existing InputStream instance that resides in a the class.  If it is the latter the InputStream in the myResource class instance (of where ever it came from) will also be closed at the end of the try with resource block because they are the same instance.

hope that helps
Q
3 years ago

Akhilesh Murthy wrote:Thanks Q, this helps.

What i concluded after many iterations is JAXB doesnt support this format which i needed. I Used MOXY implementation from eclipse to pull this through. So MOXY provides annotations which can be specified on each element type  and any element within it .

Pasting the similar article what Q had posted but this is based on annotations.

https://stackoverflow.com/questions/11743306/how-to-represent-null-value-as-empty-element-with-jaxb



My pleasure, I saw that article as well.  If you can use the annotation version, it would be best, less work for you.

Cheers
Q
3 years ago

priyanshi bhardwaj wrote:I guess I should go for the first option in large projects. Thanks!! Everyone



Are you sure you want to go with point 1 on a large project?  Here are a few questions and points to think about:
1. Who is going to administer the folders where your pictures will reside?  You may need more people involved to administer you project.  If you go with the separate images folder no matter where it resides, and depending on the size of your org, the application, you could be needing a small army to support the app when it is ready to golive. (DBA's, Web server admin, file storage admin, network admin).  
2. Where are these pictures going to reside if you go with the file store option?  If they reside on the same server they could bring you server down by filling space up with the images (unnecessary risk).  If they go on another server, and that server goes down, you loose your images. Also if this is a web application, and you have the images on a different server you could have cross domain issues.  
3. Transnational issues have already been mentioned already by Rob Spoor.
4. People who should not have access to you images will now have access to them, which could offend people and affect peoples privacy (As daft it may sound the image can be seen as data, depending on the nature of you application and business could therefore be subject to data protection).

Will it really be quicker to get the image from a file store, I don't thinks so, here's why, you still have to go to the database to find out where the image is stored before you can get the image.  You could base64 the image and store it in a clob or varchar column (depending on the image size), and therefore not have to worry about the file format after it is saved.

cheers
Q

Akhilesh Murthy wrote:

Akhilesh Murthy wrote:Hi I would want to generate a XML with a single closing tag for the elements which has null value.
For Eg: Instaed of representing XML in the below format
<Account></Account>

Want to represent like this
<Account/>

Can anyone please help me understanding on how to do this using JAXB Implementation.?



Hi there

I can see why they want to do this.  If you are transferring large amounts of XML data then having <tag></tag> style tags can just add to the size of the document. Industry regulated messaging systems love to be tight on these kind of definitions.

Anyhow, if you must have a <tag/> styled null tag you need to use a different JAXBContextFactory when you initialize the JAXBContext.  The example at https://stackoverflow.com/questions/17366054/represent-null-value-as-empty-element-in-xml-jaxb should do the job for you.  

Don't forget to create a jaxb.properties file mentioned in http://blog.bdoughan.com/2012/04/binding-to-json-xml-handling-null.html.

If your project is maven based then to get the library mentioned for the JAXBContextfactory, just add  the following dependancy (alternatively you could just download the file from mavenrepository):
       <dependency>
           <groupId>org.eclipse.persistence</groupId>
           <artifactId>eclipselink</artifactId>
           <version>2.7.0</version>
       </dependency>

The example marshall's to the console so if you want to marshall your result to a to string, it can be done via a StringWriter:
e.g. ( instead of marshaller.marshal(address, System.out); have the following code)

          StringWriter sw = new StringWriter();
          jaxbMarshaller.marshal(address, sw);
          String myString = sw.toString();
          System.out.println(myString);
         // from here you can unmarshall back to a class, or do what ever else you wish to do.

I hope that helps.

Cheers
Q


3 years ago
Hi All

I've gone for a dynamic approach with regards to the shema in a similar manner at Edwin. I read the meta data in the header and create a schema object. This object contains all the information that will dictate everything with regards to data (ie. data type, length postion in of column per records etc) and will ensure data ways ends up in the correct position in the datafile. It will also be used to affect my MVC model for the displayed GUI to my users.

My analysis of the data file gave me similar questions and conclusions(by the sounds of it) to Edwin. What redesign work would I have to go through if a new column was added (e.g. in my assignment I can see a need for a phone number column to be added). By the sounds of it some people are going for similar solutions to Andrew Monkhouse's book solution using a traditional hard coded Transfer Object design pattern.

I think you should be fine as long as you can justify it and remember to document it in your choices document as this is a major part of your assignment (your thought process and why you did certain things).

Cheers
Q
Hi there

Why do you feel you are getting error chars? Read each section of the header file as stipulated.

i.e. the first line of the datafile specification states
"4 byte numeric, magic cookie value. Identifies this as a data file"
So just read the first 4 bytes and return the value as an interger. Remember integers are 32 bit (4 byte) values. I used the readInt() method. I chose to read it as an integer because the integer value of the 4 byte value will always be the same. You don't actually care what is said in these four byte just what is the value of the bytes represents. You will have stored the value somewhere (either in a class or a properties file), which can be used to compare against.

The second value they want you to get is an interger so use readInt again.

For 2 byte numeric values I use readShort.

For the actual strings I use read() that has and out paramater of byte array. I convert this to a String value directly from the byte array. and so forth.

Cheers
Q
Hi there

Make a copy of you data file. Open it with work. Each character you see in the file is 1 byte including what is percieved by the eye as white space. You will find 2 different values in the the percieved white space.

1. what is magic cookie?
From what I gather a magic cookie in the text of this assignment is just a signature to state this is the file to be using. If this signature is different that stop the database loading process. I'm read each byte individually for this one.

2. 4 byte numeric, offset to start of record zero(what does it mean?)
I have something different. My text state 4 bytes to determine the size of each record. I'm reading this as a 32 integer.

3. Schema description section...
These are not records, these are values that define the columns in you file. The first 2 bytes (16 bit number) state how long the name of the columns is (eg. 4name). The the next number of bytes as represented by the previous value is the column name. And then finally the 16 bit (2 bytes) number representing the number of bytes the actually data in the column will be. e.g. name I think is 32 bits long etc. There are no white spaces between each of these fields.

4 what is header section?
This is the section of data you will see that match the details in your
"Start of file" and "Schema description section" sections.

5.should i use DataInputStream and DataOutputStream
Your choice. I'm using RandomAccessFile. Infact I get the impression most people here are using RandomAccessFile as opposed to DataInputStream and DataOutputStream.

6. what does "null terminated if less than the maximum length for the field" mean?
You will see white space in the file e.g. if the name column is 32 bytes then from the start of the field count 32 times while moving the cursor to the right. ie. if you have a name of James in this column theire will be 27 white space place holders.

7. what is "The character encoding is 8 bit US ASCII"?)
Bet to google this one. There is easy to read and understand text at wikipedia (search for UTF-8).

hope this helps, and good luck.
Q
Hi All

I'm working on the B&S. I�ve been playing with a few ideas since receiving my assignment while I wait to attend a course book by my company run by sun which will help me with ideas.

I�m looking to made use of design patterns where ever I can. The first that comes to mind is the Transfer design pattern as mentioned in Andrew Monkhouse�s book ( he applies it to replicate the record structure for his DVD class). In his example his example he defines this class that that it is pretty rigid, it matches his data file�s current structure. In my assignment I would have something like the follow to represent the equivalent:

Public contractor{
private Boolean deleted;
private int recordNo;
private String name;
private String location;
private String specialties;
private String size;
private String rate;
private String owner;
�. Constructor goes here populating all the above values.
Public void setName(String name){this.name = name;}
Public getName(){return this.name;}
Etc�
}

Now, as a developer I have found over a number of years working, especially on green field projects, the user community keeps changing their mind on what they want (even after they've signed off the specifications). The supplied data file only 6 has columns. So what if they decide they want to add the phone number or remove the size column. With the above structure you would have to modify this class to add/remove getter and setter methods, visit the classes and methods that require the new method or remove the deprecated method including in the GUI swing components when using the MVC design pattern.

Can anybody explain why it is not a good idea to use a transfer data factory type object that uses generics and a map collection?
public class transferObject<key,val> {
Map<key,val> transferMap;
transferObject (Map<key,val> transferMap)
{
this.transferMap = transferMap;
}

The way I see it I can then take advantage by my front end never having to know what is basing its view on, it will be told at runtime what model to use. I am developing both models to see the difference as I go along to compare issues, but at the moment my generic method is seemingly a far better solution.

Any views and assistance welcome.
Cheers
Q
Hi All

I've seen many forums threads on this site dancing around the topic of modifying or extending the DBMain interface with which I have an issue with, but none actually gave the type of answers I've been looking for, so I emailed who2contact@sun.com with my question as specified in the assignment. This is what I got back.

My Email containing the issue:
The assignment states 'Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface'. Part of the interface declares a method as follows:

// Reads a record from the file. Returns an array where each
// element is a record value.
public String [] read(int recNo) throws RecordNotFoundException;

The instructions states 'Your project must conform to this specification. Features that deviate from specification will not receive full credit', and 'Automatic failures ... where this document uses the word "must" an absolute requirement is being described. If you fail to adhere to such a requirement, your assignment will be failed automatically'.

It also states 'Provided you do not contravene any specification in this document you will not be marked on the particular choice that you made...'

Even though it states that the supplied interface must be implemented by the Data.java class, it does not state that I am not permitted to modify the interface.

My question is would I be contravening the specification or be penalised in any manner if I modified the interface method previously mentioned method at follows where myRecord is a serialisable class that contains fields previously returned as an array:

public myRecord read(int recNo) throws RecordNotFoundException;

My reason for the modification would be that the method is public and in order to simpily the OO design making it easy for junior developers to understand (part of the clarity and maintainability requirements) I want to apply the Tranfer Object pattern to this area. In fact I want to apply as many design patterns as required through out the application to enable it to conform to globally recognised standards and therefore easier for any java develop to understand.

This is their responce:
Thank you for contacting Sun Certification Customer Support.

There are ambiguities to the exam in order to allow you latitude in how you solve the problem. You are being tested not only on your knowledge of Java technology, but also on your problem solving ability. If you are uncertain of how to do something, document your thought process heavily in that section. The main idea is to ensure the project works according to specification and to document the choices you have made.

Since the assignment instructions do not specifically forbid you from modifying the interface, you should not be penalized�providing that the modification still allows the project to work as specified.

Sincerely,

Eric Boice
Sun Certification Customer Support
who2contact@sun.com

So it seems as long as you comply with the following we should not have a problem:
1. don't modify the format of the data file,
2. can insert, update, delete and read the records,
3. have a class called Data that implements an interface called DBMain (heavily document reason why the modifications have been made)
4. make use of techniques to handle database concurrency issues such as locking and making use of threading.
5. use one of the specified networking frameworks (I'm going for RMI), as well as the non-networking solution,
6. have a swing GUI component used by the user that uses a jtable to display the records that match you search, and performs all of the previously mentioned connectivity to execute all all of the stipulated database DML(Data manipulation Language) methods.

Any input and point of views are welcome from anybody out there (especially persons that have successfully completed the SCJD and the moderators) on this topic.

Cheers
Q
Hi All

I've just signed up for my SCJD assignment today, so I don't know what the limitations are yet as I'm waiting for the emails to come through, so please excuse my ingorance.

Instead of using synchronize, why not use the lock interface. According to sun it provides a "more extensive locking operations than can be obtained using synchronized methods and statements. They allow more flexible structuring"

Cheers
Q
Hello

In your example it will return true if and only if obj is an instance of C.

Lets examine the statement: (obj instanceof C && !(obj instanceof D) )

There are 2 parts to the statement joined by an "AND"(&&) statement. So both parts of the statement must return true in order for overall statement to be true.
1. The first part (obj instanceof C) checks if obj is an instance of C. This will return true if obj is an instance of C or D.
2. The second part (!(obj instanceof D)) says check that the obj is not be an instance of D (the not statement is denoted by the !).

If you write a dummy exercise you will see what I mean. e.g
public static void main(String args[])
{
a obj = new d();

if (obj instanceof c && !(obj instanceof d) )
{
System.out.println("C");
}
else
{
System.out.println("not C");
}

}

Cheers
Q
hello there

If you're looking to interact with Ms programs such as Word, Excel etc or any program for that matter that makes use of com objects look no further that JACOB (stands for Java Com Bridge). You will be able to find out details about Jacob and the required downloads at http://sourceforge.net/projects/jacob-project/. It is free open source, so it won't cost you a cent. If you're concerned about the source and stability of Jacob, Oracle make extensive use of Jacob for their Oracle forms product in a library called webutil.

If world can trap the event you require, then this will help you greatly.

Cheers
Q
[ July 11, 2007: Message edited by: Quintin Stephenson ]
13 years ago
Hi Tashi

Read the following forum:
https://coderanch.com/t/262155/java-programmer-SCJP/certification/equals


It deals with the same set of topics (shallow vs. deep comparisons and autoboxing)

Cheers
Q