Koen Ursem

Greenhorn
+ Follow
since Nov 15, 2018
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
3
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 Koen Ursem

In the case && would not be allowed i would asume this could do as well?

4 years ago

Sam Peterson wrote:
Also, since we still have the R3 object that's not eligible for garbage collection at the end of this program, what is the lifespan of that object and the two reference variable after the program finishes?



Ooh i like this question,

I wonder if R3 would be up for GC at line 10 when there is no further use of the variable two in the current scope, or on line 12 where the scope of the current codeblock ends?
4 years ago
At line 8, one is being pointed to an empty adress not refering(pointing) to any Rabbit object in memmory.
At line 9, four copies this empty refer(null addres) from one also not refering(pointing) to any Rabbit objects in memmory.

This means only three after line 6 is still pointing to the Rabbit you called R1 created from the new constructor on line 3.


Explanation:
The new constructor statement in java is the moment where data is to be created in memmory.
The variables are just referals to this data, the variable one is of type Rabbit, this is only saying that it expects on the address it refer to, that there is data on this address that equals the data-structure of a Rabbit.


4 years ago
I usually think about variables in java as pointers.

So :
Rabbit one = memory point 1008 = new instance object of Rabbit1Data.
When you then then get on line 5,
Rabbit three = one; That actually says, Rabbit three is the same memory addres of pointer Rabbit one. (It actually copys the pointing value of one, and it is not really referring to one at all after it has copied the adres).

So now both variable one and three reference to memory point 1008. (And java will check from time to time if there are any variables pointing to this same memory adress).

Now as long as there is a pointer(variable) to point 1008, Rabbit1Data should not be garbage collected.
4 years ago
I think you have the idea frameworks are only big bulky frames that do allot of things and force you to go one way. But if you look at the wiki list of frameworks @ https://en.wikipedia.org/wiki/List_of_Java_frameworks You will see there are lots of small usefull frameworks as well, some of which you may even have used already. Frameworks like JUnit, Mockito JodaTime, Lombok, SonarLint/SonarQube as example are pretty commonly seen in projects. And those are not so big that it takes allot of time to use the basics.

I would just take a look through the whole list, see if you have seen or maybe even used some before, and check out some of the frameworks to see if you like them.
Only thing I see wrong right now is that you print this.student in the displaycourseinfo instead of this.enrolledstudents (You may have to find a way to print a list correctly).
your course class is now holding both a student object and a enrolledstudents list right now, but it could be this was your intention to have that student be the teacher of the course or something?

And yes, when you have more students and courses to work with you may want to have a way of selecting the right ones. Something in the trend of if student.name = ?? then do this. Same for course.
5 years ago

Daniel Demesmaecker wrote:I you have a seperate class for your courses who have enrolled students in them it's not enough to pass only the student. You have to create an array who keeps track of the course and the enrolled students (I would use a hashmap).
so you have to pass both student and course, then in the function looping the hasmap searching for the course and adding the student, but the way I descriped before is way easier.



A Hashmap would be a neat solution, but considering this is an assignment I think OP is more looking for a simple list<Student> implementation in the Course object.


@OP
If you want to add a student to your course, you would need a list/array in your course object to save this in.
Then when you want to add the student you want to call this course object and run a method that adds the student you have given to this list/array.

Considering the code from your first code, something like this  'c.addStudent(yourStudent);' in the for loop. Be aware that your for loop is running over all courses in your Clist, so now the student would be enrolled to all courses if you implement the suggested method. I will let you try to figure that part out for yourself for now, let us know if you can figure it out or not
5 years ago
Your current code when the commented line is not commented will try to add your student into the list of courses. Now a list of Courses and Students mixed together would indeed not be what you want and if Clist is of type Course would even give you an error.

There are multiple ways of solving this, you can either give the Student an empty list of Courses where you add the courses to the list in the Student object. Or you can add an empty list of students to your Course and add the student to a students list in the Course object.
You can also let both objects have a list where you add persons to courses and courses to persons. But: then you have double data which would be redundant and can result in inconsistent data. Since person has its own list, and course has its own list.

You may want to think first about what approach you would like to make, and write it down to get an idea.
5 years ago
If this is designed by a man, he must've been a god at reading women right.
We have 2 ovens at home, 1 simple digital one, and this complex weird one with a rotating button that can be pushed in, pulled out and who knows what magic tricks doing all kind of different functions and settings.

My wife understands that weird one and doesn't get the digital one. I understand the simple one but feel lost at the complex weird one to me.
5 years ago

Junilu Lacar wrote:

Koen Ursem wrote:My guess is either your current app location is read with single backlashes where there is a '\u' in the path name from a folder or file starting with a 'u'. Or there is a property in one of the config files that points to a folder with a occurrence of '\u' like '\user' in the path.


That is a very good guess. In fact, it's what I would call an "informed and highly-probable guess." Way to think outside the box, Koen! In fact, I'm giving you some Thanksgiving Pie for it, even if it doesn't pan out (which I think it will).

@OP: If you can run the grep command, use it check if your properties file contains "\u" at all. On Windows, I believe the equivalent command is "findstr", at least according to what Google tells me.



Well thank you kindly!
I bet most programmers have at least once dealt with issues on paths with slashes and backslashes when using other systems. I had almost the same error a year ago on a vm machine where I fixed a path in the code replacing the \ for a double \\. In this case it does seem a bit different in that there could be a configuration reader that reads the path as a string at first with the properties load function, considering the file type and system it probably sees \u in the string as a encoded Unicode character that would be followed by a digital for the Unicode character.

So if I am indeed correct OP has to find a way to either escape it in the config, save the config file in a different format (UTF-8? not sure on it), or if it is a directory avoid the the occurrence of \u in the folders and file name.
Otherwise the code would have to be changed to escape it if that wouldn't work, but from the story I understand OP is not directly able to change this.
5 years ago
Is your application in a folder starting with a 'u' like c:\user\myapp for example?

In some systems the \u in user gets faulty recognized as a Unicode character.
But it could also be that in one of the xml/config files there is a path named with \ instead of \\ or /.

My guess is either your current app location is read with single backlashes where there is a '\u' in the path name from a folder or file starting with a 'u'. Or there is a property in one of the config files that points to a folder with a occurrence of '\u' like '\user' in the path.
5 years ago
Edit(cant add to previous message): It is by the way not because the constructor is a string, but because you have the String name; in the body of the class itself that it handles name as a string and cannot be set initialized as String again.
5 years ago
Yes would be this.name = name; without the String in front of it, since it is already defined as a String holding object. For the rest your Employee class looks fine.
5 years ago
I have spotted the following when I run your code,

the first is that you mix up the int[] and string[] arrays in your method. Once you instantiate it as a string or int, you either have to convert those and save it in a different variable or keep it the same type.

The 2nd is that you created a method signature (non declared method) to be overwritten by classes that could implement/extend the class, so the method can not have a return.
Example of the difference:
public static void overrideMe;
public static String giveMeString(){ //code };

When you managed to fix these, you may want to look at how to change line 13 to call a static method.
5 years ago
Since you are working with char inputs, you may also like the methods that the Character class in java gives you.

You can do for example:
Character.isDigit(myChar)
and
Character.isLowerCase(myChar)
and some more useful methods.

which are returning true or false when a char is given.


5 years ago