Recent Posts

Responsive Ads Here

Wednesday 6 April 2016

Identifiers in Java ,General examples for identifiers in java

what is identifier



 Technical Description:- A name in a java program is called identifier. It can be class name or variable name or method name or label name. We can not  set or retrieve value without knowing identifiers.

Example :
                                  identifiers in programming


General Description:- suppose if you want to make a call to some one of your friend. So how can you make a call to them? either mobile or network ,for that we need identification of his/her number or social id.Then only we can able to talk with them ,so identity is very important and it always unique ,or else we will get ambiguity(Duplication).   

                          

Example : 

8123456789  : This is Number identity,by this identity we can make a call to them.

Nagendra : This is nagendra (of course in real time different people having same name ,but do not apply this scenario to Java identifier ,because in java we can protect our identifier (name) using private keyword )

Code : This is Number identity,country code ,each country having unique number (IND +91,USA +1 ,..etc)

India : This is name identity  
We can take so many general scenario as examples like Vehicles registration Numbers,Passport Numbers,Bank Account Numbers etc .


Rules to define Identifiers :
1. The only allowed characters in java identifiers are
A to Z
a to z
0 to 9
_(Under score)
$

Note:  If we are trying to use other character we will get compile time error

Example :

All_Number -->variable name is correct
all_number -->variable name is correct
#all   -->variable name is incorrect (because java does  not allow special characters as in variable name)
_$Z  -->variable name is correct

2. Identifier should not start with digit

 Example :

123Total variable name is incorrect
Total123 variable name is correct

3.Java Identifiers are case sensitive, which means Number is different with NUMBER

Class Test
{
int NUMBER=10;
int nUmber=20;
int NumBer=30;
System.out.println(“All are different ”);
}
  
In java we can differentiate identifiers with respect to case.CAT is different from cat,

4.There is no length limit for java identifier.But it is not recommended to take more than 15 length

5. Keywords cannot be used as identifiers
      
     Example :Do not use  int (its one of the keyword in java )as variable name

   6.All predefined java class names and interface names we can use as  identifiers.Even though its legal,but it is not recommended.We can use ,but not recommended

    Class Test
    {
    int String=10;
    System.out.println(String);
    }

   Output: 10

   Class Test
   {
   int Runnable=20;
   System.out.println(Runnable);
   }

  Output : 20


Saturday 2 April 2016

Features of java

top 10 features in java
                  

Features of a language are nothing but the services or facilities or functionalities provided by language to the industry programmers .

1.Simple
2.Platform Independent
3.Architecture Neutral
4.Portable
5.Multi threaded
6.Distributed
7.High performance
8.Robust
9.Secured
10.Dynamic
11.Object-oriented
12.Highly Interpreted


1.Simple :- After you know the key factors of java ,then you can say java is a simple programming language.So as of now we can see what is simple in java, and how can we say java is a simple.
“ Java is one of the simple programming language ,because of following factors.
    1. Java seems to be familiar to the existing programmers who are related to C & C++.
    2. Java omits many rarely used ,poorly understood, confusing features of C++,like operator  overloading ,multiple inheritance ,automatic coercions           etc.
    3. Java has no go to statement.
    4. Java eliminates much redundancy example No Structures, Union functions.
    5. Java has a Garbage Collector, so the programmer will have not to worry about storage management.
 6.Java has a rich predefined class library which means Application Programming Interface (API).”               
 7. Java Programming eliminates complex concept called pointers, so that application development time is less and application execution time is less, because of magic of byte code.

What is Byte code ?
byte code wiki
Internal Flow
                      
Byte code is set of optimized instructions generated by Java compiler during compilation phase and native of byte code is much powerful than ordinary pointer code of C,C++ languages.Do not think much about byte code now ,I covered full details about Byte code in JVM architecture.
Note:Java Programming is one of the compiler and interpreted based programming language .

What is an API ?
API stands for Application Programming Interface.An API is a collection of packages, a packages is a collection of predefined classes, interfaces and sub packages.A sub packages in turns contains classes, interfaces and sub packages etc.

Packages
Classes
Interfaces

2.Platform Independent :- 

what is platform independent ?
Platform view 

                Java code can be run on Multiple platforms like WINDOWS,LINUX,SUN SOLARIS ,MAC XOS etc.we developed and compile our program in WINDOWS.Then we can run our program in MAC.Because of java is a platform independent.which means WINDOWS is one kind of platform and LINUX is a one kind of platform and MAC XOS is one kind of platform.
                               So we can say write once and run anywhere.In order to say a language is platform independent it has to satisfy following properties.

1.the language related data types must take same amount of memory space on each and Every O.S
Example : In java int is one of the data type,in there we can store integer type of values and length of it is 4Bytes.
The point is, In WINDOWS or MAC XOS or any other platform must take 4 bytes for int data types.
2.The language must contains some special internal program & whose role is converting native understating form of one OS into native understanding form of another OS.
3. So finally by this factors we can say ,java is a platform independent.
Moto of Java is “WRITE ONCE RUN ANYWHERE”

3.Architectural Neutral :-A language /technology and whose related applications are said to be architectural neutral ,if they runs on every processor without considering their architectures and vendors.To say a language or technology is an architectural neutral ,it has to satisfy the following property.

1.The language /technology must contain some special programs and whose role is converting the factor /key of one processor to factor /key of another processor .

2.Easy to interpret on any machine .
  
4. Portable :-
An application runs on every OS and on every processor without considering their architectures and vendors.

1. Portability =Platform Independent + Architectural Neutral

2.Where as java language and whose applications are said to be portable
format of exe file in java
Format of exe file
                         
5.Multi threading :- Java allows multiple concurrent threads of execution to be active at once.This means that you could be listening to an audio while scrolling the page and in the background downloading an image.Java contains sophisticated synchronization primitives,that are integrated into the language to make them easy to use and robust.

The main advantage of multi threading is that .it shares the same memory.Threads are important for multimedia ,web application etc.when we write a java program there exists a two  types of threads.

1.Foreground Thread/Child Thread
2.Background Thread/Parent Thread
1.Foreground thread/Child thread: Foreground thread is one which always executing logic of a java program,which is written in the form of user defined methods.
2.Background Thread /Parent Thread : A background thread is one which monitor execution status of foreground thread.
3.The real time implementation of multi threading concept is that to develop real world server softwares such as Tomcat ,web logic etc.Most of the real world server softwares developed by third party server vendors in java language by using Multi Threading concepts. Multi Threading of java is one f the specialized form of multi tasking of operating systems.


6. Distributed :-
It has a spring like transparent RPC system
1.Now days use mostly TCP-IP based protocols like FTP&Http
2.ava supports various levels of network connectivity through classes in java.net package
Example The URL classes allows a java application to open and remote objects on the internet .

7. High Performace :- Java is an interpreted language ,so it will never be as fast as compiled languages like C,C++.In fact ,it is about 20 times 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 network.
However we can say java is one of the high performance programming language.
1.Byte code (It reduce useless execution time)
2.Memory Management (Garbage Collector Collects unused memory space for improving performance of java application)

8.Robust :- Java is one of the strong programming language ,because it contains following facilities .

1.Java has been designed for writing highly reliable and robust software .
2.Java does automatic garbage collection ,which means prevent memory wastage
3.Extensive compile time checking ,so bugs can be found early ,this is repeated at run time for flexibility and to check consistency .
4.Java has Exception Handling .The languages like C,C++,PASCAL,COBOL  etc  &  whose applications are treated as weak ,because these languages does not contain a facility called Exception Handling .

9.Secured :-
Security is an important concern,since java is mean to be used in networked environments.Java memory allocation model is one of its main defences against malicious code ,example cannot cast integers to pointers ,so can not forge access.

1.Access restrictions are enforced (Public ,Private)
2.Byte codes are verified ,which copes with the threat of a hostile compiler
3.Program run inside virtual Machine Sand Box
4.In Java we have a dedicated API (Library ) for dealing with security .i.e in java projects ,a java programmer need not write any security program on their own and they can use readily available security program present in the exisiting API
Javax.security.*

10. Dynamic :-

In any Programming language ,we have two types of memory allocation techniques,they are
1.Static Memory Allocation
2.Dynamic Memory Allocation

1.Static Memory Allocation:- In static memory allocation memory space is created /allocated for input of the program at compile time.
*Due to static memory allocation we get the following limitations
     1.Waste of memory space
     2.Loss of data
     3.Overlapping of Existing Data
*To avoid these problems industry is highly recommended to follow dynamic memory allocation.
2.Dynamic Memory Allocation :- In Dynamic memory allocation ,the memory space is allocated for input of the program at run time.Java programming follows only Dynamic Memory Allocation ,but not static memory allocations.
*Java was designed to adapt to an evolving environment
* Java loads classes as they are need ,even from across the network.
*It defers many decisions (like object layout ) to runtime ,which solves many of the version problems that C++ has .


11. Object –oriented :-
Java is an object –oriented language, which means that you focus on the data in your application and methods that 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 behaviour of an object. Classes are arranged in a hierarchy ,so that a subclass can inherit behaviour from its superclass comes with an extensive set of classes ,arranged in packages ,that you can use in your programs.

12.Highly Interpreted :- The java compiler generates byte code,rather than primitive machine code to run a java program.we use the java interpreter to execute the complied byte codes.Java byte cides provide an architecture neutral object file format.The code is designed to transport programs efficiently to multiple platforms. 
                   In the initial versions of java compilation phase is very faster and interpretation phase is very slow.In the later versions of java SUN developers has developed a Program called JIT(Just In Time Compiler) added as part of JVM and whose role is to speed up interpretation phase by reading the entire section of the byte code and converting into native understanding form of OS.



Tuesday 22 March 2016

Count days between two days through javascript

Count days between two days through javascript

In real time applications this scenario is very important for counting days between two selected days.Here I have taken Start Date and End Date for counting days between start date and end date.For that I have taken two input fields as type date with ids as “startDate” ,”endDate”.

General Scenario: Suppose in your application, you are going to create new program for that you must select start and end date and also print how many days between two selected days by automatically.

Why we give id to the input field?
Because find and read appropriate input values.Here I have taken startDate and endDate as ids to the Start Date  and End Date fields. Because in script I can read entered values in input field through this ids only.So ids are must be unique.

<!DOCTYPE html>
<html>
<body>
<h1>Count between two days through javascript</h1>
<h4>Select Start Date</h4>
<input type="date" id="startDate" onChange="onDateChange()"/>
<h4>Select End date </h4>
<input type="date" id="endDate" onChange="onDateChange()"/>
<p>Difference is :<p id="demo"> </p></p>
<script>
function onDateChange()
{
var sDate=new Date(document.getElementById("startDate").value);
var eDate=new Date(document.getElementById("endDate").value);
var timeDiff=Math.abs(eDate.getTime()-sDate.getTime());
var diffDays=Math.ceil(timeDiff/(1000*3600*24));
document.getElementById("demo").innerHTML = diffDays;
}
</script>
</body>
</html>

Process:

   1.Whenever  we select dates ,action goes to script with onDateChange() function
   2.Read startdate and endDate values
   3.Find time difference between two selected days
   4.Find days difference between two selected days 
  5.For print out put on page ,I have taken <p id="demo">  ,in script assign values I used document.getElementById("demo").innerHTML = diffDays;

Note : You can do same thing in jquery  also count days between two selected dates.
You  can watch videotutorial on this example. 

count days between two dates through Jquery

count days between two dates through Jquery


In real time applications this scenario is very important for counting days between two selected dates.
Here I have taken Start Date and End Date for counting days between start date and end date.For that I have taken two input fields as type date with ids as “startDate” ,”endDate”.

General Scenario : Suppose in your application, you are going to create new program for that you must select start and end date and also print how many days between two selected dates by automatically.
Why we give id to the input field?
Because find and read appropriate input values.Here I have taken startDate and endDate as ids to the Start Date  and End Date fields.Becacuse in script I can read entered values in input field through this ids only.So ids are must be unique.

<!DOCTYPE html>
<html>
<body>
<h1>Count between two days through JQuery</h1>
<h4>Select Start Date</h4>
<input type="date" class="date"  id="startDate"/>
<h4>Select End date </h4>
<input type="date" class="date"  id="endDate"/>
<p>Difference is :<p id="demo"> </p></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
$(function() {
$('.date').change(function() {
var sDate=new Date($("#startDate").val());
var eDate=new Date($("#endDate").val());
var timeDiff=Math.abs(eDate.getTime()-sDate.getTime());
var diffDays=Math.ceil(timeDiff/(1000*3600*24));
document.getElementById("demo").innerHTML = diffDays;
 });
});
</script>
</body>
</html>

Process :
      1.Whenever  we select dates ,action goes to script with change function
      2.  Read startdate and endDate values
      3.  Find time difference between two selected dates
      4. Find days difference between two selected dates
    5. For print out put on page ,I have taken <p id="demo"> ,in script assign values I used document.getElementById("demo").innerHTML = diffDays;

Note : You can do same thing in  javascript also count days between two selected dates
You  can watch video tutorial on this example.



Saturday 5 March 2016

What is Path and Class Path in java ?

To run and compile java programs, we need an Environment.JDK provide java environment through PATH and CLASS PATH either command-line (or) Environment variables. Command line for Temporary setting,environment variables for Permanent setting  paths.

PATH :- PATH is where all Java libraries ,supported jars like javac,javah ,java,javap ,etc .All tools are lies in JDK bin folder ,so we need to set path for run our program successfully.

suppose if you want to compile a java program ,we do like this.

C:\Program Files (x86)\Java\jdk1.8.0\bin>javac  Test.java

Javac.exe file checked  on (C:\Program Files (x86)\Java\jdk1.8.0\bin ) when we press enter for above program Test.java .So we happily compile our program ,because javac.exe file lies in bin folder of JDK.


What  will happen  ? if we are not set path and compile a program?
My intension is, compile above program.so for that i just set path like this
C:\ >set path=”C:\>Program Files (x86)>”;
C:\>javac Test.java
In Program Files (x86) there is no javac.exe file to compile our program,so we will get an error on command program “ javac is not recognized as an internal or external command




Class Path :- The location where required .class files are available  JVM or java compiler that specifies the location of user defined classes and packages.
When we executing java programs ,the JVM finds and loads classes.The class path tells jvm ,where to look in the file system for  defining there classes.
To run program ,we should pass our .class to JVM
The JVM searches and loads classes in this order through rt.jar
       1.Boostrap classes
       2.Extension classes
       3.User defined packages and libraries

         

Setting class path as temporary
C:\Program Files (x86)\Java\jdk1.8.0\bin> set ClASSPATH=”C:\Program Files (x86)\Java\jre8\lib\rt.jar>”;

C:\Program Files (x86)\Java\jdk1.8.0\bin>java Test 







How to Set Path and class path

There are two ways to set PATH and CLASS PATH in two ways
          
      1. Temporary (Command Line)
      2. Permanent (Environment Variables)

1.We can set Path and ClassPath through command line

Go to C Drive and find where JDK is installed and copy that Path and paste in command prompt



set path as temoprary
Set Path
  
Note : you will not get any message for setting PATH successfully

2.we can set CLASSPATH through command line






2.We can set PATH and Class Path as permanently

First Go to MyComputer Properties ->Advanced System Settings ->Environment Variables -> Click on New

                                     






                                            

Copy Path URL and Paste it in below



Copy Class Path URL and Paste it in below





done we successfully set path and class path as temporary and permanently. 





Watch video to set path and class path  for permanently

What is Java Run time Environment (JRE) ?

Technical Description:-The Java Runtime Environment is the part of JDK.JRE provides the minimum requirements for executing a Java Applications.JRE consists of the JVM (Java Virtual Machine), Core classes and supporting files.

Note: you can find JRE folder in Java Development Kit (JDK)

General Description: - Suppose if we want to play a cricket, first we need a play ground and also we need players. Just assume, our match is a java program, to run our program we need an environment. If we want to play a cricket we need a ground (JRE) and Supporting files (Players), without players we cannot play a cricket and also without ground (JRE), we cannot play a cricket both are interrelated.

enuretoday.blogspot.com


Play Ground is a JRE
Cricketers are supporting classes
Assume JVM is an empire

Where we use JRE in Java Programs?

To compile and run our java programs we have to set path and class path.We use JRE for set Class path to run our programs.