Skip to content

Commit 12d57a8

Browse files
committed
first commit
0 parents  commit 12d57a8

32 files changed

+1827
-0
lines changed

A.java

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
Anonymous Inner class example:-
3+
*/
4+
5+
package javapep;
6+
7+
/**
8+
*
9+
* @author anil
10+
*/
11+
public interface A {//cannot create objects of interface
12+
void meth();
13+
14+
15+
}
16+
interface B
17+
{
18+
void meth1();
19+
}
20+
21+
abstract class C{
22+
abstract void meth2();
23+
void meth3()
24+
{
25+
System.out.println("hello meth3 abstract");
26+
27+
}
28+
29+
30+
}
31+
32+
33+
class test
34+
{
35+
public static void main(String args[])
36+
{
37+
A ob = new A()//Anonymous in a class it is only making a reference of interface A not creating object of A
38+
{
39+
40+
public void meth()
41+
{
42+
System.out.println("Anonymous implementation");
43+
44+
}
45+
};
46+
47+
B ob1 = new B()//Anonymous in a class it is only making a reference of interface A not creating object of A
48+
{
49+
50+
public void meth1()
51+
{
52+
System.out.println("Anonymous implementation in Interface B");
53+
54+
}
55+
};
56+
B o2=()->{//lamba implementation it can be implemented with function interface only
57+
//And function interface can only hold one methode
58+
System.out.println("Lambda expressions");
59+
60+
};
61+
o2.meth1();
62+
63+
64+
test ob2 = new test(){
65+
66+
void meth2()
67+
{
68+
69+
System.out.println("Abstract implementation");
70+
}
71+
};
72+
ob.meth();
73+
ob1.meth1();
74+
//ob2.meth2();
75+
}
76+
77+
78+
}
79+

Arraylist.java

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package javapep;
8+
import java.util.ArrayList;
9+
import java.util.Iterator;
10+
11+
/**
12+
*
13+
* @author anil
14+
*/
15+
public class Arraylist {
16+
17+
18+
19+
int nPage;
20+
String author;
21+
int edition;
22+
Arraylist(int n,String author ,int edition)
23+
{
24+
this.author=author;
25+
this.nPage=n;
26+
this.edition=edition;
27+
28+
}
29+
}
30+
class demo{
31+
static int display( ArrayList<Arraylist> al)
32+
{
33+
34+
System.out.println("nPage"+" "+"author"+" " +"edition");
35+
Arraylist b;
36+
Iterator it =al.iterator();
37+
while(it.hasNext())
38+
{
39+
b=(Arraylist)it.next();
40+
System.out.println(b.nPage+" "+b.author+" "+b.edition);
41+
//System.out.println(al);
42+
43+
}
44+
return 0;
45+
}
46+
public static void main(String args[])
47+
{
48+
// ArrayList<String> al= new ArrayList<>();
49+
// al.add("Anil");
50+
// al.add("Vivek");
51+
// al.add("Pankaj");
52+
// al.add("Arvind");
53+
// System.out.println(al);
54+
55+
// Iterator it =al.iterator();
56+
// while(it.hasNext())
57+
// System.out.print(it.next());
58+
59+
// if(al.contains("anil"))
60+
// {
61+
// System.out.println("yes");
62+
// }
63+
// else
64+
// {
65+
// System.out.println("NO");
66+
// }
67+
68+
// for(String a:al)
69+
// System.out.print(a);
70+
71+
72+
// for(int i=0;i<al.size();i++)
73+
// {
74+
// System.out.print(al.get(i));
75+
// }
76+
77+
Arraylist a=new Arraylist(50,"anil",1997);
78+
Arraylist b=new Arraylist(51,"pankaj",1998);
79+
Arraylist c=new Arraylist(52,"deepak",1999);
80+
ArrayList<Arraylist> al= new ArrayList<Arraylist>(); //Generic type arraylist
81+
al.add(a);
82+
al.add(b);
83+
al.add(c);
84+
display(al);
85+
86+
87+
88+
}
89+
90+
}
91+

BubbleSort.java

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package javapep;
8+
9+
/**
10+
*
11+
* @author anil
12+
*/
13+
public class BubbleSort {
14+
public static void main(String args[])
15+
{
16+
int arr[]={5,7,4,9,3,2,1};
17+
18+
int temp;
19+
for(int i=0;i<7;i++)
20+
{
21+
for(int j=0;j<7-i-1;j++)
22+
{
23+
if(arr[j]>arr[j+1])
24+
{
25+
temp=arr[j];
26+
arr[j]=arr[j+1];
27+
arr[j+1]=temp;
28+
29+
}
30+
31+
}
32+
}
33+
34+
for(int j=0;j<arr.length;j++)
35+
{
36+
System.out.println(arr[j]);
37+
}
38+
}
39+
40+
41+
}
42+

ChangeCaseWithString.java

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package javapep;
8+
9+
/**
10+
*
11+
* @author anil
12+
*/
13+
public class ChangeCaseWithString {
14+
public static void main(String args[])
15+
{
16+
17+
18+
String s1="tHis IS aN EXamPLE";
19+
char ar[]=new char[s1.length()];
20+
ar=s1.toCharArray();
21+
for(int i=0;i<ar.length;i++)
22+
{
23+
if(Character.isUpperCase(ar[i]))
24+
{
25+
ar[i]=Character.toLowerCase(ar[i]);
26+
}
27+
else if(Character.isLowerCase(ar[i]))
28+
{
29+
ar[i]=Character.toUpperCase(ar[i]);
30+
}
31+
32+
}
33+
String se=new String(ar);
34+
System.out.println(se);
35+
36+
37+
}
38+
}
39+
40+
41+

DateTime.java

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package javapep;
8+
import java.time.*;
9+
import java.time.format.DateTimeFormatter;
10+
import java.time.temporal.ChronoUnit;
11+
import java.util.Date;
12+
13+
/**
14+
*
15+
* @author anil
16+
*/
17+
public class DateTime {
18+
public static void main(String args[])
19+
{
20+
// LocalDate ld=LocalDate.now();
21+
// System.out.println(ld);
22+
// LocalTime lt=LocalTime.now();
23+
// System.out.println(lt);
24+
//
25+
// LocalDateTime ldt =LocalDateTime.now();
26+
// System.out.println(ldt);
27+
//
28+
// LocalDate ld1= LocalDate.of(2019,Month.JULY,13);
29+
// System.out.println(ld1);
30+
//
31+
// LocalDate ld2=ld1.plusDays(3);
32+
// System.out.println(ld2);
33+
//
34+
// LocalDate ld5=ld1.minusDays(3);
35+
// System.out.println(ld5);
36+
//
37+
// System.out.println(ld2.getDayOfMonth());
38+
// System.out.println(ld2.getDayOfWeek());
39+
// System.out.println(ld1.isAfter(ld2));
40+
//
41+
// LocalDate ld3=LocalDate.parse("2016-05-30");
42+
// System.out.println(ld3);
43+
//
44+
// System.out.println(ld3.isLeapYear());
45+
//
46+
// DateTimeFormatter dtf= DateTimeFormatter.ofPattern("dd-MM-yyyy,HH:mm:ss");
47+
// String s=ldt.format(dtf);
48+
// System.out.println(s);
49+
50+
Period p=Period.ofDays(10);
51+
System.out.println(p);
52+
53+
LocalTime lt1=LocalTime.now();
54+
LocalTime lt2=lt1.plusHours(5);
55+
Duration d=Duration.between(lt1,lt2);
56+
System.out.println(d.get(ChronoUnit.SECONDS));
57+
System.out.println(d.toHours());//check hours between lt1 n lt2
58+
System.out.println(d.toMinutes());
59+
60+
61+
62+
63+
}
64+
65+
}

ExcepArray.java

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package javapep;
8+
9+
class ExcepArray extends Exception
10+
{
11+
ExcepArray(String s)
12+
{
13+
super(s);
14+
}
15+
}
16+
class t{
17+
public static void main(String args[]) throws ExcepArray
18+
{
19+
int arr1[]={1,5,7,8,9,10};
20+
int arr2[]={1,5,7,8,9};
21+
try
22+
{
23+
int sum1=0;
24+
if(arr1.length==arr2.length)
25+
{
26+
for(int i=0;i<arr1.length;i++)
27+
{
28+
sum1=sum1+arr1[i]+arr2[i];
29+
}
30+
System.out.println("sumof two arrays ="+sum1);
31+
32+
}
33+
else{
34+
35+
throw new ExcepArray("Not same size");
36+
}
37+
}catch(Exception e)
38+
{
39+
System.out.println("Exception occured: "+e.getMessage());
40+
}
41+
42+
}
43+
}
44+
45+
46+
47+

0 commit comments

Comments
 (0)