Java 7 Objects class [closed] - java

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
There is a public final class Objects in Java 7 that extendes the java.lang.Object base class.
Will this by default be the base class like or do we need to call the method on "Objects" class and call the corresponding methods?

No. Nothing changes. The Objects class is simply an utility class. It has only static methods, it's in the util package, and does what ObjectUtils from commons-lang is doing.

Objects is final and it extends Object giving you null safe utilities.

Related

Why is ClassLoader an abstract class? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
ClassLoader is an abstract class, even though it doesn't have any abstract methods. Why is that so? Are there any other abstract classes without abstract methods?
A class with abstract methods has to be abstract. However, an abstract class doesn't have to have abstract methods.
Generally, a class should be abstract whenever it doesn't make sense conceptually for instances of that class to exist. Having incomplete implementation is one example of this (and it happens to be enforced by the compiler), but it's not the only example.

Java Enum: Encapsulation and runtime initialization [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have a funny question on the way home
I have an Enum
public enum Gender{
Yes(Constants.male()), female(Constants.female());
private final String value;
private Gender(String option){
value = option;
}
}
.. should I encapsulate value or just declare it as public?
Is there a disadvantage of run-time initializing the value?
In your case there shouldn't be much difference, the String class is immutable. It is recommended however as encapsulation is good practice.
As far as "run-time" init, I am not sure what you mean. Enum's as essentially singleton's so this would be inited when it is class-loaded. This is at runtime, yes, but there are no disadvantages; especially if you do not want to hardcode the values.
EDIT
As #GyroGearless points out the field should be declared as final, this is best practice even if it isn't public as it's a constant set in the constructor.

Load and start a Java class dynamically [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Class<? extends Runnable> theClass =
Class.forName("C:\Myclass.class").asSubclass(Runnable.class);
Runnable instance = theClass.newInstance();
new Thread(instance).start();
I want to write like this C:\\Myclass.class
Class.forName() takes a class name such as java.lang.Thread as parameter, not a file path. You have to load your class by using a dynamic ClassLoader
See: Method to dynamically load java class files
You have an error in your Class.forName().
You have to supply the fully qualified class name (FQCN) to this method.
If you want to load a certain class from an external source you have to write your own ClassLoader.

Work of Serializable in Java [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
When serializable is a marker interface, how could it make the object persistent?
When the body of the interface is nothing how it it perform some action on the class that implements it?
Using ObjectOutputStream makes the object persistable. This class will only serialise classes marked with this interface to prevent you serialising classes which you didn't intend or cannot be serialised.
Note: Some serialisation libraries do not follow all the rules of Serialzation and can ignore the Serializable interface.

can I have an abstract class inheriting from another abstract class ? (java) [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
public abstract class Two extends One
{
}
Class One is defined as
public abstract class One
{
}
Yes, and you cannot instantiate it either, of course.
Yes, you can.
If you extend a class with an abstract class and do not define or provide the implementation for the base class abstract methods then the child class extending it would automatically become abstract.

Categories