This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services forum!

Parag Shah

Greenhorn
+ Follow
since Jan 23, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
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 Parag Shah

Java Lists allow duplicates, wheres a Set does not allow duplicates. If you want ordering, you can use a TreeSet which is an ordered set.
8 years ago

Cody Wade wrote:I think it's starting to sink in.

So rather than creating a menubar.java file, I want a window.java file that includes the frame, textarea and menubar (and actions).

Then a (in Parag's example) a book class in a book.java file, that includes methods for reading the file and parsing it.

So I create an object that is the frame (the view), and from there I can call/create a book object.

book.load can read the file and parse it into memory

then frame.print could take that book object and get the information from it (either from the internal variables directly, or from a getter method inside the Book object) and print that into the text area.



A few thoughts :

In an OO system, think in terms of responsibilities and objects. Objects have responsibilities, and they fulfill their responsibilities through their methods. When another object wants to get some work done, it calls a method of an object. The software works by these objects collaborating with each other.

The Window object (whose blueprint/design is in Window.java) is responsible for displaying the main view of your software. To display the view, it needs a JFrame, a JMenuBar, and other visual components which you want to include. Before moving on to the next point, I would like to mention that naming a class WIndow, may not be a good idea because it is a very generic name. You can perhaps call it MainView.

Book.java is what could be called a POJO (Plain Old Java Object). It simply holds values, and has getters/setters. It's responsibility is to simply be a container for attributes that make a book.

The class responsible for parsing could be called BookParser. This class is responsible for parsing an InputStream and creating a book object from the InputStream.

You create the MainView object (which could either inherit from JFrame or could be composed if it), which provides the display. In the display there should be a way for a user to select a file. When the file is selected, and ActionListener will be invoked. This action listener instantiates BookParser, which returns a Book object. The ActionListener takes the book object and displays it in a view.


--
Regards
Parag
http://diycomputerscience.com
8 years ago
Think of objects as those things that are running in your system. They are very much like real objects in the real world (car, window, room, etc). The classes are blueprints for those objects. Think of them like an engineers design of a car, an architects design of a room, etc. The files are simply a way to organize the classes (and not objects). Think of them as folders or drawers in which the architect keeps paper designs.

Let's think about your problem in OO terms:

You want a parser that can parse the file and create an object which represents the contents of the file. I don't know what is in the file, but let's say it contained the details of a book (title, author, ISBN, etc), then the parser would create a Book object from that file. This object needs to be displayed, so you need a BookView object. The BookView object would contain all the visual artifacts you need. Since we are using OO, these artifacts would also be objects, and objects would be composed of other objects. A theoretical example would be like a room being composed of windows, doors, etc. A practical example would be a BookView objects being composed of JFrame, JMenu, JTextArea, etc.

How would all these objects be created by the system? It needs a blueprint. Just like we need a floor plan and elevation before we can build a house. These blueprints are your classes. Again the files are simply a way of organizing those classes so that your software is understandable and maintainable. Typically we use one file per class WE create (there are exceptions to this rule, but I will not get into that right now).

You do not need a file for menubar. You need a file for your view class, which will be composed of a JMenuBar, etc. You also need a file for your Parser and a file for a class which will start your software (this is a good practice).

--
Regards
Parag Shah
http://diycomputerscience.com

8 years ago
Hello,

I have been reading some tutorials on JSF. This is my initial understanding.

In JSF, the view is created from JSF tags which are placed in JSP pages. I understand they can be put in Facelets or in .jspx (xml compliant jsp page) pages as well. When put in .jspx we do not define tags, but namespaces.

Usually the point of entry into a JSF application is a JSP page that forwards to another page that is actually processed by the FacesServlet and rendered on the browser.

Is it true that the real purpose of the JSP page is to allow Faces Servlet to build a View Root for that page on the server side. Once the View Root is created it (and not the JSP page) renders the html to the browser. When a user submits a form or clicks on a button, the Faces Servlet updates the View Root for that component, which further renders the resulting view on the browser.

Is my understanding of how the view is rendered in a JSF application correct?

Thanks
Parag
12 years ago
JSF
Thanks a lot Jesper... that does solve the problem.

Regards
Parag
http://www.adaptivelearningonline.net
13 years ago
import java.math.BigInteger;

public class MathsExp {

public static void main(String[] args) {
byte b1 = (new BigInteger("2")).pow(8).intValue() - 1;
System.out.println("b1 " + b1);
System.out.println("Masked b1 with 0xFF " + (b1 & 0xFF));
System.out.println("Masked b1 with 0xFFFF " + (b1 & 0xFFFF));
}
}

Output:
b1 -1
Masked b1 with 0xFF 255
Masked b1 with 0xFFFF 65535


The first line of the output is expected: Since a byte is always signed 2^16 - 1 is taken as a negative number.

The second line is also understandable: since 0xFF is a short, the byte is propmoted to a short, hence ignoring the earlier sign bit. Performing an AND with 0xFF returns a short value of 255.

However I cannot understand why masking a byte with 0xFFFF returns 65535. The byte will be promoted to an int value and then AND will be performed with 0xFFFF. I would think this should return 255 as an int.

Am I missing something here?

Thanks
Parag
[ November 20, 2006: Message edited by: Parag Shah ]
13 years ago
Hello, I have recently created a website to help developers improve their programming and design skills.

I am trying to use the paradigm of "conversations that lead to learning". Hence all learning material os provided in the form of blogs and podcasts. Participants can ask questions by posting on their blog, reflect on the material and write about their learning on their own blog, as well as try the assignments. Everyone is welcome to participate in the beta course.

Please consider this to be version 0.1 of the course. I have many enhancements planned, but would like to wait untill I get some feedback from the community on what they consider to be usefull.

The website is at http://www.adaptivelearningonline.net
The course index is at http://www.adaptivelearningonline.net/courses-toc/

Your feedback is very welcome.

Regards
Parag
http://www.adaptivelearningonline.net
13 years ago
Hi,
I'm just guessing here... but is it possible that the data you have put as a BLOB has a mime type "text-plain" and you are getting an exception because you are trying to obtain a binary stream. This is just a random guess... I'm not even sure if mime types matter in BLOBS. Anyways hope it helps.
Parag
17 years ago
IMO an Interface must be be preffered to abstract classes unless you wish to have functionality that an Interface does not provide. This would include having non-primitive attributes (you can only define primitive data members in an interface). Also all data members in an Interface are final and static, so that may be another consideration. Also since we cannot implement methods within Interfaces, we must use abstract (non-pure) where we wish to impplement a method in the base class which will be used by the sub-classes.
Since Java does not support multiple inheritence it is always better to use Interfaces wherever possible so that we do not lock up a sub-class's ability to inherit from any other class.
Parag
Its possible to keep minimum code in the JSP. You must ensure that JSP pages are not refferenced directly, but are always forwarded or redirected to by a controller servlet The client GET/PUT request always goes to a controller servlet which will do the preliminary authentication/access control and pass on control to the JSP only if the criteria are met, if not the user is redirected to some error page ("access denied" maybe).
There are some libraries/frameworks which take care of access control. Jakarta Turbine is one of them (http://jakarta.apache.org/turbine). You may also want to check out JAAS (Java Authentication and Access Control Standard) from sun. There are also some papers on the net for standard ways to implement security... but I cant seem to remember where I saw them.
Parag
17 years ago
JSP
You can create a custom JSP Tag library which verifies if the user is allowed access to the jsp page. The Tag code will check the User Object type and see if the current page is accesible by the user. Such mappings can exist in a properties file. If you do not with to use property files then pass as parameters to the tag all user object types that should be allowed access to that page. The tag body when executed will redirect the user to an "Access Denied" page if the user is not allowed access to the page.
Your tag body can be some like this.
<security:accesscontrol />
Here your tag code will have to refer a properties file to check if the current User object in the session has access to this page.
<security:accesscontrol users="com.something.Type1 com.something.Type2" />
In this case your Tag code will simply validate if the current User Object is of one of the types specified.
Hope this helps
Parag
17 years ago
JSP
Could the answer be d. Object Diagram?
I think a sequence diagram shows the flow of messages among objects as time progresses. However it does not address any structural aspects of the objects. An Object Diagram on the other hand addresses the structural aspects of all objects in the system at a particular snapshot.
Parag
Jesse,
Maybe you can try another way to perform the debugging. Instead on relying on the remote debugger of an IDE, you can put log statements in you code using Log$J (http://jakarta.apache.org/log4j) and configuring it such that the statements are send to a remote log server. Such a setup will let youremotely debug a servlet or any other application also. I almost always prefer app logs to an IDE's debugger.
Parag
17 years ago
If you are using O'Reilly's Multipart Request, you must use their MultipartParser class to read the other parameters. I have used it succesfully a long time back. You will have to check the API of MultipartParser.java to instantiate and use it.
Hope it helps.
Parag
17 years ago
Instead of writing the query strings to an xml file, you could use some sort of messaging service (JMS) in which messages are automatically pooled. So everytime the JSP is invoked it sends the query strings out as a message and some object will pick up the message to perform the processing. If you still wish to continue using xml files, you can generate a seperate file for each request and name the file with a unique name (timestamp + thread id). This way your messages will not be lost. Your processing object can process all xml files in a particular directory and delete the file after processing is over.
Hope it helps.
Parag
17 years ago
JSP