Pages

Wednesday, November 27, 2013

Turn off your oracle password expiration

In this I am going to explain to turn off oracle user expiration alert.

To turn off this alert, execute the below sql statements.

To alter the password expiry policy for a certain user profile in Oracle first check wich profile the user is in using:

select profile from DBA_USERS where username = <username>;

Then you can change the limit to never expire using:

alter profile <profile_name> limit password_life_time UNLIMITED;
EX: ALTER PROFILE "DEFAULT" LIMIT PASSWORD_LIFE_TIME UNLIMITED;

If you want to previously check the limit you may use:

select resource_name,limit from dba_profiles where profile='<profile_name>';

Happy learning :)

Thursday, October 31, 2013

Convert DOS/MAC files to Unix format

Recently I came across file conversion issue in UNIX system. I have written a shell script in windows (i.e. via eclipse) once I completed, copied to designation server and I tried to run the same file.

But, surprisingly I got bad descriptor errors. I don’t know what the error was.  Developed script was fine no issues with syntax and logics. Later when I looked the contents of the file; I found out some of the system specific characters are in same file.


To overcome this kind file conversion issue, there is a UNIX command called “dos2unix” which is converting your dos/mac written file into UNIX format by removing those system characters.

Detailed explanation of  "dos2unix" command given below;

dos2unix - DOS/MAC to UNIX text file format converter

SYNOPSYS
       dos2unix [options] [-c convmode] [-o file ...] [-n infile outfile ...]

       Options:

       [-hkqV] [--help] [--keepdate] [--quiet] [--version]

DESCRIPTION
       This manual page documents dos2unix, the program that converts plain text files in DOS/MAC format to UNIX format.

OPTIONS

       The following options are available:

       -h --help
              Print online help.

       -k --keepdate
              Keep the date stamp of output file same as input file.

       -q --quiet
              Quiet mode. Suppress all warning and messages.

       -V --version
              Prints version information.

       -c --convmode convmode
              Sets conversion mode. Where convmode is one of: ASCII, 7bit, ISO, Mac with ASCII being the default.  Simulates dos2unix under SunOS.

       -o --oldfile file ...
              Old file mode. Convert the file and write output to it. The program default to run in this mode. Wildcard names may be used.

       -n --newfile infile outfile ...
              New file mode. Convert the infile and write output to outfile. File names must be given in pairs and wildcard names should NOT be used or
              you WILL lost your files.

Example :

dos2unix filename.sh

Sunday, October 27, 2013

Several ways of creating SingletonClass

In "SingletonClass pattern"  post I have discussed about singleton pattern. In this article, I am going to explain, several ways of creating singleton class.

As we known singleton pattern widely used for creating a one and only instance for a class.

Here is the list of the ways we can create singleton class,


  • Static Blocks.
  • Eager initialization. 
  • Lazy initialization.
  • Enums.



  • Static blocks

                  The instance creation of the class during class loading itself and even the constructor of the class called. Like below we can create static singleton class.


  • Eager initialization. 
                 In Eager initialization is one of the best approach to create singleton class. The instance of an class are created much before it is actually required. So the class instance is required or not but this will be created.


  • Lazy initialization.
                In the above method, we have drawback  whether the instance required or not we are creating a single instance and keep in memory. Even if it is not used in the application we are creating it. To avoid this, we have to use Lazy initialization. we have to create a object when required like shown below.


In this above implementation is not suitable for multi threaded environment because two threads such as Thread1 and Thread2 possess the "Obj" value as "null". We have to make synchronized block the getinstance method for mutli threaded application using double check mechanism like below,



The above code is thread safe now. Even several thread access getInstance method the synchronized method blocks other threads, complete it one by one.

  
  • Enums.
                      In Enums implementation provides implict support for thread safety, one and only instance will  be guaranteed. Hence we don't need to write synchronized blocks like above Lazy implementation.

Here is the code,


Happy Learning :)

2. Design Pattern - Singleton Design Pattern


2.1 Introduction 

Singleton design pattern one of the mostly used and simplest pattern in java. This patterns provides the best way to create the objects.

This pattern comes under the creational pattern type.

"This pattern involves a single class which is responsible to creates own object while making sure that only single object get created. This class provides a way to access its only object which can be accessed directly without need to instantiate the object of the class."


2.2. Implementation

Here is the implementation diagram for singleton pattern.

Singleton class has three methods suchs as, getinstance(), sayHi() and clone. Getinstance method provides gives instance of the class to calling class. 

Let see the code,

SingletonClass.java


 SingletonMain.Java




Output:





Saturday, October 26, 2013

1. Design Patterns - Introduction

In this topic we are going to see about the introduction part of design patterns like purpose, importance and its benefits. So lets jump start.

What is design patterns and its purpose?
                         "Design patterns" one of the best practices which is commonly used  by object - oriented developers. It solves the problems of real world problems  and helps the developers to develop a easy reusable code components.

Benefits of  Design Patterns.

     Here is the list of Benefits

  1. Code readability: They do help you write more understandable code with better names for what you are trying to accomplish.
  2. Code maintainability: Allows your code to be maintained easier because it is more understandable.
  3. Communication: They help you communicate design goals among programmers.
  4. Intention: They show the intent of your code instantly to someone learning the code.
  5. Code re-use: They help you identify common solutions to common problems.
  6. Less code: They allow you to write less code because more of your code can derive common functionality from common base classes.
  7. Tested and sound solutions: Most of the design patterns are tested, proven and sound.


Types of Design Patterns



As illustrated in the above, the design patterns are categories into three types; such as

1. Creation Patterns

      These design patterns provides way to create objects while hiding the creation logic, rather than instantiating objects directly using new operator. This gives program more flexibility in deciding which objects need to be created for a given use case.

2. Structural Patterns
      
     These design patterns concern class and object composition. Concept of inheritance is used to compose interfaces and define ways to compose objects to obtain new functionalists.

3. Behavioral Patterns
     
     These design patterns are specifically concerned with communication between objects.

All these design pattern concepts are fall in these categories. In forthcoming post, I am going to explain each design patterns and its sole purpose. So keep watching this blog. I am going to update on this post.

Your comments are welcome.

Wednesday, October 23, 2013

The Reflection API

Uses of Reflection

Reflection is commonly used by programs which require the ability to examine or modify the runtime behavior of applications running in the Java virtual machine. This is a relatively advanced feature and should be used only by developers who have a strong grasp of the fundamentals of the language. With that caveat in mind, reflection is a powerful technique and can enable applications to perform operations which would otherwise be impossible.
Extensibility Features
An application may make use of external, user-defined classes by creating instances of extensibility objects using their fully-qualified names.
Class Browsers and Visual Development Environments
A class browser needs to be able to enumerate the members of classes. Visual development environments can benefit from making use of type information available in reflection to aid the developer in writing correct code.
Debuggers and Test Tools
Debuggers need to be able to examine private members on classes. Test harnesses can make use of reflection to systematically call a discoverable set APIs defined on a class, to insure a high level of code coverage in a test suite.

Drawbacks of Reflection

Reflection is powerful, but should not be used indiscriminately. If it is possible to perform an operation without using reflection, then it is preferable to avoid using it. The following concerns should be kept in mind when accessing code via reflection.
Performance Overhead
Because reflection involves types that are dynamically resolved, certain Java virtual machine optimizations can not be performed. Consequently, reflective operations have slower performance than their non-reflective counterparts, and should be avoided in sections of code which are called frequently in performance-sensitive applications.
Security Restrictions
Reflection requires a runtime permission which may not be present when running under a security manager. This is in an important consideration for code which has to run in a restricted security context, such as in an Applet.
Exposure of Internals
Since reflection allows code to perform operations that would be illegal in non-reflective code, such as accessing private fields and methods, the use of reflection can result in unexpected side-effects, which may render code dysfunctional and may destroy portability. Reflective code breaks abstractions and therefore may change behavior with upgrades of the platform.