Wednesday, October 26, 2016

When to use Jave Thread and Android's Asynchronous task in android developement

For long-running or CPU-intensive tasks, there are basically two ways to do this: Java threads, and Android's native AsyncTask.
Use AsyncTask for:
  1. Simple network operations which do not require downloading a lot of data
  2. Disk-bound tasks that might take more than a few milliseconds
Use Java threads for:
  1. Network operations which involve moderate to large amounts of data (either uploading or downloading)
  2. High-CPU tasks which need to be run in the background
  3. Any task where you want to control the CPU usage relative to the GUI thread
And there are lot of good resources over internet which may help you:
Activity,services(Return Sticky not sticky redeliver intent),fragment communication,shared preference,Thread,AsyncTask getContext and getApplicationContext, Parcelable and Serialize and more basic. 


From java oops(in detail ) abstract class and interface difference between hash map and hash table, hash set ,string,Exception handling,and some more basic

Sunday, October 23, 2016

About XMPP Chat server





XMPP is Extended Messaging and Presence Protocol. As the name suggests it is used for (instant)
messaging. It gives the presence of the other users. Whatsapp, Google chat etc use XMPP Protocol.
I have used Smack API for client side coding and Ejabberd as the server.
If you want to add some functionality in server, learn some erlang and write your hooks in
Ejabberd Server. Its easy! And you will get a lot of help online.
I have an extremely simple hook examples on : Writing your own ejabberd Module
I have to add a few details on the blog, but its good for a start.
XMPP is really fast. Read on ejabberd.yml too!


Key XMPP technologies:
  • Core — information about the core XMPP technologies for XML streaming
  • Jingle — SIP-compatible multimedia signalling for voice, video, file transfer, and other applications
  • Multi-User Chat — flexible, multi-party communication
  • PubSub — alerts and notifications for data syndication, rich presence, and more
  • BOSH — an HTTP binding for XMPP (and other) traffic

About XMPP Chat server





XMPP is Extended Messaging and Presence Protocol. As the name suggests it is used for (instant)
messaging. It gives the presence of the other users. Whatsapp, Google chat etc use XMPP Protocol.
I have used Smack API for client side coding and Ejabberd as the server.
If you want to add some functionality in server, learn some erlang and write your hooks in
Ejabberd Server. Its easy! And you will get a lot of help online.
I have an extremely simple hook examples on : Writing your own ejabberd Module
I have to add a few details on the blog, but its good for a start.
XMPP is really fast. Read on ejabberd.yml too!


Key XMPP technologies:
  • Core — information about the core XMPP technologies for XML streaming
  • Jingle — SIP-compatible multimedia signalling for voice, video, file transfer, and other applications
  • Multi-User Chat — flexible, multi-party communication
  • PubSub — alerts and notifications for data syndication, rich presence, and more
  • BOSH — an HTTP binding for XMPP (and other) traffic

Tuesday, October 18, 2016

Inheritance


  • Inheritance is one of the concept in object oriented programming language.
  • Inheritance allows the class to use the methods and properties from another class
  • The class which inherits the derived class is called sub-class and Base class is also called as
    Super-Class
  • A Super-Class can have any number of Sub-Classes but a Sub-Class can have only on Super class, This is because JAVA doesn't support the multiple inheritance

Monday, October 17, 2016

Constructors

Constructor is a block of code that allows you to create object of class.

Difference between Constructor and Methods

Constructor do not have abstract, final, static and synchronised access modifiers can have only public, private Where methods can have all of this

Constructor do not have any return types where as methods have return types

The purpose of the constructor is to create the object of class where is the purpose of the method
is to perform any task by executing block of code.


Types of constructor : 
  • Default constructor
  • No-argument constructor
  • Parasitised constructor  


Saturday, October 15, 2016

Types of errors occur in JAVA


  • System Errors
  • Syntax Errors
  • Semantic Errors.
  • RunTime Errors.


    System Errors : 

    This errors occurs in console.Before running the applications first system would checks the wether the system path is checked or program is installed.

    Sytntax Errors :

    This errors are actual errors which prevent the compilation of code.
    this errors are very similar to semantic errors. and It can be caused by typing something wrong.


    Semantic Errors :

    This errors are easy to spot. as code development tools while show the line number and word which is causing the error.


    Runtime Errors : 

    This are the errors detected during the execution of program.


    Null pointer
    Divided by Zero

Types of errors occur in JAVA


  • System Errors
  • Syntax Errors
  • Semantic Errors.
  • RunTime Errors.


    System Errors : 

    This errors occurs in console.Before running the applications first system would checks the wether the system path is checked or program is installed.

    Sytntax Errors :

    This errors are actual errors which prevent the compilation of code.
    this errors are very similar to semantic errors. and It can be caused by typing something wrong.


    Semantic Errors :

    This errors are easy to spot. as code development tools while show the line number and word which is causing the error.


    Runtime Errors : 

    This are the errors detected during the execution of program.


    Null pointer
    Divided by Zero

Abstract Classes and Abstract methods

Abstract Classes
A class that is declared using "abstract" keyword is known as abstract class.
It may or may not include abstract methods which is abstract class can have concrete methods
(Method which has implementation) along with abstract method(without implementation) followed by semicolon

An abstract class cannot be instantiated(An object cannot be created).



Abstract Methods:

Syntax :

public abstract void display();

  •  Abstract method must be in abstract class
  • Abstract method must be overridden
  • Declaration always ends with semicolon
  • Abstract methods do not have body or implementation


Example:

abstract class test1{

  public void display()
  {



  }
abstract public void display1();
 
}

Difference between Abstract class and Interface

In this post will discuss about difference between Abstract class and Interface


abstract Classes    Interfaces
1 abstract class can extend only one class or one abstract class at a time interface can extend any number of interfaces at a time
2 abstract  class  can extend from a class or from an abstract class interface can extend only from an interface
3 abstract  class  can  have  both  abstract and concrete methods interface can  have only abstract methods
4 A class can extend only one abstract class A class can implement any number of interfaces
5 In abstract class keyword ‘abstract’ is mandatory to declare a method as an abstract In an interface keyword ‘abstract’ is optional to declare a method as an abstract
6 abstract  class can have  protected , public and public abstract methods Interface can have only public abstract methods i.e. by default
7 abstract class can have  static, final  or static final  variable with any access specifier interface  can  have only static final (constant) variable i.e. by default

Monday, October 3, 2016

XMPP file transfer in Android app

To configure proper proxy add/change these 3 properties in Openfire:
  1. xmpp.proxy.enabled                – true
  2. xmpp.proxy.port                        – 7777
  3. xmpp.proxy.externalip            – [publicly accessible host or ip]

    After setting proxy enabled and port to 7777 you can use the library as

    asmack-jse-buddycloud.jar
Code to send file:
FileTransferManager manager = new FileTransferManager(connection);
OutgoingFileTransfer transfer = manager.createOutgoingFileTransfer("usre2@myHost/Smack");
File file = new File(filenameWithPath);
try {
   transfer.sendFile(file, "test_file");
} catch (XMPPException e) {
   e.printStackTrace();
}
while(!transfer.isDone()) {
   if(transfer.getStatus().equals(Status.error)) {
      System.out.println("ERROR!!! " + transfer.getError());
   } else if (transfer.getStatus().equals(Status.cancelled)
                    || transfer.getStatus().equals(Status.refused)) {
      System.out.println("Cancelled!!! " + transfer.getError());
   }
   try {
      Thread.sleep(1000L);
   } catch (InterruptedException e) {
      e.printStackTrace();
   }
}
if(transfer.getStatus().equals(Status.refused) || transfer.getStatus().equals(Status.error)
 || transfer.getStatus().equals(Status.cancelled)){
   System.out.println("refused cancelled error " + transfer.getError());
} else {
   System.out.println("Success");
}
Code to recieve file:
FileTransferManager manager = new FileTransferManager(connection);
manager.addFileTransferListener(new FileTransferListener() {
   public void fileTransferRequest(final FileTransferRequest request) {
      new Thread(){
         @Override
         public void run() {
            IncomingFileTransfer transfer = request.accept();
            File mf = Environment.getExternalStorageDirectory();
            File file = new File(mf.getAbsoluteFile()+"/DCIM/Camera/" + transfer.getFileName());
            try{
                transfer.recieveFile(file);
                while(!transfer.isDone()) {
                   try{
                      Thread.sleep(1000L);
                   }catch (Exception e) {
                      Log.e("", e.getMessage());
                   }
                   if(transfer.getStatus().equals(Status.error)) {
                      Log.e("ERROR!!! ", transfer.getError() + "");
                   }
                   if(transfer.getException() != null) {
                      transfer.getException().printStackTrace();
                   }
                }
             }catch (Exception e) {
                Log.e("", e.getMessage());
            }
         };
       }.start();
    }
 });
Also configure ProviderManager to properly decode/parse bytestreams and other required xmls:
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/bytestreams", new BytestreamsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#items", new DiscoverItemsProvider());
ProviderManager.getInstance().addIQProvider("query","http://jabber.org/protocol/disco#info", new DiscoverInfoProvider()); If you need more help you can mail me at maidaragi1919@gmail.com