Commit 21bb2eca authored by Swathi Karre's avatar Swathi Karre

initial Commit

parents
#Thu Mar 26 12:11:08 IST 2020
gradle.version=4.10.3
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
<option name="useAutoImport" value="true" />
<option name="useQualifiedModuleNames" value="true" />
</GradleProjectSettings>
</option>
</component>
</project>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClassOnlyUsedInOnePackage" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ClassUnconnectedToPackage" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="DisjointPackage" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="EmptyDirectory" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="ExceptionPackage" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PackageInMultipleModules" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="PackageWithTooFewClasses" enabled="true" level="WARNING" enabled_by_default="true">
<option name="limit" value="3" />
</inspection_tool>
<inspection_tool class="PackageWithTooManyClasses" enabled="true" level="WARNING" enabled_by_default="true">
<option name="limit" value="10" />
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" default="false" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../" vcs="Git" />
</component>
</project>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
plugins {
id 'java'
}
group 'com.nisum'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.9
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
module demoModule
{
requires jdk.incubator.httpclient;
}
\ No newline at end of file
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#!/usr/bin/env sh
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "$@"
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
rootProject.name = 'java9Features'
package com.nisum.java9Features.DiamondOperator;
public class MyGenClass<T> {
T obj;
public MyGenClass(T obj)
{
this.obj = obj;
}
public T getObj()
{
return obj;
}
public void process()
{
System.out.println("Processing obj...");
}
}
package com.nisum.java9Features.DiamondOperator;
public class Test {
public static void main(String[] args) {
MyGenClass<String> c1 = new MyGenClass<String>("Durga") {
public void process() {
System.out.println("Processing... " + getObj());
}
};
c1.process();
MyGenClass<String> c2 = new MyGenClass<>("Pavan") {
public void process() {
System.out.println("Processing... " + getObj());
}
};
c2.process();
}
}
package com.nisum.java9Features.FactoryMethodsForUnmodifiableCollections;
public class Employee {
private int eno;
private String ename;
public Employee(int eno, String ename) {
this.eno = eno;
this.ename = ename;
}
@Override
public String toString() {
return String.format("%d=%s",eno,ename);
}
}
package com.nisum.java9Features.FactoryMethodsForUnmodifiableCollections;
import java.util.*;
public class UnmodifiableList {
public static void main(String[] args) {
Employee e1=new Employee(100,"sunny");
Employee e2=new Employee(101, "Bunny");
Employee e3=new Employee(102,"Chinny");
// Employee e4=null;
//List<Employee> emplist=List.of(e1,e2,e3,e4);
List<Employee> emplist=List.of(e1,e2,e3);
System.out.println(emplist);
Employee e5=new Employee(103,"Laddu");
//emplist.add(e5); // Unsupported Exception
}
}
package com.nisum.java9Features.FactoryMethodsForUnmodifiableCollections;
import java.sql.*;
import java.util.*;
import static java.util.Map.entry;
public class UnmodifiableMap {
public static void main(String[] args) {
Map<String,String> map=Map.of("A","Apple","B","Banana","C","Cat","D","Dog");
System.out.println(map);
/* Map<String,String> map1=Map.of("A","Apple","A","Banana","C","Cat","D","Dog");
System.out.println(map1); // IllegalArgumentException*/
/*Map<String,String> map2=Map.of("A",null,"B","Banana"); // NullPointerException
System.out.println(map2);*/
Map.Entry<String,String> e1= entry("A","Apple");
Map.Entry<String,String> e2= entry("B","Banana");
Map.Entry<String,String> e3= entry("C","Cat");
Map<String,String> m=Map.ofEntries(e1,e2,e3);
System.out.println(m);
/* Map<String,String> map3=Map.ofEntries(entry(null,"Apple"),entry("B","Banana")); // NullPointerException
System.out.println(map3);*/
/* Map<String,String> map4=Map.ofEntries(entry("A","Apple"),entry("B","Banana"));
map4.put("C","Cat"); // UnsupportedOperationException
map4.remove("A");//UnsupportedOperationException*/
}
}
package com.nisum.java9Features.FactoryMethodsForUnmodifiableCollections;
import java.util.*;
public class UnmodifiableSet {
public static void main(String[] args) {
Employee e1=new Employee(100,"sunny");
Employee e2=new Employee(101, "Bunny");
Employee e3=new Employee(102,"Chinny");
// Employee e4=null;
//List<Employee> emplist=List.of(e1,e2,e3,e4);
Set<Employee> emplist=Set.of(e1,e2,e3,e3);
System.out.println(emplist);
Employee e5=new Employee(103,"Laddu");
//emplist.add(e5); // Unsupported Exception
}
}
package com.nisum.java9Features.PrivateMethods;
public interface Java9Interf
{
default void m1()
{
m3();
}
default void m2()
{
m3();
}
private void m3()
{
System.out.println("common functionality of methods m1 & m2");
}
}
package com.nisum.java9Features.PrivateMethods;
public interface Java9InterfStatic {
public static void m1()
{
m3();
}
public static void m2()
{
m3();
}
private static void m3()
{
System.out.println("common functionality of methods m1 & m2");
}
}
package com.nisum.java9Features.PrivateMethods;
public class PrivateInstanceMethods implements Java9Interf
{
public static void main(String[] args) {
PrivateInstanceMethods t = new PrivateInstanceMethods();
t.m1();
t.m2();
//t.m3(); //CE
}
}
package com.nisum.java9Features.PrivateMethods;
public class PrivateStaticMethod implements Java9InterfStatic {
public static void main(String[] args)
{
Java9InterfStatic.m1();
Java9InterfStatic.m2();
}
}
package com.nisum.java9Features.ProcessAPI;
public class CurrentProcessInfo {
public static void main(String[] args) throws Exception {
ProcessHandle p = ProcessHandle.current();
ProcessHandle.Info info = p.info();
System.out.println("Complete Process Inforamtion:\n" + info);
System.out.println("User: " + info.user().get());
System.out.println("Command: " + info.command().get());
System.out.println("Start Time: " + info.startInstant().get());
System.out.println("Total CPU Time Acquired: " + info.totalCpuDuration().get());
}
}
package com.nisum.java9Features.ProcessAPI;
public class DestroyProcessFromProcessBuilder {
public static void main(String[] args) throws Exception {
ProcessBuilder pb = new ProcessBuilder("java", "sample");
Process p = pb.start();
System.out.println("Process Started with id:" + p.pid());
Thread.sleep(10000);
System.out.println("Destroying the process with id:" + p.pid());
p.destroy();
}
}
package com.nisum.java9Features.ProcessAPI;
public class NotepadFromProcessBuilder {
public static void main(String[] args) throws Exception {
new ProcessBuilder("notepad.exe", "sample.java").start();
}
}
package com.nisum.java9Features.ProcessAPI;
import java.util.*;
public class ProcessBasedOnID {
public static void main(String[] args) throws Exception {
//need to get the pid from task manager
Optional<ProcessHandle> opt = ProcessHandle.of(8408);
ProcessHandle p = opt.get();
ProcessHandle.Info info = p.info();
System.out.println("Complete Process Inforamtion:\n" + info);
System.out.println("User: " + info.user().get());
System.out.println("Command: " + info.command().get());
System.out.println("Start Time: " + info.startInstant().get());
System.out.println("Total CPU Time Acquired: " + info.totalCpuDuration().get());
}
}
package com.nisum.java9Features.ProcessAPI;
public class ProcessID {
public static void main(String[] args) throws Exception {
ProcessHandle p = ProcessHandle.current();
long pid = p.pid();
System.out.println("The PID of current running JVM instance :" + pid);
Thread.sleep(100000);
}
}
package com.nisum.java9Features.ReactiveStreams;
import java.util.*;
public class EmpHelper {
public static List<Employee> getEmps() {
Employee e1 = new Employee(1, "Pankaj");
Employee e2 = new Employee(2, "David");
Employee e3 = new Employee(3, "Lisa");
Employee e4 = new Employee(4, "Ram");
Employee e5 = new Employee(5, "Anupam");
List<Employee> emps = new ArrayList<>();
emps.add(e1);
emps.add(e2);
emps.add(e3);
emps.add(e4);
emps.add(e5);
return emps;
}
}
package com.nisum.java9Features.ReactiveStreams;
public class Employee {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Employee(int id, String name) {
this.id = id;
this.name = name;
}
public Employee() {
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}
package com.nisum.java9Features.ReactiveStreams;
import java.util.*;
import java.util.concurrent.*;
public class MyReactiveApp {
public static void main(String args[]) throws InterruptedException {
// Create Publisher
SubmissionPublisher<Employee> publisher = new SubmissionPublisher<>();
// Register Subscriber
MySubscriber subs = new MySubscriber();
publisher.subscribe(subs);
List<Employee> emps = EmpHelper.getEmps();
// Publish items
System.out.println("Publishing Items to Subscriber");
emps.stream().forEach(i -> publisher.submit(i));
// logic to wait till processing of all messages are over
while (emps.size() != subs.getCounter()) {
Thread.sleep(10);
}
// close the Publisher
publisher.close();
System.out.println("Exiting the app");
}
}
package com.nisum.java9Features.ReactiveStreams;
import java.util.concurrent.*;
import java.util.concurrent.Flow.Subscriber;
import java.util.concurrent.Flow.Subscription;
public class MySubscriber implements Subscriber<Employee> {
private Subscription subscription;
private int counter = 0;
@Override
public void onSubscribe(Subscription subscription) {
System.out.println("Subscribed");
this.subscription = subscription;
this.subscription.request(1); //requesting data from publisher
System.out.println("onSubscribe requested 1 item");
}
@Override
public void onNext(Employee item) {
System.out.println("Processing Employee " + item);
counter++;
this.subscription.request(1);
}
@Override
public void onError(Throwable e) {
System.out.println("Some error happened");
e.printStackTrace();
}
@Override
public void onComplete() {
System.out.println("All Processing Done");
}
public int getCounter() {
return counter;
}
}
package com.nisum.java9Features.StreamApi;
import java.util.*;
import java.util.stream.*;
public class TestDropWhile {
public static void main(String[] args) {
ArrayList<Integer> l1 = new ArrayList<Integer>();
l1.add(2);
l1.add(4);
l1.add(1);
l1.add(3);
l1.add(6);
l1.add(5);
l1.add(8);
System.out.println("Initial List:" + l1);
List<Integer> l2 = l1.stream().dropWhile(i -> i % 2 == 0).collect(Collectors.toList());
System.out.println("After dropWhile:" + l2);
}
}
package com.nisum.java9Features.StreamApi;
import java.util.stream.*;
public class TestIterate {
public static void main(String[] args) {
//Stream.iterate(1, x->x+1).forEach(System.out::println); // return infinite elements
Stream.iterate(1, x->x+1).limit(5).forEach(System.out::println);
System.out.println("3argument iterate");
Stream.iterate(1,x->x<10, x->x+1).forEach(System.out::println);
}
}
package com.nisum.java9Features.StreamApi;
import java.util.*;
import java.util.stream.*;
public class TestOfNullable {
public static void main(String[] args) {
List<String> l = new ArrayList<String>();
l.add("A");
l.add("B");
l.add(null);
l.add("C");
l.add("D");
l.add(null);
System.out.println(l);
List<String> l2 = l.stream().filter(o -> o != null).collect(Collectors.toList());
System.out.println(l2);
List<String> l3 = l.stream().flatMap(o -> Stream.ofNullable(o)).collect(Collectors.toList());
System.out.println(l3);
Map<String, String> m = new HashMap<>();
m.put("A", "Apple");
m.put("B", "Banana");
m.put("C", null);
m.put("D", "Dog");
m.put("E", null);
List<String> l4 = m.entrySet().stream().map(e -> e.getKey()).collect(Collectors.toList());
System.out.println(l4);
List<String> l5 = m.entrySet().stream().flatMap(e -> Stream.ofNullable(e.getValue())).collect(Collectors.toList());
System.out.println(l5);
}
}
package com.nisum.java9Features.StreamApi;
import java.util.*;
import java.util.stream.*;
public class TestTakeWhile {
public static void main(String[] args) {
ArrayList<Integer> l1 = new ArrayList<Integer>();
l1.add(2);
l1.add(4);
l1.add(1);
l1.add(3);
l1.add(6);
l1.add(5);
l1.add(8);
System.out.println("Initial List:" + l1);
List<Integer> l2 = l1.stream().filter(i -> i % 2 == 0).collect(Collectors.toList());
System.out.println("After Filtering:" + l2);
List<Integer> l3 = l1.stream().takeWhile(i -> i % 2 == 0).collect(Collectors.toList());
System.out.println("After takeWhile:" + l3);
}
}
package com.nisum.java9Features.TryWithResourcesEnhancements;
public class MyResources implements AutoCloseable {
MyResources()
{
System.out.println("Resource Creation...");
}
public void doProcess()
{
System.out.println("Resource Processing...");
}
public void close()
{
System.out.println("Resource Closing...");
}
}
package com.nisum.java9Features.TryWithResourcesEnhancements;
public class TryWithResourceApp {
public static void preJDK7()
{
MyResources r=null;
try
{
r=new MyResources();
r.doProcess();
}
catch (Exception e)
{
System.out.println("Handling:"+e);
}
finally
{
try
{
if (r!=null)
{
r.close();
}
}
catch (Exception e)
{
System.out.println("Handling:"+e);
}
}
}
public static void JDK7()
{
try(MyResources r=new MyResources())
{
r.doProcess();
}
catch(Exception e)
{
System.out.println("Handling:"+e);
}
}
public static void JDK9()
{
MyResources r= new MyResources();
try(r)
{
r.doProcess();
}
catch(Exception e)
{
System.out.println("Handling:"+e);
}
}
public static void multipleJDK9()
{
MyResources r1= new MyResources();
MyResources r2= new MyResources();
MyResources r3= new MyResources();
MyResources r4= new MyResources();
try(r1;r2;r3;r4)
{
r1.doProcess();
r2.doProcess();
r3.doProcess();
r4.doProcess();
}
catch(Exception e)
{
System.out.println("Handling:"+e);
}
}
public static void main(String[] args)
{
System.out.println("Program Execution With PreJDK7");
preJDK7();
System.out.println("Program Execution With JDK7");
JDK7();
System.out.println("Program Execution With JDK9");
JDK9();
System.out.println("Program Execution Multiple Resources With JDK9");
multipleJDK9();
}
}
package com.nisum.java9Features.http2;
import com.nisum.java9Features.DiamondOperator.*;
import java.net.*;
import java.net.http.*;
import java.util.*;
import java.util.concurrent.*;
public class TestAsync {
public static void main(String[] args) throws Exception {
String url = "https://www.redbus.in/info/aboutus";
sendGetAsyncRequest(url);
}
public static void sendGetAsyncRequest(String url) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(new URI(url)).GET().build();
System.out.println("Sending Asynchronous Request...");
CompletableFuture<HttpResponse<String>> cf = client.sendAsync(req, HttpResponse.BodyHandlers.ofString());
int count = 0;
while (!cf.isDone()) {
System.out.println("Processing not done and doing other activity:" + ++count);
}
processResponse(cf.get());
}
public static void processResponse(HttpResponse resp) {
System.out.println("Status Code:" + resp.statusCode());
//System.out.println("Response Body:"+resp.body());
HttpHeaders header = resp.headers();
Map<String, List<String>> map = header.map();
System.out.println("Response Headers");
map.forEach((k, v) -> System.out.println("\t" + k + ":" + v));
}
}
package com.nisum.java9Features.http2;
import java.net.*;
import java.net.http.*;
import java.nio.file.*;
import java.util.*;
public class TestSync {
public static void main(String[] args) throws Exception {
String url = "https://www.redbus.in/info/aboutus";
sendGetSyncRequest(url);
}
public static void sendGetSyncRequest(String url) throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest req = HttpRequest.newBuilder(new URI(url)).GET().build();
HttpResponse resp = client.send(req, HttpResponse.BodyHandlers.ofString());
// HttpResponse resp1=client.send(req,HttpResponse.BodyHandlers.ofFile(Paths.get("abc.html")) );
processResponse(resp);
}
public static void processResponse(HttpResponse resp) {
System.out.println("Status Code:" + resp.statusCode());
//System.out.println("Response Body:" + resp.body());
HttpHeaders header = resp.headers();
Map<String, List<String>> map = header.map();
System.out.println("Response Headers");
map.forEach((k, v) -> System.out.println("\t" + k + ":" + v));
}
}
\ No newline at end of file
module demoModule
{
requires jdk.incubator.httpclient;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment