Saturday, October 9, 2010
Tuesday, October 5, 2010
Monday, October 4, 2010
Thursday, September 30, 2010
How can use annotation based transaction in spring?
http://freejavaclass.com/articles/j2ee/hibernate/multiple_persistence_unit_in_jpa.jsp
Wednesday, September 29, 2010
Thursday, September 23, 2010
Wednesday, September 22, 2010
Tuesday, September 21, 2010
Monday, September 20, 2010
Sunday, September 19, 2010
Thursday, September 16, 2010
Wednesday, September 15, 2010
Monday, September 13, 2010
Sunday, September 12, 2010
Saturday, September 11, 2010
Friday, September 10, 2010
Thursday, September 9, 2010
Monday, September 6, 2010
Wednesday, September 1, 2010
Tuesday, August 24, 2010
Wednesday, August 11, 2010
freejavaclass.com
http://www.freejavaclass.com/ provide a common area for interesting articles, blogs , tutorials and innovative development ideas related to Java technology and other technologies too.It's so easy to use, you'll see incredible results
Monday, June 21, 2010
How can check server is up or down using java
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");
}
}
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");
}
}
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.
Monday, May 31, 2010
Avantages of Object Oriented Programming Languages (OOPL)
I have updated in http://www.freejavaclass.com/
The Object Oriented Programming Languages directly represent the real life objects like Car, Jeep, Account,
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
enapsulation make it powerful. [Tip: remember pie which, stands for Polymorphism, Inheritance and
Encapsulation are the 3 pillars of OOPL]
You can determine all the keys in a Map in the following way
I have updated in www.freejavaclass.com
By getting a Set object from the Map and iterating through it
By getting a Set object from the Map and iterating through it
What is UNICODE?
I have updated in http://www.freejavaclass.com/
Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.
Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.
What is the difference between constructor and method?
I have updated in http://www.freejavaclass.com/
Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.
What is an Object and how do you allocate memory to it?
I have updated in http://www.freejavaclass.com/
Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.
What are native operating system threads?
I have updated in http://www.freejavaclass.com/
Native operating system threads are those provided by the computer operating system that plays host to a Java application, be it Windows, Mac or GNU/Linux. Operating system threads enable computers to run many programs simultaneously on the same central processing unit (CPU) without clashing over the use of system resources or spending lots of time running one program at the expense of another. Operating system thread management is usually optimised to specific microprocessor architecture and features so that it operates much faster than Java green thread processing.
Native operating system threads are those provided by the computer operating system that plays host to a Java application, be it Windows, Mac or GNU/Linux. Operating system threads enable computers to run many programs simultaneously on the same central processing unit (CPU) without clashing over the use of system resources or spending lots of time running one program at the expense of another. Operating system thread management is usually optimised to specific microprocessor architecture and features so that it operates much faster than Java green thread processing.
What is a green thread?
I have updated in http://www.freejavaclass.com/
A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads. There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.
A green thread refers to a mode of operation for the Java Virtual Machine (JVM) in which all code is executed in a single operating system thread. If the Java program has any concurrent threads, the JVM manages multi-threading internally rather than using other operating system threads. There is a significant processing overhead for the JVM to keep track of thread states and swap between them, so green thread mode has been deprecated and removed from more recent Java implementations. Current JVM implementations make more efficient use of native operating system threads.
What is a working thread?
I have updated in http://www.freejavaclass.com/
A working thread, more commonly known as a worker thread is the key part of a design pattern that allocates one thread to execute one task. When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute(Runnable). The runnable tasks are usually stored in a queue until a thread host is available to run them. The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.
A working thread, more commonly known as a worker thread is the key part of a design pattern that allocates one thread to execute one task. When the task is complete, the thread may return to a thread pool for later use. In this scheme a thread may execute arbitrary tasks, which are passed in the form of a Runnable method argument, typically execute(Runnable). The runnable tasks are usually stored in a queue until a thread host is available to run them. The worker thread design pattern is usually used to handle many concurrent tasks where it is not important which finishes first and no single task needs to be coordinated with another. The task queue controls how many threads run concurrently to improve the overall performance of the system. However, a worker thread framework requires relatively complex programming to set up, so should not be used where simpler threading techniques can achieve similar results.
Sunday, May 30, 2010
What are “static initializers” or “static blocks with no function names”?
I have updated in http://www.freejavaclass.com/
When a class is loaded, all blocks that are declared static and don’t have function name (i.e. static initializers) are executed even before the constructors are executed. As the name suggests they are typically used to initialize static fields.
When a class is loaded, all blocks that are declared static and don’t have function name (i.e. static initializers) are executed even before the constructors are executed. As the name suggests they are typically used to initialize static fields.
public class StaticInitilaizer {
public static final int A = 5;
public static final int B;
//Static initializer block, which is executed only once when the class is loaded.
static {
if(A == 5)
B = 10;
else
B = 5;
}
public StaticInitilaizer(){} // constructor is called only after static initializer block
}
The following code gives an Output of A=5, B=10.
public class Test {
System.out.println("A =" + StaticInitilaizer.A + ", B =" + StaticInitilaizer.B);
}
Explain Java class loaders? Explain dynamic class loading?
I have updated in http://freejavaclass.com/articles/java/java_class_loaders.jsp
Class loaders are hierarchical. Classes are introduced into the JVM as they are referenced by name in a class that is already running in the JVM. So how is the very first class loaded? The very first class is specially loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running. A class loader creates a namespace. All JVMs include at least one class loader that is embedded within the JVM called the primordial (or bootstrap) class loader. Now let’s look at non-primordial class loaders. The JVM has hooks in it to allow user defined class loaders to be used in place of primordial class loader. Let us look at the class loaders created by the JVM.
Class loaders are hierarchical. Classes are introduced into the JVM as they are referenced by name in a class that is already running in the JVM. So how is the very first class loaded? The very first class is specially loaded with the help of static main() method declared in your class. All the subsequently loaded classes are loaded by the classes, which are already loaded and running. A class loader creates a namespace. All JVMs include at least one class loader that is embedded within the JVM called the primordial (or bootstrap) class loader. Now let’s look at non-primordial class loaders. The JVM has hooks in it to allow user defined class loaders to be used in place of primordial class loader. Let us look at the class loaders created by the JVM.
Class loaders are hierarchical and use a delegation model when loading a class. Class loaders request their
parent to load the class first before attempting to load it themselves. When a class loader loads a class, the child class loaders in the hierarchy will never reload the class again. Hence uniqueness is maintained. Classes loaded by a child class loader have visibility into classes loaded by its parents up the hierarchy but the reverse is not true as explained in the above diagram.
Important: Two objects loaded by different class loaders are never equal even if they carry the same values, which mean a class is uniquely identified in the context of the associated class loader. This applies to singletons too, where each class loader will have its own singleton.
What is the difference between C++ and Java?
I have updated in http://www.freejavaclass.com/- Java does not support pointers. Pointers are inherently tricky to use and troublesome.
Java does not support multiple inheritances because it causes more problems than it solves. Instead Java supports multiple interface inheritance, which allows an object to inherit many method signatures from different interfaces with the condition that the inheriting object must implement those inherited methods. The multiple interface inheritance also allows an object to behave polymorphically on those methods.
Java does not support destructors but rather adds a finalize() method. Finalize methods are invoked by the garbage collector prior to reclaiming the memory occupied by the object, which has the finalize() method. This means you do not know when the objects are going to be finalized. Avoid using finalize() method to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these resources through the finalize() method.
Java does not include structures or unions because the traditional data structures are implemented as an object oriented framework (Java collection framework).
All the code in Java program is encapsulated within classes therefore Java does not have global variables or functions.
C++ requires explicit memory management, while Java includes automatic garbage collection.
What is the main difference between the Java platform and the other software platforms?
I have updated in http://www.freejavaclass.com/
Java platform is a software-only platform, which runs on top of other hardware-based platforms like UNIX, NT etc.
The Java platform has 2 components:
Java platform is a software-only platform, which runs on top of other hardware-based platforms like UNIX, NT etc.
The Java platform has 2 components:
- Java Virtual Machine (JVM) – ‘JVM’ is a software that can be ported onto various hardware platforms. Byte codes are the machine language of the JVM.
- Java Application Programming Interface (Java API)
Friday, May 28, 2010
Give a few reasons for using Java?
I have updated in http://www.freejavaclass.com/
Java is a fun language. Let’s look at some of the reasons:
Built-in support for multi-threading, socket communication, and memory management (automatic garbage
collection).
Object Oriented (OO).
Better portability than other languages across operating systems.
Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI. EJB etc)
and network protocols (HTTP, JRMP etc) with the help of extensive standardised APIs (Application Program
Interfaces).
Java is a fun language. Let’s look at some of the reasons:
Built-in support for multi-threading, socket communication, and memory management (automatic garbage
collection).
Object Oriented (OO).
Better portability than other languages across operating systems.
Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI. EJB etc)
and network protocols (HTTP, JRMP etc) with the help of extensive standardised APIs (Application Program
Interfaces).
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...