Skip to content

Commit b99b123

Browse files
author
bhuwang
committed
updated the code examples
1 parent daabb35 commit b99b123

14 files changed

+137
-27
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ hs_err_pid*
1414
/target/
1515
.project
1616
.classpath
17-
.settings*
17+
.settings*
18+
.idea*

application.properties

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Updated by Suman Gurung
2+
#Fri Aug 12 14:20:31 NPT 2016
3+
user=Bhuwan Gautam
4+
pass=password12345678

file_writer_demo1.txt

Whitespace-only changes.

playground.iml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
4+
<output url="file://$MODULE_DIR$/target/classes" />
5+
<output-test url="file://$MODULE_DIR$/target/test-classes" />
6+
<content url="file://$MODULE_DIR$">
7+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
8+
<excludeFolder url="file://$MODULE_DIR$/target" />
9+
</content>
10+
<orderEntry type="inheritedJdk" />
11+
<orderEntry type="sourceFolder" forTests="false" />
12+
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.38" level="project" />
13+
<orderEntry type="library" name="Maven: commons-io:commons-io:1.3.2" level="project" />
14+
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
15+
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
16+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-java:2.52.0" level="project" />
17+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-chrome-driver:2.52.0" level="project" />
18+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-remote-driver:2.52.0" level="project" />
19+
<orderEntry type="library" name="Maven: cglib:cglib-nodep:2.1_3" level="project" />
20+
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.3.1" level="project" />
21+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-api:2.52.0" level="project" />
22+
<orderEntry type="library" name="Maven: com.google.guava:guava:19.0" level="project" />
23+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-edge-driver:2.52.0" level="project" />
24+
<orderEntry type="library" name="Maven: org.apache.commons:commons-exec:1.3" level="project" />
25+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0" level="project" />
26+
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit:2.18" level="project" />
27+
<orderEntry type="library" name="Maven: xalan:xalan:2.7.2" level="project" />
28+
<orderEntry type="library" name="Maven: xalan:serializer:2.7.2" level="project" />
29+
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.4" level="project" />
30+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.5" level="project" />
31+
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
32+
<orderEntry type="library" name="Maven: net.sourceforge.htmlunit:htmlunit-core-js:2.17" level="project" />
33+
<orderEntry type="library" name="Maven: xerces:xercesImpl:2.11.0" level="project" />
34+
<orderEntry type="library" name="Maven: xml-apis:xml-apis:1.4.01" level="project" />
35+
<orderEntry type="library" name="Maven: net.sourceforge.nekohtml:nekohtml:1.9.22" level="project" />
36+
<orderEntry type="library" name="Maven: net.sourceforge.cssparser:cssparser:0.9.16" level="project" />
37+
<orderEntry type="library" name="Maven: org.w3c.css:sac:1.3" level="project" />
38+
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
39+
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.2.12.v20150709" level="project" />
40+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.2.12.v20150709" level="project" />
41+
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.2.12.v20150709" level="project" />
42+
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.2.12.v20150709" level="project" />
43+
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.2.12.v20150709" level="project" />
44+
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
45+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.1" level="project" />
46+
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.3" level="project" />
47+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-firefox-driver:2.52.0" level="project" />
48+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-ie-driver:2.52.0" level="project" />
49+
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:4.1.0" level="project" />
50+
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:4.1.0" level="project" />
51+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-safari-driver:2.52.0" level="project" />
52+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-support:2.52.0" level="project" />
53+
<orderEntry type="library" name="Maven: org.webbitserver:webbit:0.4.14" level="project" />
54+
<orderEntry type="library" name="Maven: io.netty:netty:3.5.2.Final" level="project" />
55+
<orderEntry type="library" name="Maven: org.seleniumhq.selenium:selenium-leg-rc:2.52.0" level="project" />
56+
<orderEntry type="library" name="Maven: postgresql:postgresql:9.1-901-1.jdbc4" level="project" />
57+
<orderEntry type="library" name="Maven: com.alexkasko.unsafe:unsafe-tools:1.4.4" level="project" />
58+
<orderEntry type="library" name="Maven: org.glassfish.main.persistence:glassfish-oracle-jdbc-driver-packages:4.1.1" level="project" />
59+
<orderEntry type="module-library">
60+
<library name="Maven: com.sun:tools-jar:1">
61+
<CLASSES>
62+
<root url="jar://$MODULE_DIR$/../../tools/jdk1.8.0_65/jre/../lib/tools.jar!/" />
63+
</CLASSES>
64+
<JAVADOC />
65+
<SOURCES />
66+
</library>
67+
</orderEntry>
68+
</component>
69+
</module>

pom.xml

+7
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,12 @@
5050
<artifactId>unsafe-tools</artifactId>
5151
<version>1.4.4</version>
5252
</dependency>
53+
<dependency>
54+
<groupId>org.glassfish.main.persistence</groupId>
55+
<artifactId>
56+
glassfish-oracle-jdbc-driver-packages
57+
</artifactId>
58+
<version>4.1.1</version>
59+
</dependency>
5360
</dependencies>
5461
</project>

src/com/bhuwan/java/basics/oop/applicationflow/InstanceControlFlowDemo.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
/**
2-
*
2+
*
33
*/
44
package com.bhuwan.java.basics.oop.applicationflow;
55

66
/**
77
* Here all we have declared is instance blocks. Since we have not created any object then there is no chance of executing instance block.
88
* Hence the output only be "Main method."
9-
*
10-
* @author bhuwan
119
*
10+
* @author bhuwan
1211
*/
1312
public class InstanceControlFlowDemo {
1413

src/com/bhuwan/java/basics/oop/overriding/OverridingDemo.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class OverridingDemo {
1515
* Method Hiding: Only hiding the parent method by child method (Both the methods are available). You can get child method by child reference
1616
* and parent method by parent reference.
1717
*
18-
* Thump Rules:
18+
* Thumb Rules:
1919
* 1. In overriding method resolution is always based on runtime object.
2020
* 2. In overloading method resolution is always based on reference object.
2121
* </pre>
@@ -57,3 +57,11 @@ public void marriage() {
5757
System.out.println("Marriage with Priyanka Karki.");
5858
}
5959
}
60+
61+
class AnotherChildClass extends ParentClass {
62+
63+
@Override
64+
public void marriage() {
65+
System.out.println("Marriage with XYZ.");
66+
}
67+
}

src/com/bhuwan/java/collection/hashtable/PropertiesDemo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static void main(String[] args) throws FileNotFoundException, IOException
2727

2828
System.out.println("user: " + prop.getProperty("user"));
2929
prop.setProperty("pass", "password12345678");
30-
prop.store(new FileOutputStream("src/com/bhuwan/java/collection/hashtable/application.properties"), "Updated by Suman Gurung");
30+
prop.store(new FileOutputStream("application.properties"), "Updated by Suman Gurung");
3131
}
3232

3333
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#Updated by Suman Gurung
2-
#Thu Jun 23 19:44:39 NPT 2016
2+
#Fri Aug 12 14:19:52 NPT 2016
33
user=Bhuwan Gautam
44
pass=password12345678

src/com/bhuwan/java/jdbc/BatchProcessingComparision.java

+10-15
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ public static void main(String[] args) {
2727
batchProcessingWithStatement(con);
2828
batchProcessingWithPreparedStatement(con);
2929
LOGGER.info("Execution Completed Successfully........................");
30-
}
31-
catch (SQLException e) {
30+
} catch (SQLException e) {
3231
e.printStackTrace();
3332
LOGGER.info("Excepton occured while processing data." + e.getMessage() + " :: " + e.getClass());
3433
}
@@ -37,9 +36,8 @@ public static void main(String[] args) {
3736
private static void processingWithStatement(Connection con) throws SQLException {
3837
try (Statement stmt = con.createStatement();) {
3938
long start = System.currentTimeMillis();
40-
for (int i = 0; i < 500; i++) {
41-
String query = "insert into user(username, password, fullname) values ('username" + i
42-
+ "','password','fullname')";
39+
for (int i = 0; i < 1200; i++) {
40+
String query = "insert into user(username, password, fullname) values ('username" + i + "','password','fullname')";
4341
stmt.executeUpdate(query);
4442
}
4543
System.out.println("Processing with Statement - Time Taken=" + (System.currentTimeMillis() - start));
@@ -53,21 +51,19 @@ private static void processingWithPreparedStatement(Connection con) throws SQLEx
5351
stmt.setString(1, "username");
5452
stmt.setString(2, "password");
5553
stmt.setString(3, "fullname");
56-
for (int i = 0; i < 500; i++) {
54+
for (int i = 0; i < 1200; i++) {
5755
stmt.executeUpdate();
5856
}
59-
System.out
60-
.println("Processing with PreparedStatement - Time Taken=" + (System.currentTimeMillis() - start));
57+
System.out.println("Processing with PreparedStatement - Time Taken=" + (System.currentTimeMillis() - start));
6158
}
6259

6360
}
6461

6562
private static void batchProcessingWithStatement(Connection con) throws SQLException {
6663
try (Statement stmt = con.createStatement();) {
6764
long start = System.currentTimeMillis();
68-
for (int i = 0; i < 500; i++) {
69-
String query = "insert into user(username, password, fullname) values ('username" + i
70-
+ "','password','fullname')";
65+
for (int i = 0; i < 1200; i++) {
66+
String query = "insert into user(username, password, fullname) values ('username" + i + "','password','fullname')";
7167
stmt.addBatch(query);
7268
if (i % 100 == 0) {
7369
stmt.executeBatch();
@@ -82,17 +78,16 @@ private static void batchProcessingWithPreparedStatement(Connection con) throws
8278
String sql = "insert into user(username, password, fullname) values (?,?,?)";
8379
try (PreparedStatement stmt = con.prepareStatement(sql);) {
8480
long start = System.currentTimeMillis();
85-
for (int i = 0; i < 500; i++) {
86-
stmt.setString(1, "username"+i);
81+
for (int i = 0; i < 1200; i++) {
82+
stmt.setString(1, "username" + i);
8783
stmt.setString(2, "password");
8884
stmt.setString(3, "fullname");
8985
stmt.addBatch();
9086
if (i % 100 == 0) {
9187
stmt.executeBatch();
9288
}
9389
}
94-
System.out.println("Batch Processing with PreparedStatement - Time Taken="
95-
+ (System.currentTimeMillis() - start));
90+
System.out.println("Batch Processing with PreparedStatement - Time Taken=" + (System.currentTimeMillis() - start));
9691
}
9792

9893
}

src/com/bhuwan/java/jdbc/ConnectionDemo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class ConnectionDemo {
1919
*/
2020
public static void main(String[] args) {
2121
try (Connection con = DBConnection.getMySqlConnection(); Statement stmt = con.createStatement();) {
22-
stmt.execute("create table tbl_one(id int primary key)");
22+
stmt.execute("create table tbl_one_onee(id int primary key)");
2323
LOGGER.info("Table created successfully");
2424
} catch (SQLException e) {
2525
e.printStackTrace();

src/com/bhuwan/java/jdbc/DBConnection.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class DBConnection {
1616
private static final Logger LOGGER = Logger.getLogger(DBConnection.class.getName());
1717

1818
private static final String MYSQL_DRIVER = "com.mysql.jdbc.Driver";
19-
// private static final String MYSQL_CONNECTION_STRING="jdbc:mysql://localhost:3306/playground";
19+
// private static final String MYSQL_CONNECTION_STRING = "jdbc:mysql://localhost:3306/playground";
2020
private static final String MYSQL_CONNECTION_STRING = "jdbc:mysql://localhost:3306/playground?rewriteBatchedStatements=true";
2121
private static final String USERNAME = "root";
2222
private static final String PASSWORD = "liferay";
@@ -35,9 +35,9 @@ public static void main(String[] args) {
3535
public static Connection getMySqlConnection() {
3636
Connection connection = null;
3737
try {
38-
Class.forName(MYSQL_DRIVER);
38+
// Class.forName(MYSQL_DRIVER);
3939
connection = DriverManager.getConnection(MYSQL_CONNECTION_STRING, USERNAME, PASSWORD);
40-
} catch (SQLException | ClassNotFoundException e) {
40+
} catch (SQLException e) {
4141
LOGGER.log(Level.SEVERE,
4242
"DBConnection#getConnection exception occured - Class: " + e.getClass() + " message: " + e.getMessage());
4343
}

src/com/bhuwan/java/jvm/loading/DifferentClassLoaderDemo.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public static void main(String[] args) {
1717
* Bootstrap class loader
1818
*/
1919
// it should return null since it is not implemented in java.
20-
System.out.println(String.class.getClassLoader());
20+
System.out.println(Double.class.getClassLoader());
2121

2222
/*
2323
* Ext class loader
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
*
3+
*/
4+
package com.bhuwan.java.reflection;
5+
6+
import java.lang.invoke.MethodHandle;
7+
import java.lang.invoke.MethodHandles;
8+
import java.lang.invoke.MethodHandles.Lookup;
9+
import java.lang.invoke.MethodType;
10+
11+
/**
12+
* @author bhuwan
13+
*
14+
*/
15+
public class MethodHandleDemo {
16+
17+
public static void main(String[] args) throws Throwable {
18+
Lookup lookup = MethodHandles.lookup();
19+
MethodHandle findStatic = lookup.findStatic(MethodHandleDemo.class, "hello", MethodType.methodType(void.class));
20+
findStatic.invoke();
21+
}
22+
23+
static void hello() {
24+
System.out.println("hello");
25+
}
26+
27+
}

0 commit comments

Comments
 (0)