Skip to content

Commit 208d780

Browse files
committed
first commit for groovy code
0 parents  commit 208d780

15 files changed

+324
-0
lines changed

blog1.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
3+
title
4+
groovy basics for Java Programmer
5+
====
6+
7+
One of the easy ways to install groovy is to use sdkman
8+
Once installation is complete, make sure path has been set, by typing groovy -v
9+
10+
create a file having extension groovy as follows:
11+
12+
one.groovy
13+
14+
class Two
15+
{
16+
static void main(String[] args)
17+
{
18+
println 'hello'
19+
println ("hi");
20+
21+
}
22+
}
23+
24+
25+
we can run the file as follows:
26+
27+
groovy one.groovy
28+
====
29+
30+
the output is
31+
hello
32+
33+
=======
34+
lessons:
35+
1. semi-colon is optional. In java semi-colon is must to terminate a statement.
36+
2. string literal can be in single quotes as well as in double quotes. In Java String literals can only be enclosed in double quotes.
37+
3. we did not compile the file instead just ran the source code
38+
4 parentheses is optional when calling a method
39+
=======
40+
41+
42+
class Two
43+
{
44+
static void main(String[] args)
45+
{
46+
int num
47+
println num
48+
}
49+
}
50+
51+
output is 0
52+
========
53+
lessons:
54+
local variable is initialised with default value. In java it is an error
55+
=========
56+
57+
class Two
58+
{
59+
static void main(String[] args)
60+
{
61+
62+
int k
63+
64+
if(k)
65+
println 'yes'
66+
else
67+
println 'no'
68+
69+
}
70+
}
71+
=========
72+
lessons:
73+
output is no. 0 and null are considered as false and non-zero and not null values are considered as true
74+
=========

enum/One.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class One
2+
{
3+
static void main(String[] args)
4+
{
5+
6+
//Status s1=s1.getEmailStatus("sent");
7+
8+
//Status s1=s1.getEmailStatus("Sent");
9+
10+
11+
/*
12+
Status s1=Status.getEmailStatus("sent");
13+
println(s1); //null
14+
*/
15+
16+
17+
Status s1=Status.getEmailStatus("Sent");
18+
println(s1); //null
19+
20+
21+
22+
}
23+
}
24+

enum/Status.groovy

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
enum Status {
2+
3+
4+
SENT("Sent") , FAILED("Failed") ;
5+
6+
private String key;
7+
8+
private Status(String key) {
9+
this.key = key;
10+
}
11+
12+
public String getKey() {
13+
return this.key;
14+
}
15+
16+
public static Status getEmailStatus(String key) {
17+
for (Status keyValues : Status.values()) {
18+
if (keyValues.getKey().equals(key)) {
19+
return keyValues;
20+
}
21+
}
22+
return null;
23+
}
24+
25+
public static Status getStatusObject(String key){
26+
Status status = null;
27+
for(Status keyValue : Status.values()){
28+
if(keyValue.getKey().toLowerCase().contains(key)){
29+
status = keyValue;
30+
}
31+
}
32+
return status;
33+
}
34+
35+
36+
}

exception1.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Exception1
2+
{
3+
static main(args)
4+
{
5+
6+
7+
println "Krishna"
8+
println(5/0)
9+
println "oops"
10+
11+
}
12+
13+
}
14+

exception2.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Exception2
2+
{
3+
static main(args)
4+
{
5+
Thread.sleep(5000)
6+
println "Radhey \nRadhey Krishna"
7+
}
8+
}
9+

exception3.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Exception3
2+
{
3+
4+
5+
6+
static main(args)
7+
{
8+
9+
10+
11+
12+
Thread.sleep(5000)
13+
14+
15+
16+
println "Hey Gopal Radhey Krishna\n Govind Govind"
17+
18+
19+
20+
}
21+
22+
23+
24+
25+
}
26+

exception4.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Exception4
2+
{
3+
static main(args)
4+
{
5+
Thread.sleep(5000)
6+
println "Hey Gopal Radhey Krishna\n Govind Govind"
7+
}
8+
}
9+

five.groovy

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Five
2+
{
3+
static main(args)
4+
{
5+
6+
7+
println "Krishna"
8+
9+
10+
}
11+
12+
}
13+

four.groovy

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Four
2+
{
3+
static void main(String[] args)
4+
{
5+
6+
7+
String names=['alex','peter','martin']
8+
9+
//println names.each(it) //error
10+
11+
12+
//names.each{ println it}
13+
14+
/*
15+
names=["one","two","three"]
16+
names.each{ println it}
17+
*/
18+
19+
String arr=["electron","proton","neutron"]
20+
21+
arr.each{ println it}
22+
23+
}
24+
25+
}
26+

groovy-samples

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit b8ff64bbc287fbbaea9f4cce91022a73674dc84a

method/one.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class One
2+
{
3+
static main(args)
4+
{
5+
println getVal()
6+
}
7+
8+
static def getVal()
9+
{
10+
5
11+
}
12+
13+
}
14+

nt.groovy

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class NT
2+
{
3+
static void main(String[] args)
4+
{
5+
String str1=null;
6+
String str=str1;
7+
if(str)
8+
println "yes"
9+
else
10+
println "no"
11+
}
12+
13+
}
14+

one.groovy

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
class One
2+
{
3+
static void main(String[] args)
4+
{
5+
6+
7+
8+
int num
9+
println num
10+
11+
/*
12+
def num
13+
println num // null
14+
*
15+
/
16+
17+
//println 'a',500 //error
18+
19+
20+
//println a; //error
21+
22+
23+
/*
24+
println 'a'
25+
println 5
26+
*/
27+
28+
29+
///println hello// error
30+
31+
//println "Shree Krishna"
32+
33+
/*
34+
if(null)
35+
println "yes"
36+
else
37+
println "no"
38+
*/
39+
40+
41+
}
42+
43+
}
44+

three.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
println 'ohhh my god'
3+

two.groovy

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class One
2+
{
3+
static void main(String[] args)
4+
{
5+
6+
int k
7+
8+
if(k)
9+
println 'yes'
10+
else
11+
println 'no'
12+
13+
14+
}
15+
16+
}
17+

0 commit comments

Comments
 (0)