Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2f35ff

Browse files
committed
CoreJava
CoreJava Examples
1 parent 45a9ffc commit d2f35ff

File tree

121 files changed

+1808
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1808
-0
lines changed

.classpath

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
5+
<classpathentry kind="lib" path="lib/json-simple-1.1.jar"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

.project

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>CoreJava</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

bin/Alpha.class

343 Bytes
Binary file not shown.

bin/App.class

1.5 KB
Binary file not shown.

bin/Beta.class

329 Bytes
Binary file not shown.

bin/Calculator.class

767 Bytes
Binary file not shown.

bin/Camel.class

1.03 KB
Binary file not shown.

bin/Cougar.class

928 Bytes
Binary file not shown.

bin/Feline.class

465 Bytes
Binary file not shown.

bin/Gamma.class

948 Bytes
Binary file not shown.

bin/MyStuff.class

884 Bytes
Binary file not shown.

bin/Rideable.class

135 Bytes
Binary file not shown.

bin/Test.class

519 Bytes
Binary file not shown.

bin/algorithm/Employee.class

1.38 KB
Binary file not shown.

bin/algorithm/FibonacciSeries.class

979 Bytes
Binary file not shown.

bin/algorithm/Md5Testing.class

1.6 KB
Binary file not shown.

bin/algorithm/PalindromeTest.class

1.4 KB
Binary file not shown.

bin/algorithm/ReverseString.class

2.28 KB
Binary file not shown.

bin/algorithm/ThreadTest.class

1.58 KB
Binary file not shown.
950 Bytes
Binary file not shown.
1.37 KB
Binary file not shown.
1.59 KB
Binary file not shown.
1.17 KB
Binary file not shown.

bin/collectiontest/NameList.class

2.04 KB
Binary file not shown.

bin/hackerrank/PrimeCheck.class

1.38 KB
Binary file not shown.
1.35 KB
Binary file not shown.
1.21 KB
Binary file not shown.
1.55 KB
Binary file not shown.
1.98 KB
Binary file not shown.
1.51 KB
Binary file not shown.

bin/java6/Animal.class

522 Bytes
Binary file not shown.

bin/java6/Autoboxing_test.class

740 Bytes
Binary file not shown.

bin/java6/CarBoard.class

892 Bytes
Binary file not shown.

bin/java6/Dog.class

946 Bytes
Binary file not shown.

bin/java6/Dozens.class

358 Bytes
Binary file not shown.

bin/java6/Dudes.class

946 Bytes
Binary file not shown.

bin/java6/DudesChat.class

867 Bytes
Binary file not shown.

bin/java6/Ebb.class

1.2 KB
Binary file not shown.

bin/java6/Eggs.class

484 Bytes
Binary file not shown.

bin/java6/Element.class

707 Bytes
Binary file not shown.

bin/java6/FileIOExample.class

924 Bytes
Binary file not shown.

bin/java6/IkmTest$Helper.class

571 Bytes
Binary file not shown.

bin/java6/IkmTest.class

4.43 KB
Binary file not shown.

bin/java6/JSONTest.class

1.13 KB
Binary file not shown.

bin/java6/OverAndOver.class

1.42 KB
Binary file not shown.

bin/java6/Practice.class

1.17 KB
Binary file not shown.

bin/java6/ReadingFor.class

1.03 KB
Binary file not shown.

bin/java6/Regex2.class

1.82 KB
Binary file not shown.

bin/java6/SuperClass.class

734 Bytes
Binary file not shown.

bin/java6/Test1.class

831 Bytes
Binary file not shown.

bin/java6/TestException.class

1.12 KB
Binary file not shown.

bin/java6/ThreadTest.class

1.31 KB
Binary file not shown.

bin/java6/Two.class

264 Bytes
Binary file not shown.

bin/java6/WordCount.class

3.62 KB
Binary file not shown.

bin/java6/interface1.class

107 Bytes
Binary file not shown.

bin/java6/passO.class

1.17 KB
Binary file not shown.

bin/java8/A.class

398 Bytes
Binary file not shown.

bin/java8/B.class

398 Bytes
Binary file not shown.

bin/java8/Base64Test.class

2.03 KB
Binary file not shown.

bin/java8/Child.class

611 Bytes
Binary file not shown.

bin/java8/DateTimeTest.class

2.73 KB
Binary file not shown.

bin/java8/Examjava8.class

2.01 KB
Binary file not shown.

bin/java8/Indices.class

323 Bytes
Binary file not shown.
242 Bytes
Binary file not shown.
221 Bytes
Binary file not shown.

bin/java8/Java8Tester.class

2.87 KB
Binary file not shown.

bin/java8/MethodRef.class

1.33 KB
Binary file not shown.

bin/java8/Nasdaq.class

1.78 KB
Binary file not shown.

bin/java8/StreamExample.class

2.71 KB
Binary file not shown.

lib/json-simple-1.1.jar

15.7 KB
Binary file not shown.

sample.txt

Whitespace-only changes.

sample1.txt

Whitespace-only changes.

src/App.java

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
public class App {
3+
public static void main(String[] args) {
4+
HashMap<Integer,String> p = new HashMap<Integer,String>();
5+
p.put(7,"A");
6+
p.put(1,"B");
7+
p.put(5,"C");
8+
p.put(1,"D");
9+
p.remove(1);
10+
System.out.println(p);
11+
12+
String[] sa = {"tom ", "jerry "};
13+
for (int x = 0; x < 3; x++) {
14+
for (String s : sa) {
15+
System.out.print(x + " " + s);
16+
if (x == 1) {
17+
break;
18+
}
19+
}
20+
}
21+
22+
}
23+
}

src/Calculator.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Calculator {
2+
int num = 100;
3+
public void calc(int num) {
4+
this.num = num * 10;
5+
}
6+
public void printNum(){
7+
System.out.println(num);
8+
}
9+
public static void main(String[] args) {
10+
Calculator obj = new Calculator ();
11+
obj.calc(2);
12+
obj.printNum();
13+
}
14+
}

src/Camel.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
interface Rideable {
2+
String getGait();
3+
}
4+
5+
public class Camel implements Rideable {
6+
int weight = 2;
7+
public String getGait() {
8+
return " mph, lope";
9+
}
10+
void go(int speed) {
11+
++speed; weight++;
12+
int walkrate = speed * weight;
13+
System.out.print(walkrate + getGait());
14+
}
15+
public static void main(String[] args) {
16+
new Camel().go(8);
17+
}
18+
}

src/Cougar.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Feline {
2+
public String type = "f ";
3+
public Feline() {
4+
System.out.print("feline ");
5+
}
6+
}
7+
public class Cougar extends Feline {
8+
public Cougar() {
9+
System.out.print("cougar ");
10+
}
11+
void go() {
12+
type = "c ";
13+
System.out.print(this.type + super.type);
14+
}
15+
public static void main(String[] args) {
16+
new Cougar().go();
17+
}
18+
}

src/Gamma.java

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Alpha {
2+
String getType() {
3+
return "alpha";
4+
}
5+
}
6+
class Beta extends Alpha {
7+
String getType() {
8+
return "beta";
9+
}
10+
}
11+
public class Gamma extends Beta {
12+
String getType() {
13+
return "gamma";
14+
}
15+
public static void main(String[] args) {
16+
//Gamma g1 = new Alpha();
17+
//Gamma g2 = new Beta();
18+
19+
Alpha g1 = new Gamma();
20+
Beta g2 = new Gamma();
21+
System.out.println(g1.getType() + " "
22+
+ g2.getType());
23+
}
24+
}

src/MyStuff.java

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class MyStuff {
2+
String name;
3+
MyStuff(String n) {
4+
name = n;
5+
}
6+
public static void main(String[] args) {
7+
MyStuff m1 = new MyStuff("guitar");
8+
MyStuff m2 = new MyStuff("tv");
9+
System.out.println(m2.equals(m1));
10+
}
11+
public boolean equals(Object o) {
12+
MyStuff m = (MyStuff) o;
13+
if (m.name != null) {
14+
return true;
15+
}
16+
return false;
17+
}
18+
}

src/Test.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
public class Test {
3+
4+
public static void main(String[] args) {
5+
// TODO Auto-generated method stub
6+
7+
System.out.println("Hi This is Test");
8+
9+
}
10+
11+
}

src/algorithm/FibonacciSeries.java

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package algorithm;
2+
3+
public class FibonacciSeries {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
for(int i=1;i<10; i++){
8+
System.out.println(fibonacci2(i));
9+
}
10+
}
11+
12+
public static int fibonacci(int n){
13+
if(n == 1 || n == 2){
14+
return 1;
15+
}
16+
return fibonacci(n-1) + fibonacci(n-2);
17+
}
18+
19+
public static int fibonacci2(int n){
20+
if(n == 1 || n == 2){
21+
return 1;
22+
}
23+
int sum = 1;
24+
int f1 = 1;
25+
int f2 = 1;
26+
for(int i = 3; i <= n;i++){
27+
sum = f1 + f2;
28+
f1 = f2;
29+
f2 = sum;
30+
}
31+
return sum;
32+
}
33+
34+
}

src/algorithm/Md5Testing.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package algorithm;
2+
3+
import java.io.FileInputStream;
4+
import java.security.MessageDigest;
5+
import java.util.Scanner;
6+
7+
public class Md5Testing {
8+
9+
public static void main(String[] args) {
10+
// TODO Auto-generated method stub
11+
12+
13+
MessageDigest md;
14+
try {
15+
FileInputStream fis;
16+
Scanner scanner = new Scanner(System.in);
17+
byte[] bytesOfMessage = scanner.next().getBytes("UTF-8");
18+
md = MessageDigest.getInstance("MD5");
19+
byte[] mdbytes = md.digest(bytesOfMessage);
20+
21+
//convert the byte to hex format method 1
22+
StringBuffer sb = new StringBuffer();
23+
for (int i = 0; i < mdbytes.length; i++) {
24+
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
25+
}
26+
27+
System.out.println(sb.toString());
28+
29+
} catch (Exception e) {
30+
// TODO Auto-generated catch block
31+
e.printStackTrace();
32+
}
33+
34+
}
35+
36+
}

src/algorithm/PalindromeTest.java

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package algorithm;
2+
3+
import java.util.Scanner;
4+
5+
public class PalindromeTest{
6+
7+
public static void main(String[] args){
8+
//Scanner scanner = new Scanner(System.in);
9+
int[] numbers = {1, 20, 22, 102, 101, 1221, 13321, 13331, 0, 11};
10+
11+
for(int i : numbers){
12+
System.out.println(" number " + i + " palindrome result is :"+ isPalindrome(i));
13+
}
14+
}
15+
public static boolean isPalindrome(int number){
16+
if(number == reverse(number)){
17+
return true;
18+
}
19+
return false;
20+
}
21+
22+
public static int reverse(int number){
23+
int reverse = 0;
24+
25+
while(number != 0){
26+
System.out.println("number:"+number+ ",reverse:" + reverse +",reverse*10:"+(reverse*10) + ",number%10 :"+(number%10));
27+
reverse = reverse*10 + number%10;
28+
number = number/10;
29+
}
30+
return reverse;
31+
}
32+
}

src/algorithm/ReverseString.java

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package algorithm;
2+
3+
public class ReverseString {
4+
5+
public static void main(String args[]) {
6+
7+
//original string
8+
String str = "Sony is going to introduce Internet TV soon";
9+
System.out.println("Original String: " + str);
10+
11+
//reversed string using Stringbuffer
12+
String reverseStr = new StringBuffer(str).reverse().toString();
13+
System.out.println("Reverse String in Java using StringBuffer: " + reverseStr);
14+
15+
//iterative method to reverse String in Java
16+
reverseStr = reverse(str);
17+
System.out.println("Reverse String in Java using Iteration: " + reverseStr);
18+
19+
//recursive method to reverse String in Java
20+
reverseStr = reverseRecursively(str);
21+
System.out.println("Reverse String in Java using Recursion: " + reverseStr);
22+
23+
str = "abc";
24+
System.out.println("str.length()" + str.length());
25+
System.out.println("str.substring(0)" + str.substring(0));
26+
System.out.println("str.substring(1)" + str.substring(1));
27+
28+
System.out.println("str.substring(0,str.length())" + str.substring(0,str.length()));
29+
System.out.println("str.substring(0,str.length()-1)" + str.substring(0,str.length() -1));
30+
System.out.println("str.substring(1,3)" + str.substring(1,3));
31+
32+
}
33+
34+
public static String reverse(String str) {
35+
StringBuilder strBuilder = new StringBuilder();
36+
char[] strChars = str.toCharArray();
37+
38+
for (int i = strChars.length - 1; i >= 0; i--) {
39+
strBuilder.append(strChars[i]);
40+
}
41+
42+
return strBuilder.toString();
43+
}
44+
45+
public static String reverseRecursively(String str) {
46+
47+
// System.out.println(" reverseRecursively Calling str: "+ str);
48+
//base case to handle one char string and empty string
49+
if (str.length() < 2) {
50+
// System.out.println(" reverseRecursively returing str: "+ str);
51+
return str;
52+
}
53+
// System.out.println(" reverseRecursively befor returing str.substring(1): "+ str.substring(1) + ", str.charAt(0):"+ str.charAt(0));
54+
return reverseRecursively(str.substring(1)) + str.charAt(0);
55+
56+
}
57+
}

0 commit comments

Comments
 (0)