0% found this document useful (0 votes)
10 views5 pages

Class 11

Uploaded by

M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Class 11

Uploaded by

M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

ex:

----
class Test
{
public static void main(String[] args)
{
System.out.println("stmt1");

System.out.print("stmt2");

System.out.printf("stmt3");
}
}

Various ways to display the data in java


----------------------------------------
1)
System.out.println("Hello World");

2)
int i=10;
System.out.println(i);
System.out.println("The value is ="+i);

3)
int i=10,j=20;
System.out.println(i+" "+j);
System.out.println(i+" and "+j);

4) int i=1,j=2,k=3;
System.out.println(i+" "+j+" "+k);

Fully Qualified Name


====================
Fully qualified name means we need to declare a class or interface along with
package name.

It is used to increase the readability of our code.

ex:
---
class Test
{
public static void main(String[] args)
{
java.util.Date d =new java.util.Date();

System.out.println(d);
}
}

Import statements
=================
Whenever we use import statement we should not use fully qualified name.
Using shortname also we can achieve.

In java, we have three import statements.

1) Explicit class import

2) Implicit class import

3) Static import

1) Explicit class import


-------------------------
This type of import statement is highly recommanded to use because it will improve
readability of our code.

ex:
---
import java.time.LocalDate;
import java.time.LocalTime;
class Test
{
public static void main(String[] args)
{
LocalDate date=LocalDate.now();
System.out.println(date);

LocalTime time=LocalTime.now();
System.out.println(time);
}
}

2) Implicit class import


--------------------
This type of import statement is not recommanded to use because it will reduce the
readability of our code.

ex:
---
import java.time.*;
class Test
{
public static void main(String[] args)
{
LocalDate date=LocalDate.now();
System.out.println(date);

LocalTime time=LocalTime.now();
System.out.println(time);
}
}

static important
----------------
Using static import we can call static members (static variables and static
methods) directly.

Often use of static import makes our program complex and unreadable.

ex:
---
import static java.lang.System.*;
class Test
{
public static void main(String[] args)
{
out.println("stmt1");
out.println("stmt2");
out.println("stmt3");
}
}

ex:
---
import static java.lang.System.*;
class Test
{
public static void main(String[] args)
{
out.println("stmt1");
exit(0);
out.println("stmt2");
}
}

Editplus Free Download


======================
Download link : https://www.editplus.com/download.html

Java Basic Programs


====================

Q) Write a java program to perform sum of two numbers?

import java.util.Scanner;
class Example1
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter the first number :");


int a=sc.nextInt();

System.out.println("Enter the second number :");


int b=sc.nextInt();

int c = a + b;

System.out.println("sum of two numbers is ="+c);


}
}

Q) Write a java program to perform sum of two numbers without using third variable?

import java.util.Scanner;
class Example2
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);

System.out.println("Enter the first number :");


int a=sc.nextInt();

System.out.println("Enter the second number :");


int b=sc.nextInt();

System.out.println("sum of two numbers is ="+(a+b));


}
}

Assignment
===========
Q) Write a java program to find out of area of a rectangle?

You might also like