This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
i have a Main class that contains my main(), that starts my application by loading my ApplicationConfig class passing the mode("server" or "" or "alone").
in the ApplicationConfig i have all three fields databaseLocation, Address and portNumber each one is in its own JPanel, depending on the mode specified the JPanel's are set to visible.
after the user configures the application the user presses a "start" button and..
the databaseLocation variable for creating the "new Bookings object is set in the applicationConfig constructor (if that isn't clear by now);
I am halfway through coding this solution if your wondering why the serverMode() is empty.
So depending on the mode that is specified either the guiFrame is created(client and alone mode) or serverFrame will be created, the server frame will be visible to let user know the application is running and the application is still connected.
Also i have a class Bookings that when constructed, creates an instance of my DatabaseReader class(which reads the bytes from the file). my Bookings class then uses the instance to set all its variables, such as int magicCookie, int numberOfFields, ArrayList<String> bookings...
so now an instance of the ArrayList<String> bookings (line 2) exists in my ApplicationConfig class, so in short;
*alone mode example*
1) user makes request via gui class
2) gui class calls ie; find() from my Data class
3) data class performs the operation on the ApplicationConfig.bookings variable
4) data class returns the result to gui class
1st Question, should i have another class, lets say "BookingsOperations" that takes method calls from my gui class and creates a thread that calls my Data class methods, OR should i just create the threads in my gui class?
2nd Question, my approach of having two septerate classes, one for client(to send requests and display them in the gui) and one for server(to recieve request, perform operation and send it back to the client), is it a good/okay/terrible approach?
thanks if you sat through that and read my question, i look forward to your respones.
Maybe I don't understand your approach completely, but it seems weird to me that your Data class performs the operation on the ApplicationConfig.bookings variable I would expect something like this in standalone mode:
1) user clicks search-button in class
2) a class (some kind of controller) calls find-method of your Data class (if you decide to go for a thick client) or some business service method (if you decide to opt for a thin client approach)
3) find-method of data class returns result to the controller class (making a call to DatabaseReader)
4) the controller class passes the result to the gui (JTable) which is responsible for showing the matching records
If you decide to have seperate classes for handling requests in standalone and network client mode, they should implement the same interface. Otherwise your code will be one big mess (because everywhere you have to check the mode the application is running in). And if you have this interface, you can program against this interface (which is considered a very good practice) and your main gui window will be completely unaware if it's running in standalone or network client mode and that's
And as a side note: classes in Java start with a capital letter according to code conventions, so you should use GuiFrame instead of guiFrame
i can post my source code for GuiFrame, ApplicationConfig and Data, so you can see how my application is working, because perhaps my explanation was a little vague.
it would be really helpful to me if you could critic my code...
my application works fine for alone mode at the moment, although it is not thread safe yet, i just wanted to be sure im on the right track before i carry on further, investing more time on it.
also do you think it would be better if my bookings variable existed in the GuiFrame class? I need the booking variable for setting up my JTable when the application starts so i can either have it exist in my ApplicationConfig class, GuiFrame class or Main class. I didn't put it in my Main class because the only responsibility of that class is to launch the application, is how i understand it.
also you don't like the approach ive taken of creating a Booking object that stores the database file information such as the int magicCookie, String fieldNames and ArrayList<String> bookings variables? in my approach the Data class would perform the operations on these variables (ArrayList<String> bookings mostly) and each time a record is updated, created or deleted the bookings variable writes to the database file.
Thanks for your patience, i realize i probably sound like a noob, but that's why im here looking for help.
You can post a snippet of code, but no complete sources of 1 or more classes.
Why not first make sure your Data class is completely finished before developing the GUI? Making your Data class thread-safe is one of the hardest (and most important) parts of the assignment.
Have you already decided which type of approach you are going to follow: a thin client or a fat/thick client? This would make it easier to comment on your questions/assumptions.
Your Data class invokes methods on the booking-object and the booking-object is kind of a helper class to facilitate file operations (reading and writing). Is that correct?
Using a List to hold your bookings (you are using a record cache) is not a good idea, because you assume a mapping between the recNo (in the file) and the index (in the List). And while this is true for the database file you have know, it might not be the case in the (near) future, e.g. when only the records which have an availability date not in the past are loaded into the record cache. I consider a Map as a better alternative.
Maybe you want to follow this thread as well, because that's also someone just starting with OCMJD.
Joined: Apr 10, 2011
I started my application by coding from start to finsh, ie Main class, ApplicationConfig class, GuiFrame class, Data class, Bookings class, DatabaseReader and DatabaseWriter classes. and ofcourse other class like properties. thats why i ended up coding the GuiFrame before the Data class.
my intention is, that the client will call a method(from the GuiFrame) then the Client class will send the request to the server, the server will recieve the request and the Server class will send the booking back to the client and the client will perform the operation on the booking, and send the result back to the server in the case of create(), delete() or update(). so i think that is a fat/thick client, right?
my Bookings class stores variables such as ArrayList<String> bookings. to give you an idea this is the constructor...
The databaseReader instance is an instance of the DatabaseReader class(obviously) and that reads from the file, my bookings object will then hold all the variables, and my data object will perform operations on the bookings ArrayList<String> variable.
So the data class create() will look like this for example...
 do not post source code of complete methods
I havent created my exceptions yet, that is why it doesn't throw the exceptions, and as i already stated the class is NOT thread safe yet (just to be clear)
when you say that using a List is not a good idea as the recNo in the file and the index in the list may not be the same, would that be true if if my databaseReader instance reads the records on the file from start to finish, adding each record to the ArrayList<String> bookings as it goes, like this...
 do not post source code of complete methods
thanks for all your advice so far, i will check out the thread you suggested.
You think you are developing a thick/fat client? That's something you should definitely know for sure. Will your business logic be at the client or at the server? When you want to make a booking, will you perform 1 call from the client to the server (e.g. bookRoom) or will you have some seperate calls to the server (lock, update, unlock)? And don't get me wrong: both solutions (thin or thick) are perfectly acceptable.
If I look to your code (which I had to remove, because posting actual code of complete methods is not allowed), I'm quiet sure you don't have much experience with developing java applications and certainly not with a client/server one. Your Data class has references to Swing classes These classes should only be used in your client! Your Data class resides on the server, showing some kind of message dialog with an error message has completely no sense at all!
And because you have this limited experience, that's why I suggested to start with the Data class, because this class is the most important one and the Data class should be thread-safe and being able to read, update, delete records and also provide some kind of logical locking system (lock, unlock). And when you develop in an OO language like Java code reusability, maintainability, extensibility,... are very import key features of good software design and your code does not have any (excuse me for being so harsh)! For example: your Data class should be completely unaware of the type of records it is handling, so you can (re)use this class again when you need to deal with a similar file containg customers, hotels,... (Now your code contains references to a Booking class, which makes this class not reusable). All the method signatures (of the interface you have to implement) use String, so using only String in the Data class will make your class a lot more reusable (certainly if you combine it with dynamically reading the database schema, which is not a must requirement by the way)
Like I already said before: as long as you read all records from start to finish a List is not a problem, but what would happen with the indexes if you have to skip all records in the past (because the database file contains 50000 records and 45000 of them are in the past which makes your program slow down and you can get memory issues)? You'll be in trouble with your List and that was what I try to show.
Do you use some resources (books, tutorials,...) to help you with this certification. I think you don't, so I strongly suggest and recommend you buy the SCJD book by Andrew Monkhouse, it's a great book and you'll learn a whole lot from it, because at this moment your solution so far just is terrible.
Joined: Apr 10, 2011
you are correct, i do not have much experience programming, six months ago, i had zero experience in programming, which is why i posted here.
i would like for my client to make one call from the client eg: createBooking() to the server. (my application is All About Improvement Ltd, not URLybird, not much different by the sounds of it)
Roel De Nijs wrote:when you develop in an OO language like Java code reusability, maintainability, extensibility,... are very import key features of good software design and your code does not have any (excuse me for being so harsh)!
thats fine, i asked for honest criticism.
thanks for your advice, i will spend more time working on my solution.
Matthew McDonald wrote:you are correct, i do not have much experience programming, six months ago, i had zero experience in programming, which is why i posted here.
I would strongly suggest to buy the SCJD book I mentioned. I used that book too when I started this certification and I had already 5 years of developing experience with Java. And the book was still very instructive and very good value for your money. You'll learn a whole bunch of concepts which you can apply on your assignment.
This forum is also a great resource: every possible question is already asked more than 1 time, so if you start reading questions posted by other ranchers and joining some discussions you'll learn also a lot. Another useful resource is the paper written by my good friend Roberto Perillo, which you can find as one of the sticky posts in this forum.
Matthew McDonald wrote:i would like for my client to make one call from the client eg: createBooking() to the server. (my application is All About Improvement Ltd, not URLybird, not much different by the sounds of it)
Ah, you are heading for a thin client approach I will give you a high overview of the main classes in a possible (thin client) solution.
First you have the Data class. This class must implement the given interface. How you design this class is completely up to you. You can use a record cache, you can have 2 helper classes (a class for all your file operations and a class to keep track of the locked record),... This class must be able to handle multiple concurrent requests and thus should be thread-safe. If you have a look at the marking criteria in your instructions, you'll see that 120 points (out of a possible 400) are on Data class and locking. So that's why I suggest you should start with this class and develop just this class until it's completely finished. You can use a testing framework (junit, testng,...) to write tests and validate the implementation of the different methods.
Then you will have to create another interface, which is your business service. For the assignment this business service will contain at least 2 methods: find and book. You have to create at least 1 implementation of this interface. This implementation will be exposed on the RMI-server (for the networking client) or will be used directly (for the standalone client). You could also decide 2 create 2 implementations (one to expose on your RMI-server and another one to use in the standalone client). This business service will contain the business logic needed to fulfill the requirements you got. In your business service you could use a bean instead of a String to hold the necessary data of a booking (because it's easier to work with a bean than with a String).
Finally you have your GUI. You'll have a main window which is used for the standalone and network client. This window will contain some input fields, some buttons and a JTable to display the results. When you click for example on the search-button, you will invoke the find-method of your business service (the implementation you'll need to use depends of course on the mode the application is running in, but your main window is completely unaware of which mode it's running in). You'll need a few dialogs to enter the necessary configuration settings to start the different application modes (for example: if you start the standalone application, the user will need to enter or pick the database file).
Quick question: so you have an assignment "All About Improvement Ltd". Not URLyBird (hotel rooms) or Bodgitt&Scraper (contractors)? What's the "All About Improvement Ltd" about? Seems Oracle has a completely new assignment, because that's the 1st time someone mentions this name Hopefully instructions are similar to the other assignments.
Joined: Apr 10, 2011
im doing this application for my diploma, i have two modules to complete my elective, which is java. the first module this elective was a SCJP exam, which i passed. the second is this SCJD exam, which i have 160 hrs to complete. im guessing that the institute im studying at created my exam("All About Improvement) against the sun oracle(URLyBIRD) exam, that would explain why my specs are different.
the requirements are no different between my exam and the sun exam however.
ive done a major overhaul of my application in the last two days, i took your advice and removed the swing components from my Data class. I understand what you said about the "ArrayList<String> bookings" i was using, so i have decided to use a HashMap instead using the records "recNo" as the key and a String as its object, im not 100 percent on the way im mapping the HashMap, but happy for now. I am also going to figure out how i can lose the calls to my ApplicationConfig.bookings instance. from my Data class, i think your last post has sorta touched on how i might do that.