Saturday, 16 July 2016

Java programming format

Date :16- july-2016
Mr. nagur babu

Java programming format:
To design java applications, java has provided the following format.

1.       Comment section:-
As per of application development , it is convention to provide description about  the application before starting application implementation including author name, objective, module details, project details, client details……….
To provide the above specified description, we have to use comment section. Where, we have to use comments.

There are 3 types of comments in java

1.       Single line comments :-
it able to allow the description with in a single line
syntax :-
//--description –

2.       Multi line comments :-
it able to allow the description with in more then one line
syntax :-
/*
----------
-----description ---
---------
*/

3.       Documentation comments :-
It able to allow the description in more then one page
Syntax :-
/*
__
*__
*____
___
$___
#----
*/

Not only * we can use $,#... deferent symbols inside  
In general document comments are utilized to prepare API kind of documentation for our applications, but it is not suggestible
Note:-
Gathering declarative information of the programming elements like variables, methods, constructors, classes….. in a single documents is called as API kind of documents.
To simplify API kind of documents java has provided a separate commend in the form of “javadoc”.
Note 1 :-
In java application, javadoc commend is able to provide the description in the form of html files.
Ex:-
File name: c:\abc\Employee.java

public class Employee
{
        public String eid;
        public String ename;
        public float esal;
        public String eaddr;
        public Employee(String eid, String ename, float esal, String eaddr)
        {

        }
        public Employee(String eid, String ename, float esal)
        {

        }
        public Employee(String eid, String ename)
        {

        }
        public Employee(String eid)
        {

        }


public void add(String eid, String ename, float esal, String eaddr)
        {

        }
        public void search(String eid)
        {

        }
        public void update(String eid, String ename, float esal, String eaddr)
        {

        }
        public void delete(String eid)
        {

        }
}

On commend prompt :-
C:\abc>javadoc Employee.java


--generating html files ----


Date :18- july-2016
Mr. nagur babu

Annotation :-
In java application, to provide meta data or description JDK5.0 has provided a new feature in the form of “Annotation”.
Q) in  java applications, to provide description we are able to use comments, but what is the required to          use annotations?   
Ans)-
In java application, if we provide description along with comments the lexical analysis phase will remove that comments and the provided description from java program while performing tokenization as part of compilation, comments and its metadata is not available up to class and up to runtime they are available up to .java files.
As per the requirement, we need to bring metadata up to .java file, up to .class file and up to runtime of the java applications, for this , we have to use “annotation”.
Q) To bring meta data at runtime, we have already XML documents, then what is the requirements to use “annotation”?  
Ans)-
In java application, to bring meta data at runtime if we use XML documents their we are able to get the following problems
1.       We must learn XMLM technology.
2.       Every time we have to check whether xml documents are lactated properly or not.
3.       Every time we have to check whether xml documents are well formed document or not.
4.       Every time we have to check whether we are using right parsing mechanisms or not to read data from XML documents.

To overcome all the above problems, we need a java alternative that is “annotation”.
Note :-
In java/J2EE applications, we are able to use annotations as replacements for XML documents.

Which technologies are using in XML based technologies and annotation based technologies
XML based technologies
Annotation based technologies
JDK 1.4
JDK 5.0
JDBC 3.0
JDBC 4.0
Servlet 2.5
Servlet 3.0
Structs 1.x
Structs 2.x
JSF 1.x
JSF 2.x
Spring 2.x
Spring 3.x
EJBs 2.x
EJBs 3.x


Date :19- july-2016
Mr. nagur babu

2.       Package section :-

Package is the collection of related classes and interfaces as a single unit.
Package is a folder contains .class files representing related classes and interfaces as a single unit.
In java applications, packages are able to provide the following advantages
1.       Modularity
2.       Abstraction
3.       Security
4.       Sharing 
5.       Reusability

There are two types of package in java applications.
1.       Predefined packages
2.       User defined packages

1.       Predefined packages:-
There packages are defined by java programming language and provided along with java software.
Ex:-
Java.awt
Java.io
Java.util
---------
---------
2.       User defined packages :-
These package are defined by the developers as per their requirements
To defined user defined packages we have to use the following
syntax

package package_Name;

To use the above package declaration statements. We have to use the following two conditions.

1.       Package declaration statements must be first statement in java file after the comment section.
2.       Package name must be unique, they must not be shared and they must not be duplicated.
Q) Is it possible to provide more then one package declaration statement with in a single java file ?
Ans)- No, it is not possible to provide more then one package declaration statement within a single java file, because package declaration statements must be first statement in java file. If we provide more then one package declaration statement in a single java file, where only one statement as first statements all the remaining statements are not first statements, but package declaration statements must be first statements.
To provide package names, java has provide a suppurate convention like to include our company domain name in reverse.
Ex:-
package com.jntusuperfastupdates.icici.transaction.deposit;
com.jntusuperfastupdates---àcompany doming name in reverse
icici ---------àclient name/project name
transaction -----àmodule name
deposit ----àsub module name

3.       Import section :-

The main intention of import statement is to make available classes and interface of a particular packages into presents java file
To import packages into the present java file we have to use the following
Syntax :-
1.       import package_Name.util.*;
----------------------------------------
it able to import all the classes and interfaces from the specified packages .
ex:-  import java.io.*;
         import java.util.*;
2.       import package_Name.Member_Name ;
-------------------------------------------------------
It able that to import only the specified class/interfaces from the specified package.
Ex:-
import java.io.BufferedReader;
import java.util.ArrayList;

NOTE:-
In java application, we are able to provide almost one package declaration statement in a single java file, but we are able to provide more then import statement in a single java file.
Q) Is it possible to use classes and interface of a particular package in the present java file with out importing the respective package ?
Ans)-  Yes, it is possible to use classes and interfaces of a particular package in the present java file with out importing the respective package, just by using fully qualified name of the classes and interfaces.
Note :-
Providing class name and interface name, along with package name is called as fully qualified name
Ex:-
import java.io.BufferedReader;
import java.util.ArrayList;
example :-
java programming  with import statements

import java.io.*;
----------
---------
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
--------
Java program without import statements
----------
---------
new java.io.BufferedReader br=new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
--------

4.       classes/ interfaces section:-

The main intention of classes and interfaces is to represent all real world  entities in the coding part.
Ex:-
Student, employee, customer, account, products….etc.

In java file, we are able to provide any number of classes and interfaces as per the application requirements.

Date :20- july-2016
Mr. nagur babu

5         .Main class section :-

Main class is a java class, it able to include main() method.
The main requirements to provide main() method java applications is,
1.       To manage application logic in java applications.
2.       To define starting point and ending point to the application execution.

Syntax :-

public static void main(String []args)
{
------
------
}
Note :-
Main() method is not predefined method, and it is not user defined method, it is a conversion method with fixed prototype and with user defined implementation.



No comments:

Post a Comment