Tuesday, 26 November 2013

Why Java is preferred for Application programming?

Java is one of the best high level language.Application development is not only task of software engineers, they are supposed to build and structure products for clients that meet their expectations, provide the features they need and be supported by strong backup.


In earlier times, writing code for developing applications was, essentially, rocket science. There were very few people who could actually write programs that were useful and functional.
The concept of object-oriented languages changed that by allowing programming to be related and to map to real-world entities in terms of actors and actions. The object-oriented paradigm of software programming encompasses all the features of object-oriented languages. These include:

1.Polymorphism :- One general interface acts as a multiple class of actions. It is usually seen in the case of methods in Java.
2.Inheritance: Promotes code re-usability and building stronger subsystems on top of existing structures
3.Encapsulation: Binding the code and data together to keep it safe from outside interference and prevent information abuse
4.Abstraction: Intrinsic details are hidden with an interface-based layer for users. The removes the concern for deep diving into lower-level information pertaining to the system.

These features are more or less common to all the languages that follow or support the object-oriented model.

 However, the degree to which they conform to the above specifications is what sets them apart from their counterparts. The way they can be modulated and work in favor of both the developer and the end users is something that matters a lot.

Simple


  • Looks familiar to existing programmers: related to C and C++:
  • Omits many rarely used, poorly understood, confusing features of C++, like operator overloading, multiple inheritance, automatic coercions, etc.
  • Contains no goto statement, but break and continue
  • Has no header files and eliminated C preprocessor
  • Eliminates much redundancy (e.g. no structs, unions, or functions)
  • has no pointers
  • Added features to simplify:

  • Garbage collection, so the programmer won't have to worry about storage management, which leads to fewer bugs.
  • A rich predefined class library

  • Object-Oriented

    Java is an object-oriented language, which means that you focus on the data in your application and methahods tt manipulate that data, rather than thinking strictly in terms of procedures.
    In an object-oriented system, a class is a collection of data and methods that operate on that data. Taken together, the data and methods describe the state and behavior of an object. Classes are arranged in a hierarchy, so that a subclass can inherit behavior from its superclass.
    Java comes with an extensive set of classes, arranged in packages, that you can use in your programs.

    Distributed


  • It has a spring-like transparent RPC system
  • Now uses mostly tcp-ip based protocols like ftp & http
  • Java supports various levels of network connectivity through classes in the java.net package (e.g. the URL class allows a Java application to open and access remote objects on the internet).

    Interpreted

    The Java compiler generates byte-codes, rather than native machine code. To actually run a Java program, you use the Java interpreter to execute the compiled byte-codes. Java byte-codes provide an architecture-neutral object file format. The code is designed to transport programs efficiently to multiple platforms.

  • rapid turn-around development
  • Software author is protected, since binary byte streams are downloaded and not the source code

  • Robust

    Java has been designed for writing highly reliable or robust software:

  • language restrictions (e.g. no pointer arithmetic and real arrays) to make it impossible for applications to smash memory (e.g overwriting memory and corrupting data)
  • Java does automatic garbage collection, which prevents memory leaks
  • extensive compile-time checking so bugs can be found early; this is repeated at runtime for flexibilty and to check consistency

  • Secure

    Security is an important concern, since Java is meant to be used in networked environments. Without some assurance of security, you certainly wouldn't want to download an applet from a random site on the net and let it run on your computer. Java's memory allocation model is one of its main defenses against malicious code (e.g can't cast integers to pointers, so can't forge access). Furthermore:

  • access restrictions are enforced (public, private)
  • byte codes are verified, which copes with the threat of a hostile compiler

  • Architecture-Neutral


  • compiler generates bytecodes, which have nothing to do with a particular computer architecture
  • easy to interpret on any machine

  • Portable

    Java goes further than just being architecture-neutral:

  • no "implementation dependent" notes in the spec (arithmetic and evaluation order)
  • standard libraries hide system differences
  • the Java environment itself is also portable: the portability boundary is POSIX compliant

  • High-Performance

    Java is an interpreted language, so it will never be as fast as a compiled language as C or C++. In fact, it is about 20 times as slow as C. However, this speed is more than enough to run interactive, GUI and network-based applications, where the application is often idle, waiting for the user to do something, or waiting for data from the network.

    Multi threaded

    Java allows multiple concurrent threads of execution to be active at once. This means that you could be listening to an audio clip while scrolling the page and in the background downloading an image. Java contains sophisticated synchronization primitives (monitors and condition variables), that are integrated into the language to make them easy to use and robust. The java.lang package provides a Thread class that supports methods to start, run, and stop a thread, and check on its status.

    Dynamic

    Java was designed to adapt to an evolving environment:

  • Even after binaries have been released, they can adapt to a changing environment
  • Java loads in classes as they are needed, even from across the network
  • It defers many decisions (like object layout) to runtime, which solves many of the version problems that C++ has



  • Dynamic linking is the only kind there is


  • Wednesday, 13 November 2013

    Setup Eclipse With Phonegap or Cordova-2.7.0

    This post describes  how to setup your development environment for Cordova and run a simple application.


    Requirements
    Eclipse 3.4+

    Install SDK + Cordova
    Download and install Eclipse Classic
    Download and install Android SDK
    Download and install ADT Plugin
    Download the latest copy of [PhoneGap and extract its contents. We will be working with the Android directory.


    Setup New Project
                                                  Launch Eclipse, and select menu item New > Android Project. Fill out the three panels of the New Android Project wizard shown below.


    1.Enter Application Name and click Next
    .



    2.Now don't change anything just click Next again.




    3. In this window you will see Configure launcher icon , Here you can set your icon for application.After selecting icon,Click Next. 






    4.Now again click Next



    5.click Next

    6. Now you can see your project structure given below.

     

    And the magic of cordova will start now .See the below steps for integrate cordova with android app.


    In the root direct
    ory of your project, create two new directories:
    /libs
    assets/www 

    Note :- If libs and assets are already there then only create www subfolder in assets.

    Copy
    cordova-2.7.0.js from your Cordova download earlier to assets/www
    Copy cordova-2.7.0.jar from your Cordova download earlier to /libs
    Copy xml folder from your Cordova download earlier to /res

    * Verify that cordova-2.7.0.jar is listed in the Build Path for your project. Right click on the /libs folder and go to Build Paths/ > Configure Build Path.... Then, in the Libraries tab, add cordova-2.7.0.jar to the project. If Eclipse is being temperamental, you might need to refresh (F5) the project once again.
    ***Note:- You can find xml folder in phonegap-2.9.1\lib\android\example\res when you will extract
    phonegap-2.9.1 zip, In this folder you will get a config.xml.









    • Now if cordova-x.x.x is not added in Libraries then Click-> Add Jars.. and select cordova-x.x.x jar from libs.
      Edit your project's main Java file found in the src folder in Eclipse:
      Add import org.apache.cordova.*;
      Change the class's extend from Activity to DroidGap
      Replace the setContentView() line with super.loadUrl("file:///android_asset/www/index.html");








      Right click on AndroidManifest.xml and select Open With > XML Editor
      Paste the following permissions between the <uses-sdk.../> and <application.../> tags.

      <supports-screens
      android:largeScreens="true"
      android:normalScreens="true"
      android:smallScreens="true"
      android:resizeable="true"
      android:anyDensity="true" />
      <uses-permission android:name="android.permission.VIBRATE" />
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
      <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
      <uses-permission android:name="android.permission.READ_PHONE_STATE" />
      <uses-permission android:name="android.permission.INTERNET" />
      <uses-permission android:name="android.permission.RECEIVE_SMS" />
      <uses-permission android:name="android.permission.RECORD_AUDIO" />
      <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
      <uses-permission android:name="android.permission.READ_CONTACTS" />
      <uses-permission android:name="android.permission.WRITE_CONTACTS" />
      <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
      <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
      <uses-permission android:name="android.permission.GET_ACCOUNTS" />
      <uses-permission android:name="android.permission.BROADCAST_STICKY" />







    • Now  Support orientation changes by pasting the following inside the <activity> tag. 
      • android:configChanges="orientation|keyboardHidden|screenSize"
             You can see the android-manifest.xml changed below..


    *Hello World

    Create a new file index.html in  assets/www folder with below code..

      <!DOCTYPE HTML>
      <html>
      <head>
      <title>JavaArc Hello Phone Gap</title>
      <script type="text/javascript" charset="utf-8" src="cordova-2.7.0.js"></script>
      </head>
      <body>
      <h1>Hello Phone Gap</h1>
      </body>
      </html>


     Deploy to Simulator
     Right click the project and go to Run As > Android Application
     Eclipse will ask you to select an appropriate AVD. If there isn't one, then you'll need to create it.

     Deploy to Device
     Make sure USB debugging is enabled on your device and plug it into your system. (Settings > Applications  > Development)
     Right click the project and go to Run As > Android Application
    Done!