Hi I am a new Java programmer and have a small question about class design. I understand that something like this is a cyclic dependency and is probably not a way to structure a project: public class …
Tag: oop
Checking Field boolean value in Java Composition Class
I’m having some trouble checking the boolean value for a composition class that holds a few boolean fields. If true a print line statement will print but I’m not sure if the boolean value is not …
Creating multiple objects using the same instance
I just saw this tutorial creating multiple objects using the same instance by applying the DAO pattern and tried it in a simple console, but I always get this message java.lang.NullPointerException I’m now confused, as far as I know, a constructor can be used once only, and the object will be immutable. Kindly look at this: Fighter.java FightersDAO.java Demo.java Why
How to create a new object of Public Class
I am a newbie in Java, although I have knowledge of Object Oriented Programming from Python but I’m currently having problem understanding this example on creating public class either combining the …
How to resolve `Raw use of parameterized class ‘Comparable’` warning?
Got to implement the method below for an assignment which it’s subject is “WildCards”, but don’t know where to use wildcards in order to resolve the warning. Any ideas ? Answer Comparable is a generic interface, so to use it safely you must always specify the generic type to use. In your case, something like: is likely what you’re looking
A method should be in the class which realises a action or in the realised class?
Maybe the title is a little confusing, but I didn’t know how to say it properly (my English is not good at all, so sorry if it is harder to understand). Let’s say we got 2 classes, Person and Group, and a person can join a group. Both got a Collection of the joined groups or the persons that already
Why is casting in equals necessary?
I’m doing the Mooc course and it’s teaching us how to compare objects from made up classes like “Person” and see if they are equal to each other. They give us the following code: } For the equals method, I get that they compare using == first to check if it’s the same location. Next they see if the compared
What are transient dependencies?
I am studying the bnd introduction, and it says: ‘The advantage of Java was that it had found an elegant solution to the scourge of transient dependencies: Java interfaces.’ I also found the following quote: in the book ‘Professional Java for Web Applications’, but is there a simpler explanation for transient dependencies that this? Answer It’s not a thing. They
Is it better practice to use static factory methods over an interface implemented by many different objects? [closed]
Closed. This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 3 years ago. Improve this question It seems as though you could either use static factory methods or you can use an interface that many objects implement
Getting “cannot find symbol” error with reader.nextLine()
Here is my code (it is code to reverse a given string) But I cannot take in input because when I try to take the string input I get a “cannot find symbol error” even though I have clearly defined the variable “text”. This question is from MOOC.fi’s Java OOP course, and can be found here (question 52, if it