I have updated in http://www.freejavaclass.com/
InetAddress inet = null;
try
{
inet = InetAddress.getByName("mail.google.com");
System.out.println ("IP : " + inet.getHostAddress());
if(inet.isReachable(1000))
{
System.out.println("Server is up");
}
else
{
System.out.println("Server is down");
}
}
Monday, June 21, 2010
Friday, June 4, 2010
Interviewer: Explain about java collections.
I have updated in http://www.freejavaclass.com/
Collection is a group of objects treated as single unit. Arbitrary objects can be add, delete and modified as element in collection. Java designs frequently handling group of elements as collection. The key interfaces used by the collection framework are List, Set and Map. The List and Set extends the Collection interface.
A Set is a collection with unique elements and prevents duplication within the collection. HashSet and TreeSet are implementations of a Set interface. A List is a collection with an ordered sequence of elements and may contain duplicates. ArrayList, LinkedList and Vector are implementations of a List interface.
The Collection API also supports maps, but within a hierarchy distinct from the Collection interface. A Map is an object that maps keys to values, where the list of keys is itself a collection object. A map can contain duplicate values, but the keys in a map must be distinct. HashMap, TreeMap and Hashtable are implementations of a Map Interface.
Collection framework provides flexibility, performance, and robustness.
• Polymorphic algorithms – sorting, shuffling, reversing, binary search etc.
• Set algebra - such as finding subsets, intersections, and unions between objects.
• Performance - collections have much better performance compared to the older Vector and Hashtable classes with the elimination of synchronization overheads.
• Thread-safety - when synchronization is required, wrapper implementations are provided for temporarily synchronizing existing collection objects.
• Immutability - when immutability is required wrapper implementations are provided for making a collection immutable.
• Extensibility - interfaces and abstract classes provide an excellent starting point for adding functionality and features to create specialized object collections.
Collection is a group of objects treated as single unit. Arbitrary objects can be add, delete and modified as element in collection. Java designs frequently handling group of elements as collection. The key interfaces used by the collection framework are List, Set and Map. The List and Set extends the Collection interface.
A Set is a collection with unique elements and prevents duplication within the collection. HashSet and TreeSet are implementations of a Set interface. A List is a collection with an ordered sequence of elements and may contain duplicates. ArrayList, LinkedList and Vector are implementations of a List interface.
The Collection API also supports maps, but within a hierarchy distinct from the Collection interface. A Map is an object that maps keys to values, where the list of keys is itself a collection object. A map can contain duplicate values, but the keys in a map must be distinct. HashMap, TreeMap and Hashtable are implementations of a Map Interface.
Collection framework provides flexibility, performance, and robustness.
• Polymorphic algorithms – sorting, shuffling, reversing, binary search etc.
• Set algebra - such as finding subsets, intersections, and unions between objects.
• Performance - collections have much better performance compared to the older Vector and Hashtable classes with the elimination of synchronization overheads.
• Thread-safety - when synchronization is required, wrapper implementations are provided for temporarily synchronizing existing collection objects.
• Immutability - when immutability is required wrapper implementations are provided for making a collection immutable.
• Extensibility - interfaces and abstract classes provide an excellent starting point for adding functionality and features to create specialized object collections.
Object oriented Java
I have updated in http://www.freejavaclass.com/
The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account, Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and Encapsulation are the 3 pillars of OOPL]
Inheritance: The main purpose of inheritance is code reusability. In java we can achieve this by two ways,
• In has-a relationship you can achieve code reusability but can’t achieve polymorphism, the one way to achieve polymorphism is use interface implementation in your design.
Polymorphism: The ability of one object reference will hold the address of another object in the same inheritance hierarchy and capable of executing the method in the address holding object at runtime. The benefit of polymorphism is that it is very easy to add new classes of derived objects without breaking the calling code.
Encapsulation: Refers to keeping all the related members (variables and methods) together in an object. Being able to encapsulate members of a class is important for security and integrity and also improves code modularity by preventing objects interacting with each other in an unexpected way.
The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account, Customer etc. The features of the OO programming languages like polymorphism, inheritance and encapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and Encapsulation are the 3 pillars of OOPL]
Inheritance: The main purpose of inheritance is code reusability. In java we can achieve this by two ways,
• In has-a relationship you can achieve code reusability but can’t achieve polymorphism, the one way to achieve polymorphism is use interface implementation in your design.
Polymorphism: The ability of one object reference will hold the address of another object in the same inheritance hierarchy and capable of executing the method in the address holding object at runtime. The benefit of polymorphism is that it is very easy to add new classes of derived objects without breaking the calling code.
Encapsulation: Refers to keeping all the related members (variables and methods) together in an object. Being able to encapsulate members of a class is important for security and integrity and also improves code modularity by preventing objects interacting with each other in an unexpected way.
Tuesday, June 1, 2010
What is a reflection package?
I have updated in http://www.freejavaclass.com/
java. lang. reflect package has the ability to analyze itself in runtime.
java. lang. reflect package has the ability to analyze itself in runtime.
What are inner class and anonymous class?
I have updated in http://www.freejavaclass.com/
Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.
Exile on Main Street
Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.
What is the difference between this() and super()?
I have updated in http://www.freejavaclass.com/
this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.
What is Garbage Collection and how to call it explicitly?
I have updated in http://www.freejavaclass.com/
When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.Avatar (Two-Disc Blu-ray/DVD Combo) [Blu-ray]
When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.Avatar (Two-Disc Blu-ray/DVD Combo) [Blu-ray]
What is final, finalize() and finally?
I have updated in http://www.freejavaclass.com/
final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.
final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.
What are different types of access modifiers?-
I have updated in http://www.freejavaclass.com/
public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.
public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.
What is the difference between an argument and a parameter?-
I have updated in http://www.freejavaclass.com/
While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.
While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.
What is the use of bin and lib in JDK?
I have updated in http://www.freejavaclass.com/
Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.
Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.
What are Class, Constructor and Primitive data types?
I have updated in http://www.freejavaclass.com/
Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.
What is the difference between Assignment and Initialization?
I have updated in http://www.freejavaclass.com/
Assignment can be done as many times as desired whereas initialization can be done only once.
Assignment can be done as many times as desired whereas initialization can be done only once.
What is the volatile modifier for?
I have updated in http://www.freejavaclass.com/
The volatile modifier is used to identify variables whose values should not be optimized by the Java Virtual Machine, by caching the value for example. The volatile modifier is typically used for variables that may be accessed or modified by numerous independent threads and signifies that the value may change without synchronization.
The volatile modifier is used to identify variables whose values should not be optimized by the Java Virtual Machine, by caching the value for example. The volatile modifier is typically used for variables that may be accessed or modified by numerous independent threads and signifies that the value may change without synchronization.
purpose of java static class
I have updated in http://www.freejavaclass.com/
Static classes are typically used as a convenient way to group related classes without creating a new package.
Static classes are typically used as a convenient way to group related classes without creating a new package.
Subscribe to:
Posts (Atom)
How can instantiate Java interface without implementing.
public interface Foo { String method(); } public class Claaa { public static void main(String[] args) { Foo fooByIC...
-
1) Download docker for windows and don't install. 2) Restart the machine and enable "Virtualilaization" in BIOS settings 3) ...
-
http://freejavaclass.com/articles/j2ee/hibernate/multiple_persistence_unit_in_jpa.jsp
-
I have updated in http://www.freejavaclass.com/ final : final keyword can be used for class, method and variables. A final class cannot b...