Loading...
Wednesday 18 April 2018

Java Basic Programs in Urdu hindi





First Program in Java:
package myapp1;
public class MyApp1 {
    public static void main(String[] args) {
        System.out.println("Welcome
to Java ");   
    }
    }
package myapp1;   it
is a package
public class MyApp1:
Ø 
public is access modifier
keyword
Ø 
class is keyword used to
define a class.
Ø 
MyApp1 is the name of
class.
public static void main(String[] args) {    Your statements goes here   }
Ø 
public:  is access modifier keyword
Ø 
static: static is
keyword which is used to call any member of class without an object.
Ø  Void: no return type
Ø  Main(): main is the method, which is the starting point
of program, every java program must have main method, it is the entry point
from which java program starts execution.
Ø  String[] : string array : it indicates main can string
array arguments , args is the name of array.
Ø  {}: Delimiters, creates the block of main

println(): this is an output
method it produces output result , println() method is the member of printstream
class, and we use this method with the out object in System class.

Package: The collection of classes is called Package , it is the
container of classes.
Examples: java.lang, java.util,java.awt,
java.io,java.applet,java.net,java.math,java.text,java.security, javax.swing,
How to import/include a package?
Import statement is used to import any package.
import java.lang.Byte;
import java.lang.Boolean;
import java.util.Arrays;
import
java.util.Date;
import java.lang.*;
import java.util.*;

Note: java.lang
is default packages, and we don’t need to import it for using its
classes and methods.

Class:  It is blue print
for creating objects.
How to create our custom class:
We use class keyword for
creating our own custom classes.
class A
{
 Your code goes here
}













How to create custom method in class A:
    public static void hello()
    {
       
System.out.println("Hello method ");
    }



Complete Program:
package myapp1;
import java.lang.*;
import java.util.*;

class A
{
    public static void hello()
    {
       
System.out.println("Hello method ");
    }
}

public class MyApp1 {
    public static void
main(String[] args) {
       
System.out.println("Welcome to Java ");   
         A.hello();
    }
    }



Program#2:
package
javaapplication4;
import
java.util.*;

public class
JavaApplication4 {
    public static void main(String[] args) {
       
        System.out.println(new Date());
      
    }
   
}

Program#3:
package
javaapplication4;
public class
JavaApplication4 {
    public static void main(String[] args) {
        System.out.println(10+10);
        System.out.println(20-5);
        System.out.println(4*3);
        System.out.println(12/2);
        System.out.println(13%2);
 
    }
   
}


Program#4:
package
javaapplication4;
public class
JavaApplication4 {
    public static void main(String[] args) {
       
System.out.println("10+10=\t"+(10+10));
       
System.out.println("20-5=\t"+(20-5));
       
System.out.println("4*3=\t"+(4*3));
        System.out.println("12/2=\t"+(12/2));
       
System.out.println("13%2=\t"+(13%2));
      }
   }

0 Comments:

Post a Comment

 
TOP