Darren Estcourt

Greenhorn
+ Follow
since Jan 06, 2017
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Darren Estcourt

Thanks for all of your suggestions

I found some information, which has forced me into a re-think. Apparently it isn't easy to append to a serialised file, and therefore it explains why I am constantly over-writing the same data.

So when my program is running, I need to build some kind of list, maybe an ArrayList, and serialise everything is one hit.

At least I could do this with a "Save" option.

It's put me of serialization somewhat. My alternative is writing to a mysql database, but that's another story.

Thanks again all
6 years ago
Thanks for the feedback. Quite simply, I'm trying to serialise the "fullName" from the ManagerName class. I can serialise it, but the problem I have found is that if I use getters and setters and serialize a String variable i.e. fullName, then the data doesn't entirely persist. It can be overwritten, whenever I write to the file from another class with a different variable. When I write to the file from another class, the "fullName" gets reset to NULL. But if I persist an object reference, then the data never gets overwritten.

So I concluded that I really need to serialise an object reference. Therefore I created the "DataToPersist" class and simply created a parameterized constructor, and passed my String variable "fullName" as an argument to that constructor in "DataToPersist". But now I'm confused, how would I get the data from that constructor in question and use it in my "WriteClub" class ???

In short - I don't understand how to use initialised variables in a constructor, via a object reference call (i.e Test objRefCall = new Test(arg1), when I don't actually have the arguments in my calling class in the first place.

I hope this makes sense, I have been going round in circles with this problem. I am still very much a newb, most grateful for any help
6 years ago
Ok so, I am reading strings from the user using a scanner object reference and using those same strings as arguments to a parameterised constructor in another class. No problem there. However I don't understand how to access the values from the parameterized constructor in another class. Ultimately I am trying to serialise a user keyboard input, from the console. Also, does anyone have a link to a website which explains why object references should be serialised rather than variables? I used getters and setters to serialised variables, but they can be overwritten in writing to a file more than, but this is not the case with object references. Hopefully this makes sense ! Here are some code snippets, thanks in advance for any help!
6 years ago
Many thanks all, in particular to Carey, who highlighted two areas, where my code could be improved upon. I was using the "codeanywhere.com" IDE, apologies for the indentation.

I concluded that my design was entirely wrong, a "2D array" as I refer to it (perhaps wrongly!) should not really be a string, which has one set of elements with numeric data. I split them eventually into single dimension arrays and this has simplified things, and I have sorted this method out.

Thanks
6 years ago
I sorted out the indentation in my IDE, but when pasting it into this window, the indentation isn't copied across. I would be most grateful, if anyone could just give me a pointer in the right direction. I don't know whether what I'm trying to do, is even possible. Thanks
6 years ago
I have a two dimensional string array, one element holds letters (a football team name) and another holds a five digit number (stadium capacity). I would like to know how I can update the second element (which holds a number), when the user has added more "stadium seats". My 2D Array is called "club" (see parameter for the method). I am a newb, so I don't know whether, what I'm trying to do, is even possible. I have googled this numerous times and cannot find out whether this is possible. I have tried to indent this, but my browser is playing up, so apologies if the formatting is not ok.

My method is shown below.
6 years ago
I thought that any method or class, should have only one objective, hence the SRP. However, by adding a nested class, it would appear that you are nesting another piece of functionality, albeit closely linked to the outer class, and thus the outer class becomes bloated and with more than one objective, defying the SRP.

I am a newb, so maybe I have mis-understood. I have concluded that nested classes should only be used, in massive programs to streamline packages. It's certainly not something that should become a habit.

6 years ago
I have been reading the javadoc, in particular about nested classes, and I am slightly puzzled in terms of best practice, because of the "Single responsibility principle". Please correct me, if I am wrong, but I thought the Single responsibility principle (SRP) was intended for both methods and classes?

The notion of nested classes, seems to contradict the SRP. Please can anyone advise on best practice for this topic.

Thanks for your time
6 years ago
Very interesting, this is exactly the sort of thing I was looking for. It gives me a clear example of how and why this is worth knowing/doing. Thanks
6 years ago
I have been reading Oracle's javadoc, and I'm puzzled about a brief section which says that reference types can be returned from a method, as well as primitive types, and the parameters can also be object references of reference types.

I have worked out how to return an object reference, using parameters for primitive types, but I don't understand and nor can I find, an example and/or detailed explanation on how (or why) you would return an object reference, based on the arguments sent from the caller.

This is the section of the javadoc I am referring to :

----------------------------------------------------------------------------------------------------------------------------------------------------------

A method can also return a reference type. For example, in a program to manipulate Bicycle objects, we might have a method like this:


---------------------------------------------------------------------------------------------------------------------------------------------------------

Please can someone provide a link with a more detailed explanation that the javadoc, or simply explain how object references for reference types (e.g Bicycle myBike) can be used, and how
you can manipulate their values?

Still a newb, would appreciate help/advise. Thanks!
6 years ago
Thanks all

My requirements are simply to allow the user to click "save game" in my Java gui, and it will load their previous game. I started out using serialization, but then realised two things.

1. Serialization is limited, I can't create relationships per se, and I cannot read data from multiple sections aka there are no joins in serialization.

2, I felt it would useful to learn another language other then Java and my game will require some form of storage. I opted for mysql because it is open source. It might not be the most suitable RDBMS but I am a newb to back end code.

The point of the snapshot, was to simply save the game at a specific point, such that, the game can be re-loaded when the Java event is triggered by clicking the "load game" button.

Now then, I already know how to backup and re-load a mysql database using mysqldump and as Dave pointed out, this is one strategy which has been used in commercial software before. BUT it surely isn't the most elegant solution. In terms of level of details, I want the detail to be comprehensive, so I am anticipating a large database.
7 years ago
"All that information goes into the same tables as the information saved for all the other snapshots and the way you separate on set of data from others is via unique keys/identifiers".

Given the above comment, please can someone provide a link, which shows examples of sql code to capture a snapshot, without using mysqldump ?

The official mysql doc shows to use mysqldump.

I have googled this quite a lot and can't find anything specifically useful.
7 years ago
I have gone down the route of reading about timestamps and I can't find anything which suggests what type of field should have a timestamp.

My objective is just to version tables, so that when the user loads a saved game, the correct version of the table(s) are loaded.

I figured I wouldn't import a whole database, which might take a long time, given this database will be relatively large. Instead I would version tables with a timestamp and just load the tables required.

Can anyone offer me their insight on this issue?

Thanks

7 years ago
Thanks for that As a starting point, I want the users name and selected team to be persisted. To me, that means invoking a Java method which either run executeUpdate() or executeQuery() to my MYSQL database. The latter using a SELECT statement. For small amounts of data, this is fine. But then I wonder, what happens when player statistics need to be updated and then read back...that's a lot of MYSQL queries.

My other issue is knowing how I should present data in my GUI. I am thinking about "seperation of concerns" and yet I am tempted to run a SELECT statement from a method in my GUI, but then of course it will slow my GUI down.

Suffice to say I am still a newb in this context. Grateful for any advice
7 years ago