Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
If you can please help me understand if this is possible to create an object in java without having a class.
Not possible, it's either a primitive or an instance of a class.
In Java, Objects are a copy of Class (or better - instance of it).
So there can't be objects without classes.
But there is a predefined class Object which all classes inherit and therefore all objects are of type Object.
Maybe you can try
Object myObj = new Object();
if that helps for you
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Can someone explain this property with use cases by an example.
In the context of Collections class (and some other class of the Java Collections Framework) it means that a Collection is a "wrapper" of another Collection: the inner class stores the data and the outer class adds some behavior that the inner one hasn't. An example are the methods of Collections whose name starts with synchronized or unmodifiable: the method synchronizedList(List) adds synchronization to any given List, the method unmodifiableList(List) makes any given List unmodifiable and so on.
See also the Decorator Pattern.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I, and What is the best/proper way (ie, most performant and clearest syntactically) in Java to create object instances based on a prototype object instance, when this will occur repeatedly and in a performance critical code path?
I have thought about cloning via a cloning support library, but is that the best/only way? (These need to be arbitrary objects, btw, not ones that implement Clonable).
To clarify what I mean: I have an existing instance of Class T, which has fields set on it, and I want to pop out many versions of the same object to use separately, with the best performance and syntactic clarity possible.
Thanks.
Create a builder, which receives this class instance:
Person newOne = new PersonBuidler(oldOne).setAge(42)
Implementation of this builder may use apache common BeanUtils for cloning Java Beans or some other utility library for cloning arbitrary class.
See How do I copy an object in Java?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Should I always make new objects out of everything in java even if i know i will only use one?
obj = new obj();
obj.method();
or just
classOfobject.method();
Why should I bother with the creation of a new obj in a situation like this?
classOfObject.method() only works if method is static.
Having said that, if your class truly represents a "thing", be that a user, a car, whatever, then you should make the method non-static and use new to make an object and invoke information on it.
If the class is a container for methods that don't have anything to do with objects themselves, e.g. a Utils class like StringUtils, then you can use static methods, e.g. StringUtils.toUpperCase(), and be happy with it.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If I have a variable defined in a method,can I get its Class Object using reflection
public void check(List<?> String> list){
Map<String,String> map // do something
}
Can i Obtain the Class Object to perform reflection for list and map variables,both are local variables
No, reflection does not expose local variables. Byte code analysis may help, but I don't know what you are trying to do.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
If possible I would like to know what class provides input and output streams? Is it Object or System class? I am asking this because every class inherits Object class. This is a bit confusing to me.
Input and Output operations are performed by the reader class and it's sub-classes. Object is a base class which provides some "usefull" methods such as equals() and toString().
i don't know what exactly is your confusion , but i think its java.io.OutputStream and java.io.InputStream both are interfaces , based on what Stream you use , there definition in Stream class changes. i suggest you read some basic books and gets your fundamental of OOP strong.
and make full use of
Reference doc