Gadgets

Monday, 23 November 2015

Swapping two numbers using third variable

Swapping two numbers using third variable
public class Swapping {
    public static void main(String[] arg){
        int a=10,b=20,c;
        c=a;
        a=b;
        b=c;
        System.out.println("a value is : "+a+" b value is :"+b);
    }   
}
Output:

a value is : 20 b value is :10

Sunday, 22 November 2015

Enter the values through keyboard

Enter the values through keyboard: core java Programs
We have two ways to give input through keyboard
1.    Using BufferedReader class
2.    Using Scanner class
Using BufferedReader class
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Test {
               public static void main(String[] args)throws IOException
               {
                               BufferedReader br=new BufferedReader(new                                                                                    InputStreamReader(System.in));
                               System.out.println("Enter name");
                               String name=br.readLine();
                               System.out.println("Enter Id");
                               int id=Integer.parseInt(br.readLine());
                               System.out.println("Enter Salary");
                               double salary=Double.parseDouble(br.readLine());
                               System.out.println("Enter Section");
                               char section=(char)br.read();
                               System.out.println("Name : "+name+" Id : "+id);
                               System.out.println("Salary : "+salary+" Section : "+section);
               }
}

Output:-
D:\Java>javac Test.java
D:\Java>java Test
Enter name
Narendar
Enter Id
1214
Enter Salary
20000
Enter Section
A
Name : Narendar Id : 1214
Salary : 20000.0 Section : A


Using Scanner class
import java.io.IOException;
import java.util.Scanner;
public class Test {
               public static void main(String[] args)throws IOException 
               {
                               Scanner sc=new Scanner(System.in);
                               System.out.println("Enter name");
                               String name=sc.nextLine();
                               System.out.println("Enter Id");
                               int id=sc.nextInt();
                               System.out.println("Enter Salary");
                               double salary=sc.nextDouble();
                               System.out.println("Enter Section");
                               String section=sc.next();
                               System.out.println("Name : "+name+" Id : "+id);
                               System.out.println("Salary : "+salary+" Section : "+section);
 
               }
}
Output:-
D:\Java>javac Test.java
D:\Java>java Test
Enter name
Durga
Enter Id
1212
Enter Salary
20000
Enter Section
B
Name : Durga Id : 1212
Salary : 20000.0 Section : B
 


Thursday, 19 November 2015

Disabling the right click on web page

Disabling the right click on web page
We can secure our web page by using disable the right click option on web page, if we use this option users can’t copy the matter from our web page and they can’t copy images also.
This is one of the security option for our web page and it is a simple technique to avoid right click option.
 Here is the code for avoid right click option
<html>
<head>
<script>
document.onmousedown=disableclick;
function disableclick(event)
{
  if(event.button==2)
   {    
     return false;    
   }
}
</script>
        </head>
    <body oncontextmenu="return false">
               </body>

               </html>

Include one HTML file into other HTML file

Include one HTML file into other HTML file 
We have different ways to include one html file into other html page, using 
1.            <frame>
2.            <iframe>
3.            <java script>. we have different ways in java script.

if we use <frame> and <iframe> to include one html file into other html file, that web page shows border lines for each html file and it look like separate pages.  
Here is the simple way to include one html file into other html file by using javascript. 
Using <frame>: 
Here I taken 4 HTML files
header.html, body.html, footer.html
I included above three html files into home.html 
<html>
    <frameset rows="50px,150px,50px">
        <frame src="header.html"/>
        <frame src="body.html"/>
        <frame src="footer.html"/>
    </frameset>   
</html> 

Output for above example:
 Using javascript: 
Here I taken 3 html files: header.html, body.html, footer.html
I included header.html and footer.html files into body.html file.

       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
Above link is required 
Javascript code for include html file
        <script>
             $(function(){
        $("#headerContent").load("header.html");
        $("#footerContent").load("footer.html"); 
    });
        </script>
<div id="headerContent"></div>
<div id="footerContent"></div>
 Header.html 
<html>   
    <body>       
       <h1>Welcome to Hyderabad</h1>
        <h3> HOME | ABOUTUS | SERVICES | VISIT PLACES | CAREER | CONTACT </h3>       
    </body>
</html> 
 Footer.html 
<html>   
    <body>
              <h1>Thank you, visit  again</h1>       
    </body>
</html>  
Body.html
<html>
    <head>
       <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script>
             $(function(){
        $("#headerContent").load("header.html");
        $("#footerContent").load("footer.html"); 
    });
        </script>        
    </head>
    <body>
        <div id="headerContent"></div>        
        <h1>Tourist Places</h1>
        <p>1. Charminar</p>
        <p>2. Hussain sagar</p>
        <p>3. Birla mandir</p>
        <p>4. Ramoji film city</p>
        <p>5. Golconda fort</p>       
        <div id="footerContent"></div>
    </body>
</html>
Output for above example:


Saturday, 14 November 2015

set environment variables and first java program in detailed

set environment variables and first java program in detailed


1.    Set Permanent path:

Go to MyComputer properties à advanced tab à environment variables ànew tab of user variable à write path in variable name à write path of bin folder in variable value   Ã  ok à ok à ok.

1.    Right click on MyComputer and select Properties

2.    Click on Advanced system settings

3.    Click on Environment Variables

4.    Click on New in user variables

5.    Copy bin folder path

6.    Write “path” in variable name and past the path of bin folder.in variable value and click on “ok”.

7.    Click on “ok”

8.    Click on “ok”


1.   
Temporary path:

Copy the bin path and past it in command prompt as
“set path= C:\Program Files\Java\jdk1.6.0\bin”

Here I set temporary path for D driveàprograms folder because I save all my programs in that folder.

First java program in detailed:

public class Test
{
  public static void main(String[] arg)
    {
           System.out.println("This is my first java program");
     }
}

Open notepad and write the above program



I saved that program as “Test.java” in drive Dàprograms folder


Compile it “javac Test.java” and after compiled it, created a .class file


Run that .class file as “java Test” command


Explanation:

public class Test

public keyword is an access modifier, it mean other classes can access this class.
class is a keyword to declare the class name.
“Test” is a class name of this program.
{ open brace, it mean starting of the class scope.

public static void main(String[] arg)

static is a keyword. If we declare a method as static, no need to create object for that method. Here no need to create object to invoke main method. The main method is executed by JVM.
void is return type. It does not return any value.
“main” is a method name. It represents startup of the program.
(String[] arg) is main method parameter, it stores the  values as String array format  “arg” is a variable, we can give other name whatever we want(a[],b[],ect..).

Example:

String a=arg[0];
String b=arg[1];
{ open brace for main method.

System.out.println("This is my first java program");

System is a class in the java.lang package.
“out” is a static member of the System class
“println” is a method of the java.io.PrintStream
} close main method
} close class

Execution:


Save the above program as: “Test.java”
Compile:  javac “Test.java”
Execution:  java “Test.java”
Output:   This is my first java program 





History of java and uses,features

History of Java and Uses

Java is a programming language and a platform. Java divided into 3 types of categories.

Java SE (java standard edition):

it deals standalone applications.

Java EE (java enterprise edition):

it deals web applications.

Java ME (java micro edition/ mobile edition):

it deals mobile applications.

History of java:

1) Java was originally developed by James Gosling and Team (also called as Green Team) at Sun Microsystems (which has since been acquired by Oracle Corporation) and released
in 1995.

2) Firstly, it was called "Greentalk" by James Gosling and file extension was .gt after that, it was called Oak (Oak is a national tree of many countries like U.S.A., France).

3) Finally in 1995 Oak was renamed as Java.

4) Java is an island of Indonesia where first coffee was produced (called java coffee).


Uses of Java:

Types of Java Applications
There are mainly 4 types of applications that can be created using java:

1) Standalone Application / Desktop Application
     Standalone applications are install on systems, such as media player, antivirus etc. AWT        and Swing are used for creating standalone applications.

2) Web Application
     Web applications create dynamic pages and run on server side. Servlet, jsp, struts,                 Hibernate, spring are used for creating web applications.

3) Enterprise Application
     Enterprise applications are distributed in nature, such as banking applications etc. It has         high level security. EJB is used for creating enterprise applications.

4) Mobile Application
     Mobile applications are used to create for mobile devices. Android and Java ME are used      for creating mobile applications.

Versions of java:

·         JDK 1.0 (January 21, 1996)
·         JDK 1.1 (February 19, 1997)
·         J2SE 1.2 (December 8, 1998)
·         J2SE 1.3 (May 8, 2000)
·         J2SE 1.4 (February 6, 2002)
·         J2SE 5.0 (September 30, 2004)
·         Java SE 6 (December 11, 2006)
·         Java SE 7 (July 28, 2011)
·         Java SE 8 (March 18, 2014)

Download and Install java:


Check java installed or not:
Commands to check java installed or not in your system “java –version” and “java –version”

C:\Users\Narendar>java -version
C:\Users\Narendar>javac –version



Features of java:-


Simple:-
Java programming language is simple because java syntax is based on C, C++ and removed many confused features e.g. pointer, operator overloading etc. there is Automatic Garbage Collection in java.

Object oriented:-
Java is a purely object-oriented programming language. Java programs use objects & classes. We learn more about object and class in next chapter.

Platform independent:-
A platform is the hardware or software environment in which a program runs. There are two types of platforms software-based and hardware-based. Java provides software-based platform. Java runs on any hardware-based platform such as windows, Linux, etc.

Distributed:-
Information is distributed on various on a network. Using java, we can write programs which capture information & distribute it to clients.

Robust:-
Robust mean strong, java programs are strong. Java programs will not crash easily because of its execution handling and its memory management features because JVM is allotted the memory.

Portable:-
Java programs give same results on all machines. Everything is clearly defined in java specification

Architecture neutral:-
Java byte code is not machine dependent. It can be run any machine with any processor & with any operating system.

High Performance:-
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++).

Secured:-
Java is secured because No explicit pointer and Programs run inside virtual machine.

Multi-threaded:-
A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once.

Dynamic:-
We can develop programs in java which dynamically interact with the user on internet.