Friday, 9 May 2014

Date Format Conversion in Java


package com.javapages4all;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Rajeswararao (JavaPages4All)
 *
 */
public class DateFormatConversion {

public static void main(String[] args) {
Format format;
Date date = new Date();
System.out.println(date); // Sat May 10 00:31:18 IST 2014

format = new SimpleDateFormat("dd/MM/yy");
System.out.println(format.format(date)); // 10/05/14

format = new SimpleDateFormat("MM/dd/yy");
System.out.println(format.format(date)); // 05/10/14

format = new SimpleDateFormat("dd-MMM-yy");
System.out.println(format.format(date)); // 10-May-14

format = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss");
System.out.println(format.format(date)); // 2014.05.10.00.27.08

format = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z");
System.out.println(format.format(date)); // Sat, 10 May 2014 00:27:08 +0530

format = new SimpleDateFormat("EEEE, dd MMMM yyyy HH:mm:ss zzzz");
System.out.println(format.format(date)); //Saturday, 10 May 2014 00:27:08 India Standard Time
}
}

File Download from Web by using Java

package com.javapages4all;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;

/**
 *
 * @author Rajeswararao (JavaPages4All)
 *
 */
public class FileDownload {

public static void main(String args[]) throws IOException {
BufferedInputStream buffInputStream=null;
FileOutputStream fileOutputStream=null;
BufferedOutputStream buffOutputStream=null;

try {
buffInputStream= new BufferedInputStream(new URL("File Url").openStream());
fileOutputStream = new FileOutputStream("D://JavaPage4All.pdf");
buffOutputStream = new BufferedOutputStream(fileOutputStream,1024);
byte data[] = new byte[1024];
int length;
while ((length = buffInputStream.read(data)) > 0) {
buffOutputStream.write(data, 0, length);
}

} catch (Exception e) {
e.printStackTrace();
}finally{
if(buffOutputStream != null)
buffOutputStream.close();
if(fileOutputStream != null)
fileOutputStream.close();
if(buffInputStream != null)
buffInputStream.close();
}
}
}

Thursday, 1 May 2014

Why we are using XML Design for Android Apps?


  1. XML layout design is easy to understand as well keep application user interface separate from the application code.
  2. There are many devices in the market having different-different display sizes and Android provides an easier task to create UI for all using XML and keeping them separate.
  3. Also if you want to develop an multilingual application then XML is the best one.
  Bottom line:
       Only use the Java code for layout if you really need otherwise you have still best option XML.

Android Activity Creation with XML Design


import android.app.Activity;
import android.os.Bundle;

public class HelloAndroid extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

Android Activity Creation without XML Design


import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class HelloAndroid extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       TextView tv = new TextView(this);
       tv.setText("Hello, Android");
       setContentView(tv);
   }
}

How to Get Thunderbird Email Messages Into Outlook

  1. Open Thunder bird. Mail
  2. Select the messages you want to export to Outlook. How many you can export will depend on the size of each message and its attachments as well as the capability of your Internet connection and provider.                                                                                                                      
  3. After selecting the messages, right click and select "Forward as Attachments." A new mail message will open up with the email messages you selected as attachments. Enter the email address you are using with Outlook and press send.
  4. Open the email containing the email message attachments and move this active window down a bit on your screen so you can see your main inbox area in Outlook.                                
  5. Select All Attachments that contains ThunderBird mails as Attachments then Drag it into your Inbox or any Folder . Finally you got it. 

How to Delete All Lines Containing a Unwanted Words from Text File?


  1. Go to Search menu > Find... > Select "Mark" Tab. Enter Search Text in Find what Search Box or Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"
    ==> All Rows you want to keep got a Bookmark
  2. Go to Menu "Search - Bookmark - Remove Bookmarked lines"
    ==> All Bookmarked lines are deleted.

How to delete lines except lines which containing wanted word?


  1. Go to Search menu > Find... > Select "Mark" Tab. Enter a Text in Find what search box or Activate regular expressions. Search for ^<Path> (^ is for line start). Don't forget to check "Bookmark lines" and Press "Mark All"
    ==> All Rows you want to keep got a Bookmark
  2. Go to Menu "Search - Bookmark - Inverse Bookmark"
    ==> All Line you want to delete are bookmarked.
  3. Go to Menu "Search - Bookmark - Remove Bookmarked lines"
    ==> All Bookmarked lines are deleted.