Tuesday, January 10, 2017

HTML Basics

HTML-Hyper Text Markup Language

Basically HTML is used for webpage designing.It has many attributes,tags etc. which helps in designing of web pages

Below Given is a basic HTML Structure
<head>
</head>
<body>
<h1>My First Webpage</h1>
<p>HTML</p>
</body>



headUsed for describing head of a web page
bodyUsed for describing body of a web page
h1Used for heading
(1 to 6 there are headings and these are in descending size)
pUsed for paragraph

You can create your own webpage using any editor say Notepad 
Just write the code in Notepad and save it using .html or .htm extension
Then open the file in any web browser to see what is output

Output:   

Factorial of a Number JAVA

Following Program Illustrates the method of calculating Factorial of a Number:

import java.util.Scanner;
public class JavaApplication1
{

public static void main(String[] args)
{
Scanner input=new Scanner(System.in);

   System.out.println("Enter Any Number to Calculate Factorial");

   int f=1, a=input.nextInt();

   for(int i=1;i<=a;i++)

   { f=f*i;  }

   System.out.println("Factorial is : "+f);

}


}

Output:


Wednesday, December 28, 2016

Installing Java :)

Setting up Java for the first time is a little tricky. Most people find difficulty in Installing Java on their PCs.
So here, I will show you how to Install Java on your Computer.

Basically, Java requires following things:
1. JDK (Java Development Kit)
2. Text Editor
3. IDE

1. JDK (Java Development Kit):
Java Development Kit is the most important software required for Java. No Java Program will run unless JDK is installed.

JDK can be downloaded from here .

Updating the PATH Environment Variable (Optional)

You can set the JDK  PATH environment variable, so that you can conveniently run the JDK  from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable file every time you run it.
It is useful to set the PATH variable permanently so it will persist after rebooting.
To set the PATH variable permanently, add the full path of the jdk1.8.0_111\bin directory to the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.8.0_111\bin. Set the PATH variable as follows on Microsoft Windows:
  1. Click Start, then Control Panel, then System.
  2. Click Advanced, then Environment Variables.
  3. Add the location of the bin folder of the JDK installation for the PATH variable in System Variables. The following is a typical value for the PATH variable
C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.8.0_111
\bin

This is the Default Location for JDK. If you have installed JDK at
some other place, then you have to put that location.










4. Restart the Computer.

2. Text Editor:
You can use any text editor like Notepad or Notepad++.

3. IDE:
There are various IDEs for Java available. It contains Text editor within itself.

NetBeans can be downloaded from here .
Eclipse can be downloaded from here .(Eclipse IDE for Java Developers)
You can download any one of them.






Data Types in Java

DATA TYPES IN JAVA :

Following are the 8 Basic Data Types in Java:

1. int - Integer
2. short - Short Integer
3. long - Long Integer
4. char - Character
5. float - Single Precision Floating point
6. double - Double Precision floating point
7. boolean - true/false
8. byte -  8-bit integer


Following Program Illustrates various data types -:

public class datatypes {
public static void main(String[] args) {

int num=1000000; //integer variable
short s=5000; //short variable
long l=900000000; //long variable
char c='c'; //char variable
float f =159.55f; //float variable ('f' keyword should be used for float)
double d=95735.561; //double variable
boolean b=true; //boolean variable

System.out.println("Value of num is " + num);
System.out.println("Value of s is " + s);
System.out.println("Value of l is " + l);
System.out.println("Value of c is " + c);
System.out.println("Value of f is " + f);
System.out.println("Value of d is " + d);
System.out.println("Value of b is " + b);
}
}





Note:-
1. The name of Source File should be exactly the same as the name of outer class.
2. In order to use float variable, keyword 'f' must be added at the end of its value.
3. '+' operator is used to combine output line and value.

Monday, December 26, 2016

Sum of Two Variables

In Java to accept input from user there are many libraries like Scanner,Textfields etc...

To use Scanner we have to import the Scanner into our program so we can do this by using
following statement

import java.util.Scanner;

now we can create object of Scanner type by using following statements

Scanner input=new Scanner(System.in);

thus we can accept data from user

Program :

import java.util.Scanner;
public class JavaApplication1 {

   public static void main(String []args)
   {
     float a;
     int b;
     Scanner input=new Scanner(System.in);
     System.out.println("Enter Two Values");
     a=input.nextFloat();        //for accepting float data
     b=input.nextInt();           //for accepting int data   
     float c=a+b;
     System.out.println("Sum is :"+c );
}

}

Output :



Saturday, December 24, 2016

Printing a Variable

In Java We Can Print The Value Of Variable by using a '+' symbol like as shown in following program 

Program :


public class JavaApplication1 {

    public static void main(String[] args) {
        int a=15;
        System.out.println("Value Is :"+a);
    }
}


Output:


Printing sum of two variables :


public class JavaApplication1 {

    public static void main(String[] args) {
        int a=15,b=10;
        System.out.println("Sum Is :"+(a+b));
    }
}

Output:



JAVA BASICS Hello World

Java is a high-level programming language originally developed by Sun Microsystems
which was initiated by James Gosling  and released in 1995.

Java Basic Program Hello World :


public class JavaApplication1
 {

    public static void main(String[] args)   //main function
    {
        System.out.println("Hello World");  //for output
    }
    

 }


Output:




Points To Remember:
1. Java is case sensitive so be careful about upper case and lower case alphabets.
2. While using Netbeans the name of class must be same as project name and using Notepad the name of file must be same as the class name with .java extension.
3.Rules for identifiers must be followed.