Skip to main content

Posts

Showing posts from 2013

Android : adding library project into your project

Let say you have a list view activity in a separate project and is defined as library and it's main activity is "com.ls.list.MyActivity" t he proper way is to add the activity in the main project manifest file <activity android:name="com.ls.list.MyActivity" /> then create intent as usual Intent intent =new Intent(this, MyActivity.class);     startActivity(intent); another way which does not need the manifest changes  inside the main project's activity just write this simple code     Intent intent = new Intent(android.content.Intent.ACTION_VIEW);     intent.setComponent(new ComponentName("com.ls.list","com.ls.list.MyActivity"));      startActivity(intent);

Android :download android sdk manually

1- make sure that eclipse and sdk are closed 2- download the platform from this link http://qdevarena.blogspot.com/2010/05/download-android-sdk-standalone-for.html  and extract it under sdk\platforms 3-download system image for example  this for android 4.2  jelly-bean API level 17 http://software.intel.com/en-us/articles/intel-eula-x86-android-4-2-jelly-bean-bin extract it under  sdk\system-images\android-17 4- start eclipse and start sdk 

Runing multiple mysql instances on one machine

Suppose you have two mysql instances  c:\mysq1 and c:\mysql2 1- create file c:\mysql1\my.cnf add the following lines [mysqld] datadir = C:/mysql1/data port = 3308     2- create file c:\mysql2\my.cnf add the following lines   [mysqld] datadir = C:/mysql2/data port = 3309    3-now run the first instance    cd c:\mysql1\bin mysqld --defaults-file=c:\mysql1\my.cnf     4-open another command and run the second instance     cd c:\mysql2\bin mysqld --defaults-file=c:\mysql2\my.cnf finsihed ;)

Java Start/Stop System process and also check if it is running or not

This  block of code detects if mysql  database process  is running or not String line; try {             Process proc = Runtime.getRuntime().exec("wmic.exe");             BufferedReader input = new BufferedReader(new InputStreamReader(proc.getInputStream()));             OutputStreamWriter oStream = new OutputStreamWriter(proc.getOutputStream());             oStream .write("process where name='mysqld.exe'");             oStream .flush();             oStream .close();             while ((line = input.readLine()) != null) {                 // Here detects if mysqld process is running             }             input.close();         } catch (IOException ioe) {             ioe.printStackTrace();         }   This block of code starts mysql service Process p = new ProcessBuilder("c:/mysql/bin/mysqld", "").start();   And  you may use  p.destroy(); if you want to Stop it 

GIF animation for windows 7

i have created a java program that plays animated images and you can also control the speed by pressing < for  slowing down  or by pressing > for speeding up the animation program attached link http://www.4shared.com/zip/IejwaSBd/GIF.html

understanding "synchronized , wait() and notify() "

// An incorrect implementation of a producer and consumer. class Q { int n; synchronized int get() { System.out.println("Got: " + n); return n; } synchronized void put(int n) { this.n = n; System.out.println("Put: " + n); } } class Producer implements Runnable { Q q; Producer(Q q) { this.q = q; new Thread(this, "Producer").start(); } public void run() { int i = 0; while(true) { q.put(i++); } } } class Consumer implements Runnable { Q q; Consumer(Q q) { this.q = q; new Thread(this, "Consumer").start(); } public void run() { while(true) { q.get(); } } } class PC { public static void main(String args[]) { Q q = new Q(); new Producer(q); new Consumer(q); System.out.println("Press Control-C to stop."); } } Although the put( ) and get( ) methods on Q are synchronized, nothing stops the producer from overrunning the consumer, nor will anything stop the consumer from consuming the same queue value twice. Thus, you get the e

Fast Download with progress indication facility using Java NIO

package test; import java.io.FileOutputStream; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.Date; public class DownloadProgressExample {     public static void main( String[] args ) {         new Downloader( "c:/header12.jpg", "http://www.daralshifa.com/images/mainheader/header12.jpg" );     }     private interface RBCWrapperDelegate {          // The RBCWrapperDelegate receives rbcProgressCallback() messages         // from the read loop.  It is passed the progress as a percentage         // if known, or -1.0 to indicate indeterminate progress.         //         // This callback hangs the read loop so a smart implementation will         // spend the least amount of time possible here before returning.         //         // One possible implementation is to push the progress message         // atomic

When to use "Transient" keyword

/** Transient used to mark a variable not to be serialized So if you are serializing an object and you don't want to serialize a partecular variable value inside it, Then you just make it as transient and it will not be serialized Below example explains this concept */ package javabeat.samples; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; class NameStore implements Serializable{ private String firstName; private transient String middleName; private String lastName; public NameStore (String fName, String mName, String lName){ this .firstName = fName; this .middleName = mName; this .lastName = lName; } public String toStr

GIF animation fixing zero delay issue

/*  * My GIF Viewer Version 1.0<br/>  * viewing animated Gif by either making it the default program <br/>  * to view it or by dragging the image into the program's frame.<br/>  * The animation can be controlled either you slow it down by pressing <  <br/>  * or speed it up by pressing >  *  */ package gif; import java.awt.Toolkit; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import mygifutil.MyGifUtil; import java.util.List; import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.sw