GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — initial commit · AlexGithubbb/JavaLearningPath@30e525e

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .idea
    • $PRODUCT_WORKSPACE_FILE$
    • .gitignore
    • encodings.xml
    • misc.xml
    • modules.xml
    • uiDesigner.xml
  • Exception
    • Exception.iml
    • src
      • practice/java
        • ExceptionPractice1.java
        • ExceptionPractice2.java
      • random/java
        • ExceptionTest.java
        • ExceptionTestTryCatch.java
        • FinallyTest.java
        • MyException.java
        • OverrideTest.java
        • StudentTest.java
        • ThrowsTest.java
    • test.txt
  • GenericsPart2
    • GenericsPart2.iml
    • src/alexpower/java
      • Player.java
  • Generics
    • Generics.iml
    • src
      • BoundedTypePrams.java
      • GenericMethods.java
      • GenericsTest.java
      • Generics_Inherit_Subtypes.java
      • RawTypes.java
      • TypeInference.java
      • WildCards.java
      • exer1
        • DAO.java
        • DAOTest.java
        • User.java
      • java2
        • Inheritence.java
  • IOStream
    • IOStream.iml
    • charCount.txt
    • data.txt
    • hello.txt
    • hello1.txt
    • hello2.txt
    • hello3.txt
    • hello4.txt
    • nature.jpg
    • nature1.jpg
    • nature2.0.jpg
    • nature_decrypt.jpg
    • nature_encrypt.jpg
    • randomTest.txt
    • randomTest2.txt
    • src
      • network/java
        • InetAddressTest.java
      • tutorial/java
        • BufferedTest.java
        • CharCountTest.java
        • DataInputOutputStreamTest.java
        • FileInputOutputStreamTest.java
        • FileReaderWriter.java
        • InputStreamReaderTest.java
        • MyInput.java
        • ObjectInputOutputStreamTest.java
        • OtherStreamTest.java
        • Person.java
        • PicTest.java
        • PrintStreamTest.java
        • RandomAccessFileTest.java
        • ScanXan.java
    • test.data
    • test.txt
    • test_gbk.txt
    • tiger.jpeg
    • xanadu.txt
  • Java-mWS.iml
  • StaticNonStatic
    • StaticNonStatic.iml
    • src/random/java
      • StaticNonStaticTest.java
  • String
    • String.iml
    • src/com/alexpower
      • exer
        • StringTest.java
      • java
        • Person.java
        • StringMethodTest.java
        • StringTest.java
  • day01
    • day01.iml
    • src/com/alexpower/java
      • HelloJava.java
  • out/production
    • Exception
      • practice/java
        • ExceptionPractice1.class
        • ExceptionPractice2.class
      • random/java
        • ExceptionTest.class
        • ExceptionTestTryCatch.class
        • FinallyTest.class
        • MyException.class
        • OverrideTest.class
        • Student.class
        • StudentTest.class
        • SubClass.class
        • SuperClass.class
        • ThrowsTest.class
    • GenericsPart2/alexpower/java
      • Player.class
    • Generics
      • BoundedTypePrams$Box$Comparable.class
      • BoundedTypePrams$Box$NaturalNumber.class
      • BoundedTypePrams$Box.class
      • BoundedTypePrams.class
      • GenericMethods$Pair.class
      • GenericMethods.class
      • GenericsTest$Box.class
      • GenericsTest$OrderPair.class
      • GenericsTest$Pair.class
      • GenericsTest.class
      • Generics_Inherit_Subtypes$Box.class
      • Generics_Inherit_Subtypes.class
      • RawTypes$Box.class
      • RawTypes.class
      • TypeInference$BoxDemo$Box.class
      • TypeInference$BoxDemo.class
      • TypeInference$MyClass.class
      • TypeInference.class
      • WildCards.class
      • exer1
        • DAO.class
        • DAOTest.class
        • User.class
      • java2
        • Inheritence.class
    • IOStream
      • network/java
        • InetAddressTest.class
      • tutorial/java
        • Account.class
        • BufferedTest.class
        • CharCountTest.class
        • DataInputOutputStreamTest.class
        • FileInputOutputStreamTest.class
        • FileReaderWriter.class
        • InputStreamReaderTest.class
        • MyInput.class
        • ObjectInputOutputStreamTest.class
        • OtherStreamTest.class
        • Person.class
        • PicTest.class
        • PrintStreamTest.class
        • RandomAccessFileTest.class
        • ScanXan.class
    • StaticNonStatic/random/java
      • StaticNonStaticTest.class
    • String/com/alexpower
      • exer
        • StringTest.class
      • java
        • Person.class
        • StringMethodTest.class
        • StringTest.class
    • day01/com/alexpower/java
      • HelloJava.class

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.idea/$PRODUCT_WORKSPACE_FILE$‎

Copy file name to clipboardExpand all lines: .idea/$PRODUCT_WORKSPACE_FILE$
+40Lines changed: 40 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/.gitignore‎

Copy file name to clipboardExpand all lines: .idea/.gitignore
+2Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/encodings.xml‎

Copy file name to clipboardExpand all lines: .idea/encodings.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/misc.xml‎

Copy file name to clipboardExpand all lines: .idea/misc.xml
+6Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/modules.xml‎

Copy file name to clipboardExpand all lines: .idea/modules.xml
+15Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/uiDesigner.xml‎

Copy file name to clipboardExpand all lines: .idea/uiDesigner.xml
+124Lines changed: 124 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎Exception/Exception.iml‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
14+
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>
Collapse file

‎Exception/src/practice/java/ExceptionPractice1.java‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package practice.java;
2+
3+
public class ExceptionPractice1 {
4+
static void methodA(){
5+
try {
6+
System.out.println("enter method A");
7+
throw new RuntimeException("create an exception in method A");
8+
}finally {
9+
System.out.println("finally method A");
10+
}
11+
}
12+
static void methodB(){
13+
try {
14+
System.out.println("enter method B");
15+
return;
16+
}finally {
17+
System.out.println("finally method B");
18+
}
19+
}
20+
21+
public static void main(String[] args) {
22+
// ExceptionPractice1 test = new ExceptionPractice1();
23+
try {
24+
methodA();
25+
}
26+
catch (Exception e){
27+
System.out.println(e.getMessage());
28+
}
29+
System.out.println("***************************");
30+
methodB();
31+
}
32+
33+
34+
}
Collapse file

‎Exception/src/practice/java/ExceptionPractice2.java‎

Copy file name to clipboard
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package practice.java;
2+
3+
import random.java.MyException;
4+
5+
public class ExceptionPractice2 {
6+
public static void main(String[] args) {
7+
try {
8+
int x = Integer.parseInt(args[0]);
9+
int y = Integer.parseInt(args[1]);
10+
11+
int result = ecm(x , y);
12+
System.out.println(result);
13+
}catch (NumberFormatException e){
14+
System.out.println("数据不一致");
15+
}catch (ArrayIndexOutOfBoundsException e){
16+
System.out.println("缺少命令行参数");
17+
}catch(ArithmeticException e){
18+
System.out.println("除0异常");
19+
}catch(MyException e){
20+
System.out.println(e.getMessage());
21+
}
22+
}
23+
24+
public static int ecm (int i, int j) throws MyException{
25+
if( i < 0 || j < 0){
26+
throw new MyException("both i and j should be positive value!");
27+
}
28+
return i/j;
29+
}
30+
}
Collapse file

‎Exception/src/random/java/ExceptionTest.java‎

Copy file name to clipboard
+85Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package random.java;
2+
3+
import org.junit.Test;
4+
5+
import java.util.Date;
6+
import java.util.Scanner;
7+
8+
public class ExceptionTest {
9+
/****************** 以下是编译时异常 checked ******************/
10+
11+
// @Test
12+
// public void test7(){
13+
// File file = new File("test.txt");
14+
// FileInputStream fis = new FileInputStream(file);
15+
//
16+
// int data = fis.read();
17+
// while (data!= -1){
18+
// System.out.println((char) data);
19+
// fis.read();
20+
// }
21+
// }
22+
23+
/****************** 以下是运行时异常 unchecked, RuntimeException ******************/
24+
@Test
25+
public void test1(){
26+
/* NullPointerException */
27+
int[] arr = null;
28+
System.out.println(arr[0]);
29+
}
30+
31+
/* IndexOutOfBoundsException */
32+
@Test
33+
public void test2(){
34+
/* ArrayIndexOutOfBoundsException */
35+
// int[] arr = new int[5];
36+
// System.out.println(arr[5]);
37+
38+
/* StringIndexOutOfBoundsException */
39+
String str = "hello";
40+
System.out.println(str.charAt(10));
41+
}
42+
43+
/* ClassCastException */
44+
@Test
45+
public void test3(){
46+
47+
// convert string to int
48+
String numStr = "123";
49+
int x = Integer.parseInt(numStr);
50+
System.out.println(x); // return a primitive int
51+
52+
int y = Integer.valueOf(numStr);
53+
System.out.println(y); // returns a Integer() object;
54+
55+
Object target = new Date();
56+
String str = (String) target;
57+
System.out.println(str);
58+
}
59+
60+
/* NumberFormatException */
61+
@Test
62+
public void test4(){
63+
String str = "10A";
64+
int x = Integer.valueOf(str);
65+
System.out.println(x);
66+
}
67+
68+
/* InputMisMatchException */
69+
70+
@Test
71+
public void test5(){
72+
Scanner scanner = new Scanner(System.in);
73+
int x = scanner.nextInt(); // if user's input is not an integer, will pop up the exception
74+
System.out.println(x);
75+
scanner.close();
76+
}
77+
78+
/* ArithmeticException */
79+
@Test
80+
public void test6(){
81+
int a = 9;
82+
int b = 0;
83+
System.out.println(a / b);
84+
}
85+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.