Wednesday, 24 May 2017

UNIX Useful Commands

Files and Directories:

These commands allow you to create directories and handle files.
Command
Description
cat
Display File Contents
cd
Changes Directory to dirname
chgrp
change file group
chmod
Changing Permissions
cp
Copy source file into destination
file
Determine file type
find
Find files
grep
Search files for regular expressions.
head
Display first few lines of a file
ln
Create softlink on oldname
ls
Display information about file type.
mkdir
Create a new directory dirname
more
Display data in paginated form.
mv
Move (Rename) a oldname to newname.
pwd
Print current working directory.
rm
Remove (Delete) filename
rmdir
Delete an existing directory provided it is empty.
tail
Prints last few lines in a file.
touch
Update access and modification time of a file.

Manipulating data:

The contents of files can be compared and altered with the following commands.
Command
Description
awk
Pattern scanning and processing language
cmp
Compare the contents of two files
comm
Compare sorted data
cut
Cut out selected fields of each line of a file
diff
Differential file comparator
expand
Expand tabs to spaces
join
Join files on some common field
perl
Data manipulation language
sed
Stream text editor
sort
Sort file data
split
Split file into smaller files
tr
Translate characters
uniq
Report repeated lines in a file
wc
Count words, lines, and characters
vi
Opens vi text editor
vim
Opens vim text editor
fmt
Simple text formatter
spell
Check text for spelling error
ispell
Check text for spelling error
ispell
Check text for spelling error
emacs
GNU project Emacs
ex, edit
Line editor
emacs
GNU project Emacs
emacs
GNU project Emacs

Compressed Files:

Files may be compressed to save space. Compressed files can be created and examined:
Command
Description
compress
Compress files
gunzip
Uncompress gzipped files
gzip
GNU alternative compression method
uncompress
Uncompress files
unzip
List, test and extract compressed files in a ZIP archive
zcat
Cat a compressed file
zcmp
Compare compressed files
zdiff
Compare compressed files
zmore
File perusal filter for crt viewing of compressed text

Getting Information:

Various Unix manuals and documentation are available on-line. The following Shell commands give information:
Command
Description
apropos
Locate commands by keyword lookup
info
Displays command information pages online
man
Displays manual pages online
whatis
Search the whatis database for complete words.
yelp
GNOME help viewer

Network Communication:

These following commands are used to send and receive files from a local UNIX hosts to the remote host around the world.
Command
Description
ftp
File transfer program
rcp
Remote file copy
rlogin
Remote login to a UNIX host
rsh
Remote shell
tftp
Trivial file transfer program
telnet
Make terminal connection to another host
ssh
Secure shell terminal or command connection
scp
Secure shell remote file copy
sftp
secure shell file transfer program
Some of these commands may be restricted at your computer for security reasons.

Misc Commands:

These commands list or alter information about the system:
Command
Description
chfn
Change your finger information
chgrp
Change the group ownership of a file
chown
Change owner
date
Print the date
determin
Automatically find terminal type
du
Print amount of disk usage
echo
Echo arguments to the standard options
exit
Quit the system
finger
Print information about logged-in users
groupadd
Create a user group
groups
Show group memberships
homequota
Show quota and file usage
iostat
Report I/O statistics
kill
Send a signal to a process
last
Show last logins of users
logout
log off UNIX
lun
List user names or login ID
netstat
Show network status
passwd
Change user password
passwd
Change your login password
printenv
Display value of a shell variable
ps
Display the status of current processes
ps
Print process status statistics
quota -v
Display disk usage and limits
reset
Reset terminal mode
script
Keep script of terminal session
script
Save the output of a command or process
setenv
Set environment variables
stty
Set terminal options
time
Time a command
top
Display all system processes
tset
Set terminal mode
tty
Print current terminal name
umask
Show the permissions that are given to view files by default
uname
Display name of the current system
uptime
Get the system up time
useradd
Create a user account
users
Print names of logged in users
vmstat
Report virtual memory statistics
w
Show what logged in users are doing
who
List logged in users
Enjoy Learning.

Java program to create singleton class


Java Singleton design pattern is one of the design patterns that manages the instantiation of an object
This design pattern suggests that only one instance of a Singleton object is created by the JVM.
This pattern is useful when exactly one object is needed to coordinate actions across the system.

For example, you can use it to create a connection pool. It’s not good to create a new connection every time a program needs to write something to a database; instead, a connection
or a set of connections that are already a pool can be instantiated using the Singleton pattern.

Example Class that follows Singleton Pattern.

public class SingletonExample {  
   private static SingletonExample INSTANCE = new SingletonExample ();  
   //Marking default constructor private;  
   //to avoid direct instantiation.  
   private SingletonExample () {  
   }  
   //Get instance for class SingletonExample  
   public static SingletonExample getInstance() {  
    return INSTANCE;  
   }  
 }  

In above code snippet, we have declared a static object reference to SingletonExample class called INSTANCE and is returned every time getInstance() is called.

  • In in a multi-threaded environment ,sometimes when two or more threads enter the method getInstance() at the same time before Singleton instance is not created, will result into simultaneous creation of two objects.

Such problems can be avoided by defining getInstance() method synchronized.

public static synchronized SingletonExample getInstance() { }  


Enjoy Learning.

Important SDET(Software Development Engineer Testing) Interview Question

                  Important SDET(Software Development Engineer Testing) Interview Question

QA
  1. Explain life cycle of a bug
  2. What is regression testing? How is it different from functional testing?
  3. Difference between whitebox and black box testing
  4. What is A/B testing?
  5. What is smoke testing? Difference with Sanity testing?
  6. How can we perform credit card authorization testing?
  7. How do we test a multi channel application? Especially when the integration points are not in place with downstream systems?
  8. What is end to end testing?
  9. How can we test a webservice?
  10. How can we form a request in Jmeter, hit a service and read the response?
  11. Difference between unit, integration and QA testing
  12. What is included in a test plan?
  13. what is boundary analysis with an example
  14. What is negative testing? Create 5 negative  test cases for email validation
  15. What is backend testing?
  16. How do you perform XML validation?
  17. What are the basic elements you put down while reporting a bug?
  18. Create 5 test cases for placing an order in an ecommerce website using PayPal as payment type
  19. Write 5 P1 test cases for shopping cart on an ecom website.
  20. Write 5 P1 testcases for a user profile page on an ecom website.
  21. Write 5 P1 test cases for a Ship confirmation email sent from an ecom website to a customer
Mobile
  1. What are the different types of apps ?
  2. What is the difference between Native and Hybrid app
  3. How can app be installed on IOS devices?
  4. What are the app formats for IOS and Android
  5. What is the difference between Desktop and mobile testing
  6. How to install local IOS and Android builds to device
  7. Mention what are the common bugs found while mobile testing
  8. What is the approach to test different screen size
  9. What is the approach to test different device/OS version
DB (Exact queries are not needed in answers. A high level approach will do)
  1. In an EMPLOYEE table having EMPLOYEE ID and DEPT ID, find department with max employees
  2. CASE..WHEN..THEN statement in SQL
  3. Write a query to find salary of an employee using join between EMPLOYEE and SALARY tables
  4. Difference between innerjoin and outerjoin
  5. PL/SQL – high level
  6. Explain trigger and its difference between a PL/SQL
  7. Nosql vs RDBMS, with an example
  8. Is it possible to have primary key and foreign key in mongo db
  9. How to find data in a mongodb collection
  10. Find state with max stores in a STORES table (with the columns - store id, storename, city, state, zip)
  11. How to ensure that child records are deleted when parent with foreign key constraint is deleted
  12. Difference between truncating and deleting a table
  13. Query to find number of records in a table
  14. Possible to have more than one column as primary key?
  15. Difference between WHERE and HAVING clauses
  16. What is difference between count(1) and count(*).
  17. Find number of non-null records in a column
  18. Find number of null records in a column

UNIX (exact syntaxes are not required. Keywords would be enough)
  1. Unix commands for :
    1. changing directories
    2. listing files
    3. finding keywords in a file
    4. changing file permissions
    5. tailing
    6. Create a shell script to display a menu to a user
    7. Get current directory
    8. Find keyword in a file
    9. List files starting with the word Sears in a directory
    10. Find wordcount in a file
    11. Schedule a shell script to run every 30 seconds
    12. How to connect to a unix server from another unix server
    13. Difference between ftp and scp
    14. How to find a string from a set of files?
    15. How to find files which are modified 15 mins before?
    16. How to list all running processes in a server and stop it?
    17. Finding file names which start with the letter A in a directory
JAVA
  1. How to convert json to a hashmap
  2. Explain how to implement multi-threading
  3. Explain race condition and how to avoid it
  4. Diff between string, string buffer and string builder
  5. Difference between hashmap, hashtable, concurrent hashmap and treemap
  6. Possible to have duplicate key in a hashmap? Explain
  7. Execute a query and get the results of the query into a hashmap with column names as the keys and column values as the values
  8. Explain class casting
  9. Explain polymorphism and encapsulaiton
  10. Sort an arraylist
  11. Sort a map with integer as keys and string as values based on length of its values
  12. Difference between abstract class and interface
  13. Difference between final, finalize and finally
  14. What happens when a line of code in finally block has an exception?
  15. What is an iterator? Where can it be used?
  16. What is a Set? How is it different from arraylist?
  17. Mail contents of a file using java
  18. How is hashmap different from an array list?
  19. Difference between hashmap and treemap?
  20. How would you read a file and write to a new file?
  21. Explain try-catch logic?
  22. What is Finally block? You are executing a try block, with no exceptions. Will it go to finally?
  23. Why do we need getters and setters?
  24. How to iterate through a hashmap
  25. How to find common elements between 2 array lists

SELENIUM
  1. How to handle popups in selenium?
  2. What is Page Object Model (POM) & Page Factory in Selenium?
  3. What are the differenttypes of wait and when to use what?
  4. What are the operating systems and browsers supported by Selenium?
  5. What is the default port for Selenium and can it be customized?
  6. What is the use of Capabilities class?
  7. What is the difference between Remote Webdriver and Webdriver?
  8. How to use JavaScript with Selenium WebDriver using Java?
  9. What is the diffrence between assert and verify?
  10. What are the different types of locators in Selenium and which one is preferred?
PROBLEM SOLVING 
  1. Open file containing alphanumeric phone numbers, convert them to numbers ((eg: 1-800-GO-PIZZA to 18004674992)and write them to a different text file
  2. Find difference between two text files which have data similar in structure
  3. You have Order Items table and orders table. Orderitems table could have many records for an order. How to find the orders that have exactly 2 items in them? OrderId is the foreign key in orderitems table.
  4. Find duplicate numbers in a Textfile with 20000 six digit numbers. On finding duplicates, write them in another textfile with number of occurances.
  5. Find missing number from an array that is supposed to contain 1-100 numbers
MISC 
  1. Difference between RESTful service and SOAP service
  2. Schedule an executable jar to run every 30 seconds in a Windows server
  3. Using regular expession, find $ amount in a string which appears after the $ character
  4. What is continuous integration?
  5. Convert xml to json?

Important Java Interview Questions

                                                      Important Java Interview Questions


Java:
What is JVM ? Why is Java platform independent ?
What is the Difference between JDK and JRE ?
What are dynamic binding (run-time) and static binding (compile-time) ?
Can you override private or static method in Java ?
What is Autoboxing and Unboxing ?
What is the difference between an Interface and an Abstract class ?
What are pass by reference and pass by value ?
What is the difference between a synchronized method (coarse grained lock) and a synchronized block (fine grained lock) ?
Why Collection doesn’t extend Cloneable and Serializable interfaces ?
What is difference between fail-fast and fail-safe ?
What is the big-O notation?
What do System.gc() and Runtime.gc() methods do ?
What is difference amoung finally, final and finalize() ?
What is the difference between JDBC and JPA ?
Java Design Patterns:
What is design patterns ? Have you used any design pattern in your code ?
Can you name few design patterns used in standard JDK library?
Give an example where you prefer abstract class over interface ?
What is Singleton design pattern in Java ? Few issues and solutions in singleton (thread-safe)?
When to use Strategy Design Pattern in Java?
What is Observer design pattern in Java? When do you use Observer pattern in Java?
Difference between Strategy and State design Pattern in Java?
What is main benefit of using factory pattern ? Where do you use it?
What is MVC design pattern ? Give one example of MVC design pattern ?
What is Chain of Responsibility design pattern ?
What is Builder design pattern in Java? When do you use Builder pattern ?
What is Adapter design pattern ? Give examples of adapter design pattern in Java?
Difference between Decorator and Proxy pattern in Java?
Can you write code to implement producer consumer design pattern in Java?
Design a Vending Machine which can accept different coins, deliver different products?
Servlets/JSP:
What is different between web server and application server?
What is the difference between a Servlet and a JSP ?
What are the advantages of servlets over CGI?
What are servlets filters?
What is difference between ServletConfig and ServletContext?
How can we achieve transport layer security for our web application?
Are Servlets Thread Safe? How to achieve thread safety in servlets?
What are common tasks performed by Servlet Container?
What is the difference between Applet, Servlet and Scriptlet ?
What is the difference between session and cookie ?
Explain lifecycle of a JSP?
What is a sciptlet in JSP and what is its syntax?
What do the id and scope attribute mean in the action elements?
What is the difference between JspWriter and PrintWriter?
How is Session Management done in JSP?
What are the JSP implicit objects ?
How do you implement the auto refresh in JSP?
How to disable caching on back button of the browser?
In JSP page, how can we handle runtime exception?
What is the difference between ServletContext and PageContext?
Web Service:
What is the difference between SOAP (JAX-WS) and REST (JAX-RS) web services?
How would you decide what style of Web Service to use? SOAP or REST?
Which JAX-RS implementation did you use (Jersey, RESTEasy, Restlet, Spring)?
What is the difference between web service and API?
Differentiate between SOA (Service Oriented Architecture) versus WOA (Web Oriented Architecture)?
What tools do you use to test your Web Services?
What is the difference between SOA and a Web service?
Why not favor traditional style middle-ware such as RPC, CORBA, RMI and DCOM as opposed to Web services?
What are the types of information included in SOAP header?
How can you explain HTTP Binding in SOAP ?
As per JAX-RS recommentation, what and where will you use GET, POST, PUT, DELETE methods?
Spring:
What is Spring? What are benefits of Spring framework?
Which are the Spring framework modules?
What is Inversion of Control (IoC) and Dependency Injection?
What is the difference between BeanFactory and ApplicationContext?
In how many ways, you can configure Spring into our application?
Explain Spring Bean lifecycle?
What are different Spring Bean Scopes?
Difference between constructor injection and setter injection?
Name some of the design patterns used in Spring Framework?
What is bean auto wiring?
What are the JSR-250 Annotations? Explain them?
Explain AOP in terms of cross-cutting Concern, Join Point, Advice...?
What are differnt data access implementations (JDBC, JPA, Data)?
Explain @RequestMapping annotation?
AngularJS:
Explain Directives in Angular?
Do I need Jquery for Angular?
How is the data binding in Angular ?
What is “$rootScope” and how is it related with “$scope”?
Explain compile and link phase?
What is the difference between Factory and Service?
How to implement routing in Angular?
What are the different custom directive types in AngularJS?
How do we make HTTP get and post calls in Angular?
JavaScript:
Explain the differences between Java and JavaScript?
What are undeclared and undefined variables?
What is ‘this’ keyword in JavaScript?
Does JavaScript support automatic type conversion?
What is called Variable typing in Javascript?
Explain the difference between “==” and “===”?
What are the different types of errors in JavaScript?
What is the difference between .call() and .apply()?
How are JavaScript and ECMA Script related?
How do JavaScript timers work? What is a drawback of JavaScript timers?
JQuery:
Whether jQuery HTML work for both HTML and XML documents?
Difference between ID selector and class selector in jQuery?
What is $(document).ready() function? Why should you use it?
What is the difference between onload() and document.ready()?
How do you add an HTML element in DOM tree?
Difference between $(this) and this keyword in jQuery?
What is difference between detach() and remove() method in jQuery?
What is main advantage of loading jQuery library using CDN?
What is difference between jQuery.get() and jQuery.ajax() method?
What is method chaining in jQuery? what is benefit of using method chaining?
Which one is more efficient, document.getElementbyId( "myId") or $("#myId)?
What is jQuery connect?
How can we debug jQuery?
What is the use of jQuery.data() method?
Where jQuery code is getting executed?
Performance Tuning:
How would you improve performance of a Java application?
How do you tune database performance?
How would you refresh your cache?
How would you refresh your cache if your database is shared by more than one application?
How would you detect and minimize memory leaks in Java?
Why does the JVM crash with a core dump or a Dr.Watson error?
What is structure of Java Heap ? What is Perm Gen space in Heap ?
How do you identify minor and major garbage collection in Java?
What is difference between ParNew and DefNew Young Generation Garbage collector?
How do you find GC resulted due to calling System.gc()?
What is difference between Serial and Throughput Garbage collector?
When does an Object becomes eligible for Garbage collection in Java ?
What is finalize method in Java ? When does Garbage collector calls finalize method in Java ?
Can we force Garbage collector to run at any time ?
Does Garbage collection occur in permanent generation space in JVM?
How to you monitor garbage collection activities?
What are some indications that you need to increase the SHARED_POOL_SIZE parameter?
When looking at v$sysstat you see that sorts (disk) is high. Is this bad or good? If bad, how do you correct it?
When should you increase copy latches? What parameters control copy latches?

Enjoy Learning:)

Wednesday, 26 April 2017

Install Docker and Build Docker Image for Java Services


Overview
This page captures high level info to install docker and to build and deploy applications on docker

Steps

Install Docker

  1. Install docker 
    • For mac from the link https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac
    • For windows from the link https://docs.docker.com/docker-for-windows/install/
  2. Once Docker is installed, you can run some basic commands from the following link
    • https://docs.docker.com/docker-for-mac/
  3. Docker basics tutorial
    • https://docs.docker.com/engine/getstarted/
Build Docker Image for Java Web Services

There are multiple ways to build a docker image at multiple levels of integration. Following are the high level steps for building a docker image from war file.

  1. Create "Dockerfile" for guiding docker through the build process
    • Create a file with name "Dockerfile"
    • Add the webserver image to the Dockerfile, that you want to deploy your application as the base, as follows
      • FROM tomcat:7-jre8
    • Add maintainer name
      • MAINTAINER "your mailid"
    • Add copy command to the deploy path
      • ADD {warfile-name} /usr/local/tomcat/webapps/
    • Complete Dockerfile (sample)
      • #Pull base image
      • From tomcat:7-jre8
      • # Maintainer
      • MAINTAINER "dixitsatish34@gmail.com"
      • # Copy to images tomcat path
      • ADD ranking-service.war /usr/local/tomcat/webapps/
  2. Copy Dockerfile and war file to a directory
  3. Run the following command for Docker build
    • docker build -t {image-name} .
    • ex: docker build -t ranking-service .

Deploy & Run Docker Image

Use the following command to run the image build in previous step(with port bindings)

    • docker run --rm -it -p {port binding} {image-name}
    • ex: docker run --rm -it -p 8080:8080 ranking-service


References
https://docs.docker.com/docker-for-mac/install/

Enjoy Learning.

Wednesday, 19 April 2017

ERROR [io.undertow.request] (default task-2) UT005023: Async is not supported for this request, as not all filters or Servlets were marked as supporting async


While upgrading JBOSS to Wildfly, we may observer below Exception:

"ERROR [io.undertow.request] (default task-2) UT005023: Exception handling request 
to /Sample/eventchannel: java.lang.IllegalStateException:
 UT010026: Async is not supported for this request, as not all filters or Servlets were
 marked as supporting async"

In order to avoid this error,

Upgrade the Servelet Jar version above 3.0

<dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>javax.servlet-api</artifactId>
           <version>3.0.1</version>
           <scope>provided</scope>
       </dependency>


Enjoy Learning.

Upgrade JBOSS7 to Wildfly 8.1

Installations


Download Java 8 and Wildfly 8.2.0-Final on local machine

Standalone xml Changes

Location - (${JBOSS_HOME}\standalone\configuration)

Adding SSL configuration

1.       Add a new  security realm under <security-realms>
<security-realm name="SSLRealm">
                <server-identities>
                    <ssl>
                        <keystore path="${path_to_jks_file}/jboss.jks" relative-to="jboss.server.config.dir" keystore-password="changeit"/>
                    </ssl>
                </server-identities>
            </security-realm>
2.       Copy the jboss.jks inside jboss7 to ${JBOSS_HOME}\standalone\configuration
3.       Make a new entry for https listener within <server name="default-server"> , within <subsystem xmlns="urn:jboss:domain:undertow:1.2">
<https-listener name="default-ssl" socket-binding="https" security-realm="SSLRealm"/>

Adding Datasource

1.       Make a new entry for datasource within <datasources> for PV
<datasource jndi-name="java:/jdbc/datasources/pvMySQLDS" pool-name="pvMySQLDS" enabled="true">
                    <connection-url>jdbc:mysql://DB server name:3306/DB name</connection-url>
                    <driver>mysql</driver>
                    <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                    <pool>
                        <min-pool-size>10</min-pool-size>
                        <max-pool-size>400</max-pool-size>
                    </pool>
                    <security>
                        <user-name>DB_USER</user-name>
                        <password>DB_PWD</password>
                    </security>
                    <timeout>
                        <blocking-timeout-millis>5000</blocking-timeout-millis>
                    </timeout>
                </datasource>
2.       Add a new driver for MySQL within <drivers>
<driver name="mysql" module="com.mysql">
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>

Adding global modules

1.       Add global modules within <subsystem xmlns="urn:jboss:domain:ee:2.0">
<global-modules>
                <module name="config" slot="main"/>
                <module name="org.bouncycastle" slot="main"/>
                <module name="com.mysql" slot="main"/>
            </global-modules>
 Note:Put this change if required.

Copying dependent folders\jars


1.       Copy config folder into ${JBOSS_HOME}\modules\system\layers\base






2.       Copy mysql folder into ${JBOSS_HOME}\modules\system\layers\base\com.



Application changes


Open jboss-deployment-structure.xml and replace the existing with the following:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>

                <deployment>

                                <exclude-subsystems>
                                                <subsystem name="jaxrs" />
                                </exclude-subsystems>

                                <exclusions>
                                                <module name="javax.ws.rs.api" />
                                </exclusions>

                </deployment>
</jboss-deployment-structure>

Note: Put this change if required.


Enjoy Reading