Professional Documents
Culture Documents
Edition :
Java has various version ( from 1.0 to 10 ) presently using Java 7 version
Java software (JDK) JAVA DEVELOPMENT KIT. JDK is open source software without JDK we
can’t run java application
Class
Class demo
Class name
{ method
{ statement
CMD:
C:\User\java.S…….\Desktop>cd java
Javac.java demo
“hello”
Key words :
** The keywords const and goto are reserved, even they are not currently in use.
const -Reserved for future use
goto – Reserved for future use
Datatypes :
Primitive datatypes
Non primitive datatypes
Primitive datatypes :
Boolean
Char
Bit
Short =2 byte
Int =4 byte
Long =8 byte
Double
Float
Bit
Short
Long ( To represent integer values )
Int
Float
Double ( To represent the decimal values )
Class datatypes
{
Public static void main ( string [] arg)
{
Boolean b=true;
System.out.println(b);
Char c=’a’;
System.out.println(c);
Int a =10;
System.out.println(a);
Double d=10.333;
System.out.println(d);
}
}
Path
Desktop
Cd java
Javac desktop.java
Java datatypes
To copy path :
My computer
C drive
Program files
Bin
For scanner :
Import java.util.scanner ;
Scanner s=new.scanner(system.in);
system.out.println(“ enter the value );
int a=s.nextInt();
system.out.println(“ enter the value again “);
int d=s.nextInt();
int c=a+d;
system.out.println(c);
Keywords, datatypes
Variables and types
Decision making statements
Oops concept
Exception handling
Collection fragments
Multi threading
File.io
Inner class
ADVANCED JAVA :
SqL
JDKC
HTML
Datatypes :
Primitive datatypes
Non primitive datatypes
Class demo
( eg )
Class demo
{
Public static void main ( string [] arg)
{
Byte b=45;
System.out.println(b);
}
}
Output :
15
Steps :
File -> new -> project -> program name
Expand project name
Select source -> new -> package
[ package starts with com.demo]
Next -> new -> class -> class name
17/07/2019
Control statements :
If statement:
package com.odd;
int age=89;
if(age>=18)
{
System.out.println(" eligible ");
}
else
{
System.out.println("not eligible ");
}
Output:
not eligible
Else if statement:
2.PROGRAM
package com.odd;
int mark=85;
}}
Output :
Grade B
package com.odd;
int number=15;
if(number%2==0)
{
System.out.println("even");
}
else
{
System.out.println("odd");
}
}
Output :
Odd
4.To find the greatest of number Program
package com.odd;
int x=95;
int y=75;
int z=83;
Output :
Z is greatest
5.Bodmas Program
package com.odd;
{
int a=10;
int b=20;
int c=2;
int d=25;
int e=15;
float z=d+b-c*a/e;
System.out.println(z);
{
System.out.println( a/e);
}
{
System.out.println(c*a);
}
{
System.out.println(d+b);
}
{
System.out.println(b-c);
}
{
System.out.println(10/15*2+25-20);
{
System.out.println(25+20-2*10/15);
}
}
Output :
19/07/2019
Looping statements :
1. While loop
2. Do while loop
3. For loop
While loop :
package looping;
Output :
1,2,3,…..,100
Do while loop :
Program :
package looping;
Output :
20
package looping;
Output :
20,21,22,……,100
Decrement operator :
package looping;
Output :
100,99,98,………,10
22/07/19
For loop :
Program :
package looping;
Output :
0,1,2,…..,10
Notes :
To increment a number the int value should be lesser then the assigned value and the
relational greater symbol should be on the assigned value.
To decrement a number the int value should be greater than the assigned value and the
relation greater symbol should be on the int value.
Switch :
Program :
package looping;
public class Switch {
int options=3;
switch(options)
{
case 1:
System.out.println("breakfast");
break;
case 2:
System.out.println("lucnh");
break;
case 3:
System.out.println("snacks");
break;
case 4:
System.out.println("dinner");
}
}
Output :
Lunch
22/07/2019
Nested loop :
Program :
package examples;
}
System.out.println();
}
Output :
00000
11111
22222
33333
44444
Program : Logic :
} i becomes 2 0<=2 “” T
}
package examples;
Output :
**
***
****
*****
Program :
package examples;
Output :
2x1=2
2x2=4
2x3=6
……..
2x20=40
Program :
package examples;
Output :
994
995
996
997
998
999
1000
Program :
package examples;
output :
Is a prime number
23/07/19
Arrays :
An array, in the context of java is dynamically created object that serves as a container to hold
constant number of values of the same datatype. By declaring an array, memory space is allocated
for values of a particular type.
Program :
package arrays;
Output :
1234567891011121314151617
Program :
package arrays;
}
System.out.println();
}
Output :
123
123
Program :
package arrays;
public class arrays {
Output :
10
20
30
40
50
60
Program :
package arrays;
import java.util.Arrays;
int z=Arrays.binarySearch(a,-5);
System.out.println(z);
Output :
-5-3,1,3,4,5,6,7,8
Program :
package arrays;
for(int i=0;i<2;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
System.out.print(c[i][j]+" ");
}
System.out.println();
}
Output :
3 8 10
7 11 14
24/07/19
String :
(eg):
Pool heep
1 s1 } ->
2 s2 }
3 s3 }
Scanner function :
Scanner is a class in java.util package used for obtaining the input of the primitive types like int,
double, etc. and strings. It is the easiest way to read input in a java program, through not very
efficient in your want an input method for scenarios where time is a constraint like in competitive
programming.
Program :
package string;
import java.util.Scanner;
Output :
Program :
package string;
Output :
java
Program :
package string;
String x="siva";
String y=x.concat("rama");
System.out.println(y);
Output :
5
v
0
sivarama
Program :
package string;
import java.util.Scanner;
Output:
enter a value
2
ente b values
4
6
Program :
package string;
Output :
y
k
c
i
v
Program :
package string;
import java.util.Scanner;
public class enter_string {
Output :
enter string
vicky
vicky
5
Program :
package string;
Output :
vickyfalsh
hslafykciv
Program :
package string;
Output :
rahul
Program :
package string;
Output :
************3456
Program :
package string;
Output :
true
true
Oops :
Global variable is declared inside the class and outside the method.
Int is a global variable that is declared inside the class and outside the
method.
A obj = name A()
Program :
package oops;
Output :
Java
Meathods :
Local variable :
declared inside a variable is called local variable.
Default value of global variable is 0
Default value of global string is null
Default value of global float is 0.0
Program :
package oops;
public class A {
int a;
int b;
int c;
void add()
{
a=10;
b=20;
c=a+b;
System.out.println(c);
}
void sub()
{
a=10;
b=20;
System.out.println(c);
}
A a=new(A);
a.add
Output :
Program :
package meathod;
}
public void ece()
{
System.out.println("magesh ");
}
public void mech()
{
System.out.println(" babu");
Main :
package meathod;
import java.util.Scanner;
case 2:
c.ece();
String s2[]= {"B","v","X"};
for(String y:s2)
{
System.out.println(y);
}
break;
case 3:
c.mech();
String s3[]= {"c","f","s"};
for(String z:s3)
{
System.out.println(z);
}
}
}
}
Output :
Program :
package meathod;
String name;
public void cinematography()
{
name="KV anadnh";
System.out.println(name);
}
public void direction ()
{
name="shaankar";
System.out.println(name);
}
}
package meathod;
import java.util.Scanner;
System.out.println("Cinema ");
System.out.println("==================================");
System.out.println("Enthiran 2.0");
System.out.println("==================================");
System.out.println("1. Direction ");
System.out.println("==================================");
System.out.println("2. Music artist");
System.out.println("==================================");
System.out.println("3. Cinematography");
System.out.println("==================================");
System.out.println("4. Actor");
Scanner s=new Scanner (System.in);
System.out.println("enter ur choice");
int choice=s.nextInt();
case 2:
c.music();
String s2[]= {};
for(String y:s2)
{
System.out.println(y);
}
break;
case 3:
c.cinematography();
String s3[]= {};
for(String z:s3)
{
System.out.println(z);
}
break ;
case 4:
c.actor();
String s4[]= {};
for(String w:s4)
{
System.out.println(w);
}
}
Output :
Cinema
==================================
Enthiran 2.0
==================================
1. Direction
==================================
2. Music artist
==================================
3. Cinematography
==================================
4. Actor
enter ur choice
2
AR Rahaman
Methods :
Methods
Instance Static
Program :
package meadthods1;
{
System.out.println(strength);
Output :
100
10
Program :
package meadthods1;
}
public static void main(String[] args)
{
Retrun r=new Retrun();
System.out.println(r.add());
Output :
10
Program :
package meadthods1;
public class V {
V.add();
Output :
welcome