Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Sunday, December 1, 2019

Design Patterns

Singleton 
---------------
class App{
    private App(){}
    static App createInstance(){}
}


Factory
---------------
interface App{
    public void develop();
    public void test();
    public void debug();
    public void deliver();
}
public class IOSApp implements App{}
public class TVApp implements App{}
public class WatchApp implements App{}

class AppStoreFactory{
   public App createApp(AppType type) {
       App app;
       switch (type) {
       case IOS:
           app = new IOSApp();
           break;
       case TV:
           app = new TVApp();
           break;
       case GLASS:
           app = new GlassApp();
           break;
       default:
           app = new GlassApp();
           break;
       }
       return app;
   }
}

Composite
---------------
Compose objects into tree structures to represent part-whole hierarchies. Composite lets client treat individual objects and compositions of objects uniformly.

Employee
Manager implements Employee
VP extends Manager
SectionManager extends Manager
TeamLeader extends Manager
Developer implements Employee

Adapter
---------------
Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn’t otherwise because of incompatible interfaces.


Prototype
---------------
public abstract class App implements Cloneable {}
public class IOSApp extends App {}
public class WatchApp extends App {}


public class BasicAppCache {
     public void load() {}
     public App get(AppType type) {}
}

or

public class AdvancedAppCache {
    private App load(AppType type) {}
    public App get(AppType type) {}
}


public class AppFactory {
    BasicAppCache appCache;
    public App createApp(AppType type) {
        return this.appCache.get(type);
    }
}

public class AppStore {
    public static void main(String... args) {
        final App app = new AppFactory().createApp(AppType.WATCH));
    }
}


Proxy
--------------
Allows for object-level access control by acting as a pass-through entity or a placeholder object.

public interface Book {}
public class RealBook implements Book {}
public class ProxyBook implements Book {}
public class LibraryService {

}

Wednesday, February 17, 2016

Big Performance Mistake - Java Application Development.

1. The framework sample that you use, keep close eye on on following:

a. Every library included in project.
b. Every xml created that's load on runtime.
c. Every default code generate by tool

all above items will decrease a chances of bad performance for application.

Review a debug logs and try to resolve any unknown error and exception that caused but not disturbing application process but it might overloading JVM or database and other related applications / connections.

You might not able to feel any performance issue on development / test server because application is running with sample data / limit number of records and users.

2. Not every architect makes a good decisions:-

Custom measuring for example:-
a. Was impacted by garbage collection
                b. just measured overall time but not # SQL Exceptions

DON'T ASSUME you know what code does somebody else developed

3. Use performance test tools dynatrace, New Relic, AppDynamics, HP Load Runner.

4. Idenfity how many sql exection in your code also number of same sql statement executed in your code.
a. Optimize the sql statement or cache data
b Connection equitation time

5. Identify how many number of threads are created and utilized by application and number of call made to API's and time take by each in API.

6. Bad Deployments
a. Different framework / library version between development and production server.
b. Perform Unit Test, Functional Test, Performance Test before deployment

7. Push without a plan ( Idea was great but implementation wasn't correct)
a. Need to check number of images on each page that might cause application slowness.
b. Number of redirection and size of resources are used in each page.
c. Use diagnostics tools to make sure overloading won't happen.






Monday, February 15, 2016

Weblogic ServletContext.getRealPath() - NullPointerException

Setting weblogic Admin Console option

Domain | Web Application | Archived Real Path Enabled to

You can also apply fix in application level by adding the following entry to weblogic.xml file:

<container-descriptor>
    <show-archived-real-path-enabled>true</show-archived-real-path-enabled>
</container-descriptor>

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...