Skip to content

Commit 0273017

Browse files
committed
0001 : Initial Setup
Lesson 00 Lambda Lesson 01 Functional Interface
1 parent 57d56a9 commit 0273017

File tree

9 files changed

+137
-36
lines changed

9 files changed

+137
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build/

nbproject/build-impl.xml

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,43 @@ is divided into following sections:
5454
<property file="nbproject/project.properties"/>
5555
</target>
5656
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
57-
<property name="platform.java" value="${java.home}/bin/java"/>
57+
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
58+
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
59+
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
60+
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
61+
<condition property="platform.javac" value="${platform.home}/bin/javac">
62+
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
63+
</condition>
64+
<property name="platform.javac" value="${platform.javac.tmp}"/>
65+
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
66+
<condition property="platform.java" value="${platform.home}/bin/java">
67+
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
68+
</condition>
69+
<property name="platform.java" value="${platform.java.tmp}"/>
70+
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
71+
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
72+
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
73+
</condition>
74+
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
75+
<condition property="platform.invalid" value="true">
76+
<or>
77+
<contains string="${platform.javac}" substring="$${platforms."/>
78+
<contains string="${platform.java}" substring="$${platforms."/>
79+
<contains string="${platform.javadoc}" substring="$${platforms."/>
80+
</or>
81+
</condition>
82+
<fail unless="platform.home">Must set platform.home</fail>
83+
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
84+
<fail unless="platform.java">Must set platform.java</fail>
85+
<fail unless="platform.javac">Must set platform.javac</fail>
86+
<fail if="platform.invalid">
87+
The J2SE Platform is not correctly set up.
88+
Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files.
89+
Either open the project in the IDE and setup the Platform with the same name or add it manually.
90+
For example like this:
91+
ant -Duser.properties.file=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
92+
or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
93+
</fail>
5894
<available file="${manifest.file}" property="manifest.available"/>
5995
<condition property="splashscreen.available">
6096
<and>
@@ -183,20 +219,6 @@ is divided into following sections:
183219
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
184220
<isset property="profile.available"/>
185221
</condition>
186-
<condition else="false" property="jdkBug6558476">
187-
<and>
188-
<matches pattern="1\.[56]" string="${java.specification.version}"/>
189-
<not>
190-
<os family="unix"/>
191-
</not>
192-
</and>
193-
</condition>
194-
<condition else="false" property="javac.fork">
195-
<or>
196-
<istrue value="${jdkBug6558476}"/>
197-
<istrue value="${javac.external.vm}"/>
198-
</or>
199-
</condition>
200222
<property name="jar.index" value="false"/>
201223
<property name="jar.index.metainf" value="${jar.index}"/>
202224
<property name="copylibs.rebase" value="true"/>
@@ -266,7 +288,7 @@ is divided into following sections:
266288
<property location="${build.dir}/empty" name="empty.dir"/>
267289
<mkdir dir="${empty.dir}"/>
268290
<mkdir dir="@{apgeneratedsrcdir}"/>
269-
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
291+
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
270292
<src>
271293
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
272294
<include name="*"/>
@@ -306,7 +328,7 @@ is divided into following sections:
306328
<sequential>
307329
<property location="${build.dir}/empty" name="empty.dir"/>
308330
<mkdir dir="${empty.dir}"/>
309-
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
331+
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
310332
<src>
311333
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
312334
<include name="*"/>
@@ -387,7 +409,7 @@ is divided into following sections:
387409
<element name="customize" optional="true"/>
388410
<sequential>
389411
<property name="junit.forkmode" value="perTest"/>
390-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
412+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
391413
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
392414
<syspropertyset>
393415
<propertyref prefix="test-sys-prop."/>
@@ -410,7 +432,7 @@ is divided into following sections:
410432
<element name="customize" optional="true"/>
411433
<sequential>
412434
<property name="junit.forkmode" value="perTest"/>
413-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
435+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
414436
<batchtest todir="${build.test.results.dir}">
415437
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
416438
<filename name="@{testincludes}"/>
@@ -449,7 +471,7 @@ is divided into following sections:
449471
</fileset>
450472
</union>
451473
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
452-
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Java8Features" testname="TestNG tests" workingDir="${work.dir}">
474+
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Java8Features" testname="TestNG tests" workingDir="${work.dir}">
453475
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
454476
<propertyset>
455477
<propertyref prefix="test-sys-prop."/>
@@ -529,7 +551,7 @@ is divided into following sections:
529551
<element name="customize" optional="true"/>
530552
<sequential>
531553
<property name="junit.forkmode" value="perTest"/>
532-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
554+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
533555
<test methods="@{testmethods}" name="@{testincludes}" todir="${build.test.results.dir}"/>
534556
<syspropertyset>
535557
<propertyref prefix="test-sys-prop."/>
@@ -554,7 +576,7 @@ is divided into following sections:
554576
<element name="customize" optional="true"/>
555577
<sequential>
556578
<property name="junit.forkmode" value="perTest"/>
557-
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
579+
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
558580
<batchtest todir="${build.test.results.dir}">
559581
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
560582
<filename name="@{testincludes}"/>
@@ -734,6 +756,9 @@ is divided into following sections:
734756
<classpath>
735757
<path path="@{classpath}"/>
736758
</classpath>
759+
<bootclasspath>
760+
<path path="${platform.bootcp}"/>
761+
</bootclasspath>
737762
</nbjpdastart>
738763
</sequential>
739764
</macrodef>
@@ -749,7 +774,9 @@ is divided into following sections:
749774
</macrodef>
750775
</target>
751776
<target name="-init-debug-args">
752-
<property name="version-output" value="java version &quot;${ant.java.version}"/>
777+
<exec executable="${platform.java}" outputproperty="version-output">
778+
<arg value="-version"/>
779+
</exec>
753780
<condition property="have-jdk-older-than-1.4">
754781
<or>
755782
<contains string="${version-output}" substring="java version &quot;1.0"/>
@@ -774,7 +801,7 @@ is divided into following sections:
774801
<attribute default="${debug.classpath}" name="classpath"/>
775802
<element name="customize" optional="true"/>
776803
<sequential>
777-
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
804+
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
778805
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
779806
<jvmarg line="${debug-args-line}"/>
780807
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
@@ -801,7 +828,7 @@ is divided into following sections:
801828
<attribute default="jvm" name="jvm"/>
802829
<element name="customize" optional="true"/>
803830
<sequential>
804-
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
831+
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
805832
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
806833
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
807834
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
@@ -999,7 +1026,7 @@ is divided into following sections:
9991026
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
10001027
<echo level="info">To run this application from the command line without Ant, try:</echo>
10011028
<property location="${dist.jar}" name="dist.jar.resolved"/>
1002-
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
1029+
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
10031030
</target>
10041031
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
10051032
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
@@ -1208,10 +1235,13 @@ is divided into following sections:
12081235
</not>
12091236
</and>
12101237
</condition>
1238+
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
1239+
<arg value="-version"/>
1240+
</exec>
12111241
<condition else="" property="bug5101868workaround" value="*.java">
1212-
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
1242+
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
12131243
</condition>
1214-
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
1244+
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
12151245
<classpath>
12161246
<path path="${javac.classpath}"/>
12171247
</classpath>

nbproject/genfiles.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
build.xml.data.CRC32=dfd64344
1+
build.xml.data.CRC32=53a7d579
22
build.xml.script.CRC32=c6b5575f
33
build.xml.stylesheet.CRC32=8064a381@1.79.1.48
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
6-
nbproject/build-impl.xml.data.CRC32=dfd64344
7-
nbproject/build-impl.xml.script.CRC32=03e8f915
6+
nbproject/build-impl.xml.data.CRC32=53a7d579
7+
nbproject/build-impl.xml.script.CRC32=3066fa53
88
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48

nbproject/private/config.properties

Whitespace-only changes.

nbproject/private/private.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
compile.on.save=true
2+
do.depend=false
3+
do.jar=true
4+
javac.debug=true
5+
javadoc.preview=true
26
user.properties.file=C:\\Users\\manbhakr\\AppData\\Roaming\\NetBeans\\8.1\\build.properties

nbproject/project.properties

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
annotation.processing.enabled=true
22
annotation.processing.enabled.in.editor=false
3-
annotation.processing.processor.options=
43
annotation.processing.processors.list=
54
annotation.processing.run.all.processors=true
65
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
6+
application.title=Java8Features
7+
application.vendor=manbhakr
78
build.classes.dir=${build.dir}/classes
89
build.classes.excludes=**/*.java,**/*.form
910
# This directory is removed when the project is cleaned:
@@ -26,6 +27,7 @@ dist.archive.excludes=
2627
dist.dir=dist
2728
dist.jar=${dist.dir}/Java8Features.jar
2829
dist.javadoc.dir=${dist.dir}/javadoc
30+
endorsed.classpath=
2931
excludes=
3032
includes=**
3133
jar.compress=false
@@ -36,8 +38,8 @@ javac.deprecation=false
3638
javac.external.vm=true
3739
javac.processorpath=\
3840
${javac.classpath}
39-
javac.source=1.7
40-
javac.target=1.7
41+
javac.source=1.8
42+
javac.target=1.8
4143
javac.test.classpath=\
4244
${javac.classpath}:\
4345
${build.classes.dir}
@@ -58,7 +60,7 @@ main.class=java8features.Java8Features
5860
manifest.file=manifest.mf
5961
meta.inf.dir=${src.dir}/META-INF
6062
mkdist.disabled=false
61-
platform.active=default_platform
63+
platform.active=JDK_1.8
6264
run.classpath=\
6365
${javac.classpath}:\
6466
${build.classes.dir}

nbproject/project.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<configuration>
55
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
66
<name>Java8Features</name>
7+
<explicit-platform explicit-source-supported="true"/>
78
<source-roots>
89
<root id="src.dir"/>
910
</source-roots>

src/com/know/lambda/Lesson_00_Lambda_Expression.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,56 @@
1111
* - NO NAME
1212
* - NO RETURN TYPE
1313
* - NO MODIFIER
14-
*
14+
* - ADD ARROW SYMBOL
1515
* Lambda expression are introduced in java 8 to
1616
* enable Functional Programming features in java.
1717
* Other Languages like Python, R, C , C++
1818
* already have Lambda Features.
1919
*
20+
* If we have function
21+
*
22+
* public void test(){ System.out.println("Test Function in java 7");}
23+
*
24+
* then in java 8 we can create using no name , no return type and no modifier
25+
*
26+
* Remove Public , void and test
27+
* ()->{System.out.println("Test Function in java 8");}
28+
*
29+
* we can remove braces in case of a single line
30+
* () -> System.out.println("Cheers to Java 8");
31+
*
2032
*
2133
* @author KnowGroup
2234
*/
2335
public class Lesson_00_Lambda_Expression {
36+
37+
public void test(){
38+
System.out.println("Test function in java 7");
39+
}
40+
41+
@FunctionalInterface
42+
interface Interf1{
43+
abstract void m1();
44+
}
45+
46+
interface Interf2{
47+
abstract void m2(Integer i,Integer j);
48+
}
49+
50+
interface Interf3{
51+
abstract Integer m3(Integer i,Integer j);
52+
}
2453

54+
public static void main(String arg[]){
55+
Interf1 if1 = () -> System.out.println("Cheers to Java 8");
56+
if1.m1();
57+
58+
Interf2 if2 = (i,j) -> System.out.println("Adding :: "+i+"+"+j+" = "+(i+j));
59+
if2.m2(10, 20);
60+
61+
Interf3 if3 = (i,j) -> i*j;
62+
Integer m3_result = if3.m3(12,10);
63+
System.out.println("m3_result :: "+m3_result);
64+
65+
}
2566
}

0 commit comments

Comments
 (0)