Programming Tutorials
ProgrammingBulls is created to help programmers (web or otherwise) how to program in HTML, CSS, PHP, Perl. Please find the following tutorials for your reference:
List of Latest Tutorials
Java: Sorting Integer Arraylist using Collections.sort
Step 1: Define the Comparator that compares integer values.
import java.util.Comparator;
public class MyIntComparable implements Comparator<Integer>{
@Override
public int compare(Integer o1, Integer o2) {
return (o1>o2 ? -1 : (o1==o2 ? 0 : 1));
}
}
Step 2: Call the Comparator in Collections.Sort.
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Simple2 {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(5);
list.add(4);
list.add(3);
Java: String to Integer
You can convert a String to integer using parseInt() method of Integer wrapper class or using valueOf() and intValue() methods together as follows.
str = "25";
int i = Integer.valueOf(str).intValue();
or
int i = Integer.parseInt(str);
Java: Sort using Collections
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class MainClass {
public static void main(String args[]) throws Exception {
List list = Arrays.asList("a","c","b");
Collections.sort(list);
for (int i = 0, n = list.size(); i < n; i++) {
if (i != 0)
System.out.print(", ");
System.out.print(list.get(i));
}
System.out.println();
}
}
Java Convert String to Double
public class ConvertStringToDouble {
public static void main(String[] args) {
String aString = "78";
double aDouble = Double.parseDouble(aString);
System.out.println(aDouble);
}
}
How to install Java on CentOS?
Following are the steps on how to install java sdk on CentOS:
Remove any java package (free and open source implementation) previously (eventually) installed from the CentOS Linux as follows:
yum erase jre
Remove tomcat5 and all it’s related packages.
Find the related *).bin file (jdk-6u20-linux-i586-rpm.bin) from the main page of the Sun’s official download page.
After you have downloaded your bin file. Run it on linux shell as follows:
chmod +x jdk-6u20-linux-i586-rpm.bin
Configuring .htaccess for Performance
Caching is useful for files on web server that rarely change. Images and other static content can be cached to avoid re-requesting them on each page load and hence, performance can be improved.
In this tutorial you'll learn how to do file caching using Apache .htaccess file.
Enabling .htaccess on Ubuntu server
First step is to check that .htaccess is enabled on your linux server. If it is not, you can enable it here:
a2enmod headers
Example .htaccess for performance
Which of PHP, ASP or Java is best for Maintenance Ease, Scalability and Uptime?
Planning to build a large portal? There are many large sites today that are on Php. Some believe J2EE or ASP.Net deliver the required performance. What is the best technology to go for scalability and uptime?
My answer for scalability is that they all work great. Computers have become fast. It depends on who codes. Most of the technologies: php, asp.net, j2ee, perl, ruby all have large websites built with them.
How to install Mod_gzip on Linux Server
This is a quick tutorial on how to install mod_gzip on linux server.
cd /usr/local/src
wget http://easynews.dl.sourceforge.net/sourceforge/mod-gzip/mod_gzip-1.3.26.1a.tgz
tar zxvf mod_gzip-1.3.26.1a.tgz
cd mod_gzip-1.3.26.1a
You must now open Makefile in your favorite editor and change the first line to:
APXS?=/usr/sbin/apxs
Save it, and continue:
make
make build
make install
How to Remove unwanted tabs in Drupal 6
In Drupal 6, you can remove unwanted tabs by using following function in template.php:
<?phpfunction yourthemename_preprocess_page(&$vars) { // Remove undesired local task tabs. // This first example removes the Users tab from the Search page. yourthemename_removetab('Users', $vars);}?>
<?php// Remove undesired local task tabs.// Related to yourthemename_removetab() in yourthemename_preprocess_page().function yourthemename_removetab($label, &$vars) { $tabs = explode("\n", $vars['tabs']); $vars['tabs'] = '';?>
Fixing PHP Security Holes using PhpSecInfo
Lately, I have come across an amazing tool PHPSecinfo that allows us to fix PHP security holes by scanning and then recommending changes in php.ini.
PhpSecInfo is an equivalent to the phpinfo() function that reports security information about the PHP environment, and offers suggestions for improvement.
It does not do any kind of code auditing, but recommends loop in php configuration.