Skip to main content

Posts

Showing posts from August, 2011

How to see Android SDK logs?

In Android application can't use System.out.println(...);. Android have Log  to print some outputs while developing the application. This Log should be avoid in production. Log.v("TAG", "MSG") - Verbose Log.e("TAG", "MSG") - Error Log.d("TAG", "MSG") - Debug These logs can't be seen in eclipse or any other place. These logs can be viewed only adb shell. $adb shell # logcat

Android development environment on Windows

Before start installing SDK make  sure system have JDK 5 or later. Download Android SDK installer for windows and install from here  http://developer.android.com/sdk/index.html After installed run the android SDK and atleast one SDK platform example (2.3.3) Open eclipse and go to "Install New Software" Install ADT plugins from https : //dl-ssl.google.com/android/eclipse/ restart the eclipse In Eclipse, Open Window -> Preferences and select "Android" from left side Select the path of the Android SDK installed In Eclipse, Open Window -> Android SDK and AVD manager. From SDK manager, can install required android platforms, libraries and etc... That's All, we are good to start Android application development. This is best startup giude  http://developer.android.com/resources/tutorials/hello-world.html

Android development in Linux (Ubuntu)

Setting up Android development environment in Linux is very easy compare to windows. :( Before start make sure system have JDK5 or latest version of Java. JRE is not enough JDK needed. Install Android SDK. (just extract linux version SDK zip file to a folder) Install eclipse:  sudo apt-get install eclipse In Eclipse, Open  "Install New Software" add Ecplise ADT plugin  https : //dl-ssl.google.com/android/eclipse/ After installed ADT plugin, restart the eclipse. In Eclipse, Window -> Preferences, Select Android on left side. Choose the path of the Android SDK installed folder. Click OK. In Eclipse, Window -> Android SDK and AVD Manager Install the platforms, samples and compatibility library from there.  That's all we are good to start develop Android Applications..... This is best startup giude  http://developer.android.com/resources/tutorials/hello-world.html

PHP file upload permission in linux

Normally while upload a file and move that file into web folder, will throw a error.  Moving uploaded file will work fine in windows. PHP Warning:  move_uploaded_file(upload/<<filename>>): failed to open stream: Permission denied in /var/www/<<project>>/some.php on line 21, referer: http://localhost/project/some.php To solve above problem. change permission to 077 to that upload folder. user@system:/var/www/project$ chmod 077 upload/

Prevent SQL injection in PHP with MySQL

SQL injection is more vulnerable in web applications. When using PHP with MySQL avoiding SQL injection is very simple.  The below code is not safe. Because once can inject own sql command here. like " 1; delete from customer where customerid = '1' ;" will delete the customer from table. $customerId = $_GET["cid"]; $sql = "select * from customer where customerid = $customerId"; There is built-in function to prevent SQL Injection from MySQL library. Before passing the parameter to SQL, make the parameter as safe by calling this function like below. $customerId =  mysql_escape_string( $customerId); $sql = "select * from cutomer where cutomerid = $customerId";

Random Numbers with or without range and Random item from a array in JavaScript

Here is the way to get random integers in JavaScript return Math.floor(Math.random()*8) the above will return random number from 0  to 7 To get a random number within given range. return Math.floor(Math.random() * (to - from + 1) + from); this will return a random number given range from & to can get a random item from array like below functions: function getRandomFromTo(from, to){ return Math.floor(Math.random() * (to - from + 1) + from); } function getRandomItem(arr){ return arr[getRandomFromTo(0, arr.length - 1)]; }

Display PHP errors in browser

To see the PHP error normally we use  error_reporting(E_ALL). If display errors are not On in php.ini, we can't see the errors. Here are the steps to enable errors in ini file. display_errors = On display_startup_errors = On track_errors = On html_errors = On the above four properties should have value " On ".  Don't forget to off in the production mode.

Installing PHP, Apache2 with MySQL on windows

1. Install apache2 server 2. Install PHP5 from zip file not from windows installer. Download "Thread Safe" version Unzip the file Add the PHP unzipped directory to system's path (c:/php) (If using windows installer to install PHP, php5apache2_2.dll will not be available. so use ZIP archive to install PHP) Configure PHP with apache2 add the below end of #LoadModule lines LoadModule php5_module "c:/php/php5apache2_2.dll" AddHandler application/x-httpd-php .php # configure the path to php.ini PHPIniDir "c:/php" configure MySql Install MySql by windows installer edit "php.ini" file  to enable Mysql in PHP add the extextion path: extension_dir = "c:\php\ext" load mysql extensions: ;extension=php_mysql.dll ;extension=php_mysqli.dll remove ";" from above extension=php_mysql.dll extension=php_mysqli.dll restart/ start the apache2 server.

Findbugs maven plugin configuration

By using findbugs we can avoid some performance issues before deployment. To use findbugs in project, 2 plugins required. One for execute findbugs check on the code, another for print the report in console or generate html report. <project> ...... <build> <plugins> ....             <plugin>                 <groupId>org.codehaus.mojo</groupId>                 <artifactId>findbugs-maven-plugin</artifactId>                 <version>2.3.2</version>                 <inherited>true</inherited>                 <configuration> <!-- skip findbugs execution set value "true" -->                     <skip>false</skip>                     <effort>Max</effort>                     <threshold>Medium</threshold>                     <xmlOutput>true</xmlOutput>                 </configuration>                 <executions>                     <execu

setting up PMD with maven

PMD is very useful plugin to check the java code.  <project> ..........     <properties> ........... <!-- When running PMD check with JDK 1.5 or 1.6, we will get like this warning "Can't use annotations when running in JDK 1.4 mode!". We can't see any PMD validation errors. To resolve this issue have set target jdk property as below -->         <targetJdk>1.5</targetJdk>     </properties> ............     <build>         <plugins> .......... ...........             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-pmd-plugin</artifactId>                 <version>2.5</version>                 <inherited>true</inherited>                 <configuration> <!-- to skip PMD check set "true" -->                     <skip>fasle</skip> <!-- break the build when PMD found error, set

Integrate Checkstyle plugin with maven build

Checkstyle will make java code more readable & maintainable.             checkstyle-maven plugin configuration:          <build >         <plugins>                ..................           <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-checkstyle-plugin</artifactId>                 <version>2.5</version>                 <inherited>true</inherited>                 <configuration>                     <!--to skip checkstyle validation set value as "true" -->                     <skip>false</skip>                     <consoleOutput>true</consoleOutput>                     <logViolationsToConsole>true</logViolationsToConsole>                     <!--want to make build fail, when checkstyle found validation error. set value as "true".-->                     <failOnViolation>true<

Creation and applying of subversion patch in netbeans

Creation of Patch: Select the project on the projects  window Select  Team -> "Export Diff Patch" Select the folder and enter file name of patch and click on Ok Patch file will be opened in editor view. Creation of patch has done. Applying Patch: Select the project on the  projects  window Select Team -> Apply Diff Patch Select patch file Answer  "Yes"  in question dialog to confirm watching differences. We done applying new patch into project.

Running and debugging jetty maven plugin in Netbeans

Coding with Netbeans will make developer life simple. We don't need search for plugins and install different plugins from different places. Maven projects can opened as directly in Netbeans without any settings. Here is the way to run & debug using maven jetty plugin. We can't add Jetty server as servers in Netbeans. Run project: Right click on project and open the properties. click on "Actions" on left side. On right side there will be list of available actions.  To run jetty can be created a new action or override default "Run Project" Here I am overriding default one, Because I can run the project just by hitting "F6" key click on "Run Project" Enter the value "Execute Goals" as "jetty:run", If you want run as offline add "jetty:run -o" "Active Profiles" can be empty In "set Properties" field we can set like skip test. Here I am skipping test. Done, After setting y

unlock the static files while jetty is running on windows.

When running a java maven web application  in jetty on windows. All static files are locked and not able edit and save those files while jetty is running. This will eat developers time beacuse each and every change in javascript & css files, jetty have to re-started. Depends on application's dependencies that build will take more than 5minutes. Why jetty is locking the static files? Jetty buffers static content for webapps such as html files, css files, images etc and uses memory mapped files to do this if the NIO connectors are being used. The problem is that on Windows, memory mapping a file causes the file to be locked, so that the file cannot be updated or replaced. This means that effectively you have to stop Jetty in order to update a file Jetty provides a configuration switch in the  webdefault.xml  file for the  DefaultServlet  which enables or disables the use of memory mapped files. If you are running on Windows and are having file locking problems, you should

How to create google chrome app

Creating google chrome application is very as creating  a web application. Create web application using html, javascript & css. can run in apache server or as file system in browser and test. when application is ready, create file in root folder "manifest.json" with below content {   "name": "<<application name>>",   "description": "<<description.........>>",   "version": "1",   "app": {     "launch": {       "local_path": "<<index html file or the start page of your application>>"     }   },    "icons": {  "16": "icon16.png", "48": "icon48.png",         "128": "icon128.png" } } in local_path specify the index page or the first page of your web application. icons - are used as logos of your chrome app. 16 - will be used as favicon (16X16) 48 - used to show i

Java5 Autoboxing & Unboxing

As any Java programmer knows, you can't put an   int   (or other primitive value) into a collection. Collections can only hold object references, so you have to   box   primitive values into the appropriate wrapper class (which is   Integer   in the case of   int ). When you take the object out of the collection, you get the   Integer   that you put in; if you need an   int , you must   unbox   the   Integer   using the   intValue method. All of this boxing and unboxing is a pain, and clutters up your code. The autoboxing and unboxing feature automates the process, eliminating the pain and the clutter. http://download.oracle.com/javase/1.5.0/docs/guide/language/autoboxing.html

Secure Coding Guidelines for the Java Programming Language

http://www.oracle.com/technetwork/java/seccodeguide-139067.html Secure Coding Guidelines for the Java Programming Language, Version 3.0 Introduction 0 Fundamentals Guideline 0-1 Prefer to have obviously no flaws than no obvious flaws Guideline 0-2 Design APIs to avoid security concerns Guideline 0-3 Avoid duplication Guideline 0-4 Restrict privileges Guideline 0-5 Establish trust boundaries Guideline 0-6 Contain sensitive data Guideline 0-7 Particular data format and API issues Guideline 0-7a Avoid dynamic SQL Guideline 0-7b XML and HTML generation requires care Guideline 0-7c Restrict XML inclusion Guideline 0-7d Take care interpreting untrusted code 1 Accessibility and Extensibility Guideline 1-1 Limit the accessibility of classes,interfaces, methods, and fields Guideline 1-1a Limit the accessibility of packages Guideline 1-1b Isolate unrelated code Guideline 1-2 Limit the extensibility of classes and methods Guideline 1-3 Understand how a su