Сообщения

Сообщения за апрель, 2022

JSP - Java Server Pages

 1.  @Override protected void doGet ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { request .getRequestDispatcher( "login.jsp" ).forward( request , response ) ; } request.getRequestDispatcher("jsp sehifesinin adi").forward(request, response); - bu emeliyyat request ve responsu jsp sehifesine gonderir. 2. @Override protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { try { String username = request .getParameter( "username" ) ; String password = request .getParameter( "password" ) ; User user = userService .findUserByUsernameAndPassword( username , password ) ; request .getSession().setAttribute( "loggedInUser" , user ) ; System . out .println( user ) ; } catch ( Exception e ) { System . out .println( "Some problem occurred" ) ; }

yaml file

  server : port : 8080 ms : applicationName : MS9 version : 1.0 package az.ingress.ms9 ; import az.ingress.ms9.singleton.Flyable ; import lombok. AllArgsConstructor ; import lombok. RequiredArgsConstructor ; import org.springframework.beans.factory.annotation. Autowired ; import org.springframework.beans.factory.annotation. Qualifier ; import org.springframework.beans.factory.annotation. Value ; import org.springframework.boot.CommandLineRunner ; import org.springframework.boot.SpringApplication ; import org.springframework.boot.autoconfigure. SpringBootApplication ; @SpringBootApplication public class Ms9Application implements CommandLineRunner { @Autowired private Flyable flyable ; @Autowired @Qualifier ( "animal" ) private Flyable flyable2 ; @Value ( "${ms.applicationName}" ) private String applicationName ; // public Ms9Application(@Qualifier("bird") Flyable flyable, @Qualifier("animal") Flyable flyable2)

Apache Tomcat

 Apache Tomcat - bir programdir, hansiki 8080 portunda TCP socket acir ve qulaq asir ve sorgu gozleyir. 

Read and Write XML files

  package main ; import com.fasterxml.jackson.core.type.TypeReference ; import com.fasterxml.jackson.databind.ObjectMapper ; import com.fasterxml.jackson.dataformat.xml.XmlMapper ; import model.Address ; import model.Person ; import java.io.File ; import java.io.FileInputStream ; import java.io.InputStream ; import java.util.List ; public class Main { public static void main ( String [] args ) { try { ObjectMapper mapper = new XmlMapper() ; InputStream inputStream = new FileInputStream( new File( "D:/Yigim/persons.xml" )) ; TypeReference < List < Person >> typeReference = new TypeReference <>() { } ; List < Person > persons = mapper .readValue( inputStream , typeReference ) ; for ( Person p : persons ) { System . out .println( "name is " + p .getFirstName() + " city is " + p .getAddress().getCity() + " fir

Interface

 Interface - lerde body-siz metodlar by default public abstract olur. package main.example9 ; public interface Worker { public abstract void work () ; } Interface - lerde variable-lar public static final olur. public static final String name = "Parvin" ; Interface - lerde body-li metodlar yazmaq mumkundur. By default public olurlar. package main ; public interface Runnable { public static final String name = "Parvin" ; public abstract void foo () ; public default void foo2 () { System . out .println( "foo2 in Runnable" ) ; } }

Collection API

Изображение
 

Integer. Integer pool

package main ; public class Main3 { public static void main ( String [] args ) { int i1 = 5 ; int i2 = 5 ; int i3 = 6 ; int i4 = 10 ; int i5 = 128 ; int i6 = 128 ; Integer i7 = 5 ; Integer i8 = new Integer( 5 ) ; Integer i9 = new Integer( 10 ) ; Integer i10 = new Integer( 10 ) ; Integer i11 = new Integer( 128 ) ; Integer i12 = new Integer( 129 ) ; Integer i13 = 129 ; Integer i14 = 128 ; Integer i15 = 128 ; Integer i16 = 127 ; Integer i17 = 127 ; System . out .println( i1 == i2 ) ; // true + System . out .println( i1 == i3 ) ; // false + System . out .println( i5 == i6 ) ; // true + System . out .println( i1 == i7 ) ; // true + System . out .println( i6 == i14 ) ; // true + System . out .println( i10 == i9 ) ; // false + System . out .println( i7 == i8 ) ; // false + System . out .print

Inheritance

Изображение
  Cedvelde gorduyumuz kimi varis klas ferqli paketlerin icinden yalniz public ve protected fieldleri gore biler. Eyni paketdedilerse o zaman default (package private)  olanlarida gore biler.  package main.example3 ; public class Parent { public static int a = 1 ; public int b = 2 ; protected int c = 3 ; private int d = 4 ; int e = 5 ; public static void method1 () { System . out .println( "static method1 in Parent" ) ; } public void method2 () { System . out .println( "public method2 in Parent" ) ; } protected void method3 () { System . out .println( "protected method3 in Parent" ) ; } void method4 () { System . out .println( "default method4 in Parent" ) ; } } package main.example3 ; public class Child extends Parent { public static int a = 11 ; public int b = 22 ; protected int c = 33 ; private int d = 44 ; int e = 55 ; public static void

Constructor

 Constructor - A constructor in Java is similar to a method that is invoked when an object of the class is created.  Not clean version: package main ; public class Tree { public String type ; public double height ; public Tree ( String newType , double newHeight ) { type = newType ; height = newHeight ; } public Tree ( String newType ) { type = newType ; height = 1.0 ; } public Tree ( double newHeitht ) { type = "Pine" ; height = newHeitht ; } public Tree () { type = "Pine" ; height = 1.0 ; } } Clean version: package main ; public class Tree { public String type ; public double height ; public Tree ( String newType , double newHeight ) { type = newType ; height = newHeight ; } public Tree ( String newType ) { // type = newType; // height = 1.0; this ( newType , 1.0 ) ; } public Tree ( double newHeit

Enum

  package main ; public enum Transport { PLANE , TRAIN , AUTOMOBILE } package main ; public class Main { public static void main ( String [] args ) { Transport tp = Transport . PLANE ; if ( tp == Transport . PLANE ){ System . out .println( "plane..." ) ; } } } package main ; public class Main { public static void main ( String [] args ) { Transport tr = Transport . TRAIN ; foo ( tr ) ; } public static void foo ( Transport transport ) { if ( transport == Transport . AUTOMOBILE ) { System . out .println( "automobile" ) ; } else if ( transport == Transport . TRAIN ) { System . out .println( "train" ) ; } else { System . out .println( "plane" ) ; } } } --------------------------------------------------------------------------------------------- Arxa planda ne baw verir? package main ; public enum