Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Alex Lucard

Ranch Hand
+ Follow
since Aug 06, 2015
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
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Alex Lucard

Thank you Campbell Ritchie This is what I am looking for.
4 years ago
I am still new at Java. Can you give an give an code example of this Comparable plus will this let me Comparable an arrays list of objects for two fields.
4 years ago
Sorry input excel file was hard to see the rows
sampel  excel file input
TimeStamp                             Location                       Cardnumber
11/28/2017 2:13 PM               Reader 2 Suite Exit       1
11/28/2017 1:22 PM               Reader 2 Suite Exit       2
11/28/2017 1:18 PM               Reader 3 Suite Entry    2
11/28/2017 10:54 AM             Reader 2 Suite Exit       2
11/28/2017 8:33 AM               Reader 3 Suite Entry    3
11/28/2017 8:30 AM               Reader 2 Suite Exit       1
11/28/2017 8:02 AM               Reader 3 Suite Entry     2
11/28/2017 6:44 AM               Reader 3 Suite Entry     3
11/27/2017 6:34 PM               Reader 2 Suite Exit        1
11/27/2017 5:35 PM               Reader 2 Suite Exit        2
4 years ago
How can I sort an arrylist of objects based on two fields in the objects.
I am reading in an ecxel file with three rows TimeStamp, Location, Cardnumber
sampel  excel file input
TimeStamp                             Location           Cardnumber
11/28/2017 2:13 PM Reader 2 Suite Exit 1
11/28/2017 1:22 PM Reader 2 Suite Exit 2
11/28/2017 1:18 PM Reader 3 Suite Entry 2
11/28/2017 10:54 AM Reader 2 Suite Exit 2
11/28/2017 8:33 AM Reader 3 Suite Entry 1
11/28/2017 8:30 AM Reader 2 Suite Exit 1
11/28/2017 8:02 AM Reader 3 Suite Entry 2
11/28/2017 6:44 AM Reader 3 Suite Entry 1
11/27/2017 6:34 PM Reader 2 Suite Exit 1
11/27/2017 5:35 PM Reader 2 Suite Exit 2

I have them reading into an ArrayList
I would like to sort the Arraylist on first on Cardnumber then Timestamp.
This way all the same card numbers will be together and then that is sorted by datetime.

I am looking for help on how to do the sort arraylist of objects on two fields.package com.lucard.mutators;

Some of my java code.
___________________________
4 years ago
I will look into the serialise, But can you save the text file inside the jar file?
5 years ago
Can anyone tell me how you get a java object to save the values in it's fields between restart without the use of a database or external file.
I created a GUI jar file that when runs will login into a server and pull a log file.
The GUI has text fields.
1) Server IP
2) Login ID
3) Password.
I would like it to keep my settings between runs.
The password expires every 14 days so I do not what to hard code it.
5 years ago

Bear Bibeault wrote:Notice that the only static is for the main method's driver class, which isn't part of the model.

static is something that should be use very sparingly, and only under very specific circumstances, none of which apply to your case.



I am going to redo my code to fit the way you have it here.
6 years ago

Bear Bibeault wrote:Not a static to be found.



Thank you this will help me see how to use Static and non Static to get a object for use as a value holder.
6 years ago

Bear Bibeault wrote:Exactly, just getting the right output does not mean it is "working". Using static is wrong -- once again, you need to understand what that is actually doing so you can see why it creates the right output, but only by accident.


I am at a loss can you show me the same thing with out the static keyword.
Can you show me the way you are talking about this in code.
I learn better with code examples.
Can you make a java object with fields to hold strings and/or int values that other classes can pull that data out of.
Something like a TaxObj with a field to hold state tax value that one class can set and other classes can pull this value or string from.
It does not have to be a int for tax I was just using that as an example.
6 years ago
I did get this to work I had to change just one line in the original class TheRecordObject.
I added the keyword static to the private String.

This is now my output.
run:
Store the value of Mike in TheRecordObject
The Full name is =Mike
BUILD SUCCESSFUL (total time: 0 seconds)
6 years ago
To help clarify
What I think is going on is that in the class StoreTheName I am instantiating an new object from TheRecordObject and passing the value Mike into the the private String firstName by calling setFirstName.

Next from the ReadNameObject I am trying to access and print the value that was just stored in the firstName String from the StoreTheName class. Now here is were I think things are going wrong.
The ReadNameObject is not access the same object that was instantiate from the StoreTheName class.
Let me know if this is wrong but I think I need to fix the ReadNameObject to call the same object that was made in the StoreTheName class,
6 years ago
Ok I did make the change and removed the key word static from both the StoreTheName and ReadNameObject.
Then changed the code in the TheMainClass to this.



I still get the same output. I think it is instantiating a new object TheRecordObject each time. What i think is missing is how to not make a new TheRecordObject object but to use the same TheRecordObject object for both method StoreTheName and ReadNameObject.
6 years ago
I do not have a preference at this time on static or or no static.
If I remove the static from a class like ReadNameObject
Then I will need to change the main method.
Change the one line from
ReadNameObject.fullName();

to this next two lines.

ReadNameObject readIt = new ReadNameObject();
readIt.fullName();
but I still get them same output.
Store the value of Mike in TheRecordObject
The Full name is =null

I can do it but I still get the same out put. null.
6 years ago
I find Bear Bibeault comment to be insulting. This is a site for people just getting start programming. The way you learn to program is by doing it. So to tell someone “Are you trying to learn how to program, or just trying to get some specific output written” is not helping.

I did post the output I did get and the out put I would like to get in the post.

This is the output I get
Store the value of Mike in TheRecordObject
The Full name is =null


This is the output I would like to get
Store the value of Mike in TheRecordObject
The Full name is =Mike
What I am trying to learn is who in java is to pass data/values from one class to multiple classes using a object or gettters and setters.
6 years ago

Campbell Ritchie wrote:

Alex Lucard wrote:Bear Bibeault Why not . . .

I think you need to learn what static means before you try any more programming.


Will changing them to something other than static get the output I am looking for.
6 years ago