Review of java Shilber


import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;


import java.time.*;


import java.time.format.*;

class A{
    
    int A=100;
    public void test(){
        System.out.println("testA");
    }
    
    public void test2(){
        System.out.println("test2");
    }
}

class B extends A{ 
    int A=1000;
    public void test(){
        System.out.println("testB");
    }
    
    public void test3(){
        System.out.println("test3");
    }
   
}

class c extends A{ 
    int A=1000;
    public void test(){
        System.out.println("testc");
    }
    
    public void test4(){
        System.out.println("testc");
    }
   
}


//If you prepare a constructor in the superclass, it will always be called by the super in the derived class, but if there is no argument, it will be called explicitly.
//It is not necessary, and it is OK to call the constructor of the superclass when moving to another constructor with this etc.
class spclass { 
    int A=1000;
    
    spclass(String s){
        System.out.println("Superclass constructor");
    }
   
}

class konsutoTest extends spclass{ 
    int A=1000;
    
    konsutoTest(){
        this("s");
        System.out.println("Derived class constructor");
    }
    
     konsutoTest(String s){
        super("s");
        System.out.println("Derived class constructor");
    }
}

interface intaTest{
    public void process(); //Public if nothing is attached to the modifier
}

class Sample implements intaTest{
    public void process(){}; //You have to be public or strong
}




public class Main {
    
    protected static int st;
    protected static boolean bl;
    protected static int[] bll;
    protected static String stt;
    protected static ArrayList ALL;
    protected static ArrayList ALL2;
    protected static StringBuilder stb=new StringBuilder(5);

    
    public static void main(String[] args) throws Exception {
        
        //Review of default constructor
        new konsutoTest();
        
        //Polyforism
        //Put an instance of B in A, but in the end the instance of B is just a diff of A
        //If you put it in the box of A, you can only see the thing of A, but the overridden method is reflected in A
        //Since the value of the field is output according to the box, be careful if it is overridden if there is a problem with politics.
        A a=new B();
        
        a.test();
        a.test2();
        System.out.println(a.A);
        
        B b=(B)a;
        b.test3();
        
        System.out.println(b.A);
        // Your code here!
        
        //Date problem
        //LocalDateTime date = LocalDateTime.of(2015,9,15,1,1);
        LocalDate date = LocalDate.of(2015,9,15);
        System.out.println(date);
        System.out.println(date.format(DateTimeFormatter.ISO_DATE));
        
        double ddd=10.1d;
        float fff=10f;
        int iii=100;
        String sss;
        long lll=10;
        
        ddd=fff;//Small to big is OK
        fff=(float)ddd;//Cast from big to small
        
        ddd=iii;
        iii=(int)ddd;//When cast, it loses digits
        
        double v=10.0+10;//because int is in double
        
        long l=10+10;//Because the int type implicitly changes to LONG
        
        lll=lll+iii;//It's okay because long also contains int
        
        
        
        System.out.println("StringBuilder<StringBuilder> =initial value" + stb.toString() +"StringBuilder<StringBuilder> =number" +stb.length());//NULL because it is a reference type
        
        
        try{
        RuntimeExceptionTest();
        }
        catch(RuntimeException e){
            System.out.println(e);
        }
        
                
        try{
            
        bll=new int[3];
        
        ArrayList<Integer> ll = new ArrayList<Integer>();
        ArrayList<String> list = new ArrayList<>();//No because there is a type designation
        ArrayList list2 = new ArrayList();//Anything is OK because it is generic and no type is specified
        
        System.out.println("ArrayList<Integer> =" + ALL2);//NULL because it is a reference type
        System.out.println(list);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
        
        ll.add(10);
        list.add("10");
        list2.add('B');

        System.out.println(ALL2);//NULL because it is a reference type
        System.out.println("ArrayList<Integer> =" + ll);//NULL because it is a reference type
        System.out.println("ArrayList<String>=" + list);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
        
        System.out.println("string=" + stt);//NULL because it is a reference type
        System.out.println("array=" + ALL);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
        
        System.out.println(bl);
        
        System.out.println(bll[0]);
        System.out.println(bll.length + "← Number of arrays Contents" + bll[0]);//You can get the number with just the instance of the array. The contents are initialized with 0.
        System.out.println(args);//args must be int[0]Make a hash code with 0 numbers
        

        //Exceptional practice

        Main.test();
        System.out.println("XXXXXXXX");

        }
        catch(RuntimeException e){
            System.out.println(e);
            
        }
        catch(Exception e){
            System.out.println("Not reachable");
            
        }
        
        
    }
    
    public static void RuntimeExceptionTest()
    {
        //Unchecked exception: You don't have to throw it, catch it at the caller
        //It is not necessary to describe it.

        if(2==1)
        {
            throw new RuntimeException();
        }
        else{
            throw new NullPointerException();
        }
       
    }
    
    public static void test() throws Exception
    {
        //throws throws an error to the caller for processing by the caller
        st=100;
        if(1==1)
        {
            throw new RuntimeException();
        }
        else
        {
            throw new Exception();
        }
        
    }
    
}


Recommended Posts

Review of java Shilber
NIO.2 review of java
NIO review of java
Java review
Java IO review
[Java] Overview of Java
Expired collection of java
Predicted Features of Java
java --Unification of comments
Java NIO 2 review notes
Java inner class review
History of Java annotation
java (merits of polymorphism)
A quick review of Java learned in class
Review Java annotations now
Review java8 ~ Lambda expression ~
[Java] Three features of Java
Summary of Java support 2018
Java review ③ (Basic usage of arrays / reference type)
A quick review of Java learned in class part4
[Java] About Objects.equals () and Review of String comparisons (== and equals)
A quick review of Java learned in class part3
A quick review of Java learned in class part2
About an instance of java
[Java] Beginner's understanding of Servlet-②
[Java] Practice of exception handling [Exception]
[Java11] Stream Summary -Advantages of Stream-
Basics of character operation (java)
Progate Java (Beginner) Review & Summary
[Java] Creation of original annotation
4th day of java learning
[Java] Beginner's understanding of Servlet-①
Java end of month plusMonths
Java Collections Framework Review Notes
[Java] Summary of regular expressions
[Java] Summary of operators (operator)
[Java] Implementation of Faistel Network
[Java] Comparator of Collection class
Summary of Java language basics
[Java] Summary of for statements
Summary of Java Math class
Enumeration of all combinations Java
java (inheritance of is-a principle)
Implementation of gzip in java
Advantages and disadvantages of Java
Benefits of Java static method
[Java] Summary of control syntax
Implementation of tri-tree in Java
Summary of java error processing
[Java] Summary of design patterns
[Java] Summary of mathematical operations
Review of Ruby basic grammar
[Java] Speed comparison of string concatenation
Think of a Java update strategy
[Java] Delete the elements of List
[For beginners] Summary of java constructor
Various methods of Java String class
Root cause of java framework bugs
About fastqc of Biocontainers and Java
[Java version] The story of serialization
Summary of [Java silver study] package