Compression using mod_deflate in Apache
A compression filter optimizes the size of the content that you send from your web server to a user via the Internet. This will save lots of bandwidth and so the application will be a lot faster as the content will be transfered to browser pretty soon. This task can be performed by turning mod_deflate module on.
To set mod_deflate I added following block in httpd.conf, This file can be found in
1. Load deflate_module module. It might be commented in the beginning of the file. Uncomment if commented.
LoadModule deflate_module modules/mod_deflate.so
2. Set compression filter
<Location />
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# file-types indicated will not be compressed
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>
</Location>
3. Create a new log file to check compression results, it can be done by placing following code in httpd.conf. You need to make sure that mod_log_config is included in httpd.conf.
<IfModule mod_log_config.c>
<IfModule mod_deflate.c>
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
SetEnvIf Request_URI \.gif image-request
SetEnvIf Request_URI \.js image-request
SetEnvIf Request_URI \.css image-request
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/deflate.log deflate env=!image-request
</IfModule>
</IfModule>
I have verified compression with & without ssl mode and don’t find any problem.
How to Enable/Disable Input element in JQuery
To disable input elements (checkbox, radio button, text box, button etc) in jquery, you need to set disabled attribute.
// check box
$("#check_box_id").attr("disabled", "disabled");
// radio button
$("#radio_btn_id").attr("disabled", "disabled");
// Text box
$("#text_box_id").attr("disabled", "disabled");
// button
$("#btn_id").attr("disabled", "disabled");
To Enable the input elements (checkbox, radio button, text box, button etc) , we need to remove disabled attribute. This can be done in the following way.
// check box
$("#check_box_id").removeAttr("disabled");
// radio button
$("#radio_btn_id").removeAttr("disabled");
// Text box
$("#text_box_id").removeAttr("disabled");
// button
$("#btn_id").removeAttr("disabled");
What will be output of the following program?
public static void main(String[] args) {
String s1 = new String("Hello");
change(s1);
System.out.println(s1);
}
public static void change(String s1) {
s1 += " Guest";
}
The output of the program will be “Hello” only. ” Guest” won’t be appended to the original string.
This is due to immutable nature of string. In the change method, appending string to s1 won’t change previous string, rather it will create a new string which will be “Hello Guest” and will be pointing to some other memory location and not to the String location which is passed to the ‘change’ method.
What is the Test Development Cycle?
Test Development Cycle includes following:
Test Planning -> Test Strategy -> Test Case Creation -> Test Cases Validation -> Test Cases Execution
In the V-Model of Testing when System Tests are prepared?
In the V-Model of testing System Tests are prepared when business specifications are ready after requirements phase and before design phase.
Which one of the following is more efficient?
String str1 = "Hello " + "Guest"; // 1
String str2 = (new StringBuffer().append("Hello ")).append("Guest").toString(); //2
str1 is resolved at compile time, while str2 is resolved at runtime time with an extra StringBuffer and String. The version that can be resolved at compile time is more efficient. It avoids the overhead of creating a String and an extra StringBuffer, as well as avoiding the runtime cost of several method calls.
What are the different types of testing?
Following are some important types of software testing:-
1. Unit Testing
2. Integration Testing
3. System Testing
4. Acceptance Testing
5. Performance Testing
6. Regression Testing
7. Stress Testing
8. Smoke Testing
What could be the lifecycle of a bug in a bug tracking system?
The Lifecycle of a bug contains following:
1. New
2. Assigned
3. Resolved Fixed/Not-Reproducible/Function as Design
4. Verified/Reopened
5. Closed
differences between the == operator and the equals() method in Java
Equals method compare values of the receiver and sender object. It returns true if the values are same. While ‘==’ operator is a fundamental operator, it compares reference of the sender and receiver object. E.g.
String s1 = "Hello";
String s2 = "Hello";
String s3 = new String("Hello");
System.out.println(s1 == s2); // true
System.out.println(s1 == s3);// false
System.out.println(s1.equals(s2));// true
System.out.println(s1.equals(s3));// true
From the example, we can see that reference and value for s1 & s2 are same. At the same time s3 is a newly created instance which has same value as of s1 and s2 but reference is different.
String in Java?
Strings are immutable. A string can’t be altered once created. Applying a method on string won’t change string’s value; rather it will create a new string. String is also final, and so can’t be sub classed. When you assign one String variable to another, no copy is made. Even when you take a substring there is no new String created.
Creating String : String can be created by assigning string literals as shown below. The text between double quotes is a string literal. By assigning a string literal, you can avoid using the new keyword. In fact, this special shortcut syntax was designed to improve String performance. Each JVM only keeps one copy of each string literal. In the following code firstStr and secondStr points to same string reference. thirdStr creates a new String in String pool.
String firstStr = "I am a String Literal";
String secondStr = "I am a String Literal";
// Points to the same object as firstString
String thirdStr = new String("I am a String Literal");
// By using constructor, It will create a new Object in JVM
Note: You almost always want to initialize String references with literals to avoid creating unnecessary objects in the JVM. This can really add up if you are creating hundreds of identical Strings.