Сообщения

Сообщения за май, 2021

Inheritance

      You can only specify one superclass for any subclass that you create. Java does not support the inheritance of multiple superclasses into a single subclass.     Super. Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.    super has two general forms. The first calls the superclass' constructor. The second is used to access a member of the superclass that has been hidden by a member of a subclass. package main ; public class Car { private int a ; public Car ( int a ) { this . a = a ; } } package main ; public class BMW extends Car { public BMW ( int a ) { super ( a ) ; } } Also, super() must always be the first statement executed inside a subclass constructor. The second form of super acts somewhat like this , except that is always refers to the superclass of the subclass in which it is used. This second form of super is most applicable to situations in which member names of a class hide

JVM, JRE, JDK, IDE

Изображение
  %3CmxGraphModel%3E%3Croot%3E%3CmxCell%20id%3D%220%22%2F%3E%3CmxCell%20id%3D%221%22%20parent%3D%220%22%2F%3E%3CmxCell%20id%3D%222%22%20value%3D%22code%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%2220%22%20y%3D%22140%22%20width%3D%2260%22%20height%3D%2250%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%223%22%20value%3D%22javac%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22160%22%20y%3D%22140%22%20width%3D%2260%22%20height%3D%2250%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%224%22%20value%3D%22JVM%22%20style%3D%22rounded%3D0%3BwhiteSpace%3Dwrap%3Bhtml%3D1%3B%22%20vertex%3D%221%22%20parent%3D%221%22%3E%3CmxGeometry%20x%3D%22440%22%20y%3D%22140%22%20width%3D%2260%22%20height%3D%2250%22%20as%3D%22geometry%22%2F%3E%3C%2FmxCell%3E%3CmxCell%20id%3D%225%22%20value%3D%22byte%20code%22%20style%3D%22r

String class

 The objects of type String are immutable; once a String object is created, its contents cannot be altered.

Classes, methods, access control

       The data, or variables, defined within a class are called INSTANCE variables. The code is contained within methods. Collectively, the methods and variables defined within a class are called members of the class.     A parameter is a variable defined by a method that receives a value when the method is called.     An argument is a value that is passed to a method when it is invoked.     Garbage collection only occurs sporadically (if at all) during the execution of your program. It will not occur simply because one or more objects exist that are no longer used. package main ; public class Test { int a , b ; Test ( int i , int j ) { a = i ; b = j ; } boolean equalTo ( Test o ) { if ( o . a == a && o . b == b ) return true ; else return false ; } } package main ; public class Main { public static void main ( String [] args ) throws Exception { Test ob1 = new Test( 100 , 22 ) ; Test ob2 = new Test( 100 ,

How to change java.util.Date --->>> java.sql.Date

SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd" ) ; Date date = sdf .parse( "1991-11-02" ) ; java.sql.Date sqlDate = new java.sql. Date( date .getTime()) ; } }  

Collections

This is my simulation if Array class. package main ; public class MyArrayList { private Object [] elementData = new Object[ 10 ] ; int size = 0 ; public void add ( Object element ) { ensureCapacity() ; elementData [ size ++] = element ; } public void ensureCapacity () { if ( size == elementData . length ) { Object [] arr2 = new Object[ elementData . length / 2 + elementData . length ] ; for ( int i = 0 ; i < elementData . length ; i ++) { arr2 [ i ] = elementData [ i ] ; } elementData = arr2 ; } } public Object get ( int i ) { return elementData [ i ] ; } public int size () { return size ; } } ArrayList works kind of similar to this class.

Spring config file

Изображение
package com.luv2code.springdemo ; public interface Coach { public String getDailyWorkout () ; public String getDailyFortune () ; } package com.luv2code.springdemo ; public interface FortuneService { public String getFortune () ; } package com.luv2code.springdemo ; public class BaseballCoach implements Coach { // define a private field for the dependency private FortuneService fortuneService ; // define a constructor dependency injection public BaseballCoach ( FortuneService fortuneService ) { this . fortuneService = fortuneService ; } @Override public String getDailyWorkout () { return "Spend 30 minutes on batting practice" ; } @Override public String getDailyFortune () { // use my fortuneService to get a fortune return fortuneService .getFortune() ; } } <? xml version ="1.0" encoding ="UTF-8" ?> <beans xmlns ="http://www.springframework.org/schema/beans&

Regular Expressions - Regex

  package main ; import java.util.regex.Pattern ; import java.util.regex.Matcher ; public class Main { public static void main ( String [] args ) { String re = "." ; String text = "a" ; Pattern pt = Pattern . compile ( re ) ; Matcher mt = pt .matcher( text ) ; boolean result = mt .matches() ; System . out .println( result ) ; } } Here we match any character. The output will be true. 1. . - matches any character except new line.

Architechture 3

Изображение

Architechture 2

Изображение
 

Architechture 1

Изображение
 

End of File (EOF)

  package main ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) throws Exception { Scanner in = new Scanner( System . in ) ; while ( in .hasNext()){ int n = in .nextInt() ; System . out .printf( "%d \n " , n ) ; } } }

Continue and Break examples with label in Java

  package main ; import com.sun.prism.Graphics ; import java.io. * ; import java.util.Scanner ; public class Main { public static void main ( String [] args ) throws Exception { // row: for(int i = 1; i <= 5; i++){ // column: for(int j = 1; j <= 5; j++){ // System.out.print(j + " "); // if(j == 3) break; // } // System.out.println(); // } outer: for ( int a = 1 ; a <= 10 ; a ++) { inner: for ( int b = 1 ; b <= 10 ; b ++) { if ( b % 3 == 0 ){ System . out .println( b ) ; break inner ; } } } } }