React with Redux

 What is  React?

Basically react is a frontend development tool to develop an application. 

It helps in making our application more robust and easier.

What is redux?

It is state management library of React which is used to transfer data from one component to another by keeping the data collection in a generalized store. The data are store in the store through this way.

1st:- component: it passes data to action 

2nd:- Action: here we do the required change in the data if it is needed

3rd:- Reducers:- from here Data is passed to store 


finally, from the store, the data is fetched using the connect method in the component.

So basically the call flow goes like this.

component :- action:- reducers:- store:- component


#for sending data from component to action then reducers we have to use mapDispatchToProp to make sure that component data dispatches to reducers otherwise data will not enter in State.


For making the store available throughout the application the app (in index.js ) must be wrapped with the provider. 

Also, make sure in App.js store is initialized and exported otherwise we can create separate store class also.


Stream API

In java stream api is used to fetch something and then filter the result according to the requiremnt.

It is a generic approach which is used on Generic class.
The Stream api is used to fetch the stream, the filter api to filter the required information  ,the map api is used to map the function which are filtered and the  forEach  api to display the filtered mapped output.

given an example :-


package com.test;

import java.util.ArrayList;
import java.util.List;

class productPrice {
    int price;

    public productPrice(int price) {
        super();
        this.price = price;
    }

}

public class TestStream {

    public static void main(String[] args) {
        List<productPrice> abc = new ArrayList<productPrice>();
        abc.add(new productPrice(4));
        abc.add(new productPrice(9));
        abc.add(new productPrice(8));

        abc.stream().filter(k -> k.price > 4).map(r -> r.price)

                .forEach(System.out::println);
        ;

    }

}

************************** OUTPUT ****************************************

9
8

Why CAA get huge attention..

India is a country of politics and Reliance Jio lies on top of it
and it is worth living in such type of country.
 
Now, coming to CAA why these fucking morons are shouting about CAA.
CAA is a pre  planned agenda of  BJP party to create polarisation in the country and he sucedded in his attempts.

Reason we all  know that BJP could not fulfill his promises and to diverse the mind of the people he has to something to engage the  people.

These are a part of story and the other part is that CAA(Citizen Amendment Act) is one of the toughest and boldest decision towards India Development.

 
why other communities are opposing it because they have sympathy for their community who are refuges. This is called religious emotions. Moreover, the other community were silent on the act of government like "Triple talaq", "Aydhoya" and "article 370,35A" so they have not a chance to protest against the government so this they are using their all force to create pressure on the government.

From my view, it is good to do protest but breaking the properties of innocent people under the name of protest should not be accepted. Moreover, the police who breaks the properties of common people should also be punished.

Now, coming to the title ...

why CAA got huge attention???

After CAA there were a huge protest all over the country the major outrage was broken at jamiya and  jnu college of Delhi.When the student came out in large numbers and started  with the silent protest. The protest suddenly took a violent turn and it moved to vandalizing the public properties like buses and throwing stones on police officers. In return, police enter the campus and beat those miscreants. Now, this became a hot issue in the news channel. All channel telecast this in different perspectives. Thus, a rise of violent protest under the name of silent protest rose all across the country. Large group of Muslim religion came out in street and started vandalizing public properties.
Though the mob include other communities too who may be so called by rumors about bill.


In the course of this event, the illiterate people have made it a hub to seek attention of media.
The student are now angry with everything  now even if something is not happening in the country then they will raise an irrelevant issue and  start protesting. They know if someone wanna get attention in this country then he/she has to go offtrack. This is how leaders are born.

Now, if they are not getting attention they start rejecting the regular classes and also not letting the professors to enter the premises. These are the things which attract media and display the student activities on screen.













At end, i would like to conclude with a message that India is not a such a good country where we would live and waste our life good moments for the sake of  cheap politics or viewpoint of people.
There are other develop countries in the world where we can spend our time and give our self a good living. It is as simple as it is "If you want to live in this country ... tolerate what is going on or leave this country" and nothing is more beautiful than leaving your country for the sake of good life.

Difference between public private and protected


 Key difference is


in public access modifier, we can access the data type anywhere in the project with extending that class.

In protected access modifier, we can access the data type anywhere but in other class, we have to inherit that class.

In default, we can access that variable in that same package only.

In private access modifier, we can access that variable only in that class and not in any other class even by inheriting them.


**********************************Example**************************************








the picture shows that by making the object of the same class we can access the public and protected variables of the parent class.

Note:- please do it by yourself in your pc to get understanding .. as if you will not do.. u may not get up to what which you should. Next, it is up to you. My work is done.



***************************************Example***********************************

Now, we are not extending to parent class present in another package.






In this case, we have to make an object of that class whose variable we need to fetch.

thus only public variable is accessible here.

***********************************Example ***********************************

Now, we are accessing a private variable in another class.






In this case all public, protected and default variable is accessible but not the private one.






























Steps to enter a node in hybris

In sap hybris, if we wish to insert node we need to add the following attributes in the Impex file.

The Impex file is a file to insert data in the database

# create a navigation node
# create update link
# create linkComponent

Fire all these Impex in the console.

then go to back-office and search synchronized.
Then synchronized it. While synchronizing the content from staged will go to online.

After that, it will reflect on the website.


*********************************** Example *************************** ***********




Impex for Pack node:-
$contentCatalog=b2ctelcoContentCatalog
$contentCatalogName=B2C Telco Content Catalog
$contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Staged])[default=$contentCatalog:Staged]
$productCatalog=b2ctelcoProductCatalog
$productCatalogName=B2C Telco Product Catalog
$productCV=catalogVersion(catalog(id[default=$productCatalog]),version[default='Staged'])[unique=true,default=$productCatalog:Staged]
$medias=medias(code, $contentCV);
$product=product(code, $productCV)
$category=category(code, $productCV)
$siteResource=jar:de.hybris.platform.b2ctelcostore.constants.B2ctelcostoreConstants&/b2ctelcostore/import/sampledata/contentCatalogs/$contentCatalog
$jarResourceCms=jar:de.hybris.platform.b2ctelcostore.constants.B2ctelcostoreConstants&/b2ctelcostore/import/sampledata/cockpits/cmscockpit
$addonExtensionName=stltelcoaddon
$mediaContainer=media(qualifier, $contentCV);
$asmAddonExtensionName=assistedservicestorefront
$lang=en
INSERT_UPDATE PageTemplate;$contentCV[unique=true];uid[unique=true];name;frontendTemplateName;restrictedPageTypes(code);active[default=true]



INSERT_UPDATE CMSNavigationNode;uid[unique=true];$contentCV[unique=true];name;parent(uid, $contentCV);links(&linkRef);&nodeRef
;PackNavNode;;Pack;MyAccountNavNode;;PackNavNode

# Create CMS Link Components For My Account Pages
INSERT_UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];name;url;&linkRef;target(code)[default='sameWindow']
;;PackLink;Pack Link;/my-account/pack;PackLink
# Create CMS Navigation Entry For Navigation Child Nodes
INSERT_UPDATE CMSNavigationEntry;uid[unique=true];$contentCV[unique=true];name;navigationNode(&nodeRef);item(&linkRef)
;PackNavNodeEntry;;Pack Nav Node Entry;PackNavNode;PackLink

UPDATE CMSLinkComponent;$contentCV[unique=true];uid[unique=true];linkName[lang=$lang]
;;PackLink;"Pack"


INSERT_UPDATE ContentPage;$contentCV[unique=true];uid[unique=true];masterTemplate(uid,$contentCV);label;defaultPage[default='true'];approvalStatus(code)[default='approved'];homepage[default='false']
;;pack;DashboardPageTemplate;/my-account/dashboard





Steps to setup hybris




There are some basic steps which one must follow while configuring hybris in your system.

# first, go to a  folder where you wish to create your workspace.

# open terminal at that location

# do git clone <link where your project is>

# Now, the project will be called at that location.

#Do checkout to a place where you wish the project to.

#In the platform directory, perform following Linux commands.

# setting up hybris:-  . ./setup-hybris.sh

#. ./setantenv.sh       :- to set up the environment.

# ant clean all:- it makes a new folder like bin, config, data, log, roles, heap and classes like .class and .java class.

#now to define the server IP address we need to do the host entry.As we make our system as a server so how others will access it??
 so we will make our IP entered in host entry by which others can access my server.

#open vi editor and enter your ip address.

#finally initialize the hybris by- ant initialize









How to copy file from one system to another in linux


Following are commands to copy files from one system to another:-

_____________________________________LOGIN_____________________________________

first, log in to person systems from which you have to copy the files.

 ssh elitecore@10.12.115

here elitecore is the username of that person system and 10.12.115  is the IP address of that person system.
to get the IP address of the system type in the terminal:-

ifconfig

it will show your io address in your system.

after that type password of that system.

[elitecore@shashi-jaiswal ~]$ ssh elitecore@10.121.21.115
The authenticity of host '10.121.21.115 (10.121.21.115)' can't be established.
ECDSA key fingerprint is SHA256:ZeRadrZ3eR4dOZ8BRz4Mso0By+qriP9ZEqtKPnadSRU.
ECDSA key fingerprint is MD5:c4:72:fb:85:a4:b2:df:0b:12:16:a2:34:4f:9d:75:8e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.121.21.115' (ECDSA) to the list of known hosts.
elitecore@10.121.21.115's password:
Last login: Fri Aug 16 18:04:47 2019 from 10.121.21.137
[elitecore@dushyant-nasit ~]$ scp /opt/software/sts-java-11
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 ... [[user@]host2:]file2

___________________________________COPY_________________________________________

Now to copy files from that person system to your system.


scp <file-name> elitecore@10.121.21.112:


here <file name> is the name of file you wish to copy.

to get the file name you can do ls command to search in that directory.


if the file, not a zip file then type

scp -r <file-name> elitecore@10.121.21.112





scp CXCOMM190500P_1-70004140.ZIP elitecore@10.121.21.112:
The authenticity of host '10.121.21.112 (10.121.21.112)' can't be established.
ECDSA key fingerprint is SHA256:ZeRadrZ3eR4dOZ8BRz4Mso0By+qriP9ZEqtKPnadSRU.
ECDSA key fingerprint is MD5:c4:72:fb:85:a4:b2:df:0b:12:16:a2:34:4f:9d:75:8e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.121.21.112' (ECDSA) to the list of known hosts.
elitecore@10.121.21.112's password:
CXCOMM190500P_1-70004140.ZIP                  100% 1454MB  90.9MB/s   00:16
______________________________________________________________________________

























What's an ideal life?



We always have a dream of becoming something then after becoming that we again dream something the process continues until we die. So what is an ideal life? How can one say where he is he is ideally satisfied.


The answer comes from self .... if your present situation does not satisfy your self-esteemed then you need a change but make sure you change for betterment and when you desperately need a change then the betterment or not does not matter.

Your self-esteemed is only carried along with you all the way to life. So surround yourself among the company of good people from your point of view and enjoy.

You should never regret in life for what you have not got rather you should all thing which you have not got is all because you lack something in you. You must accept all the situation happened with you as everyone is born equal. Some learn some facts in life much earlier

Why some are considered as great people and why some as duffer it is because they did not welcome the change in life. They never tried to make their life better. If they tried to make better then also they do not have the vision and courage in their path and if they have the courage then they do not have the opportunity.

















method overloading with different return type


/**
 * method overloading with different return type
 *
 *
 */

public class MethodOverloading {
   
    // Simple one
    void print(int a ) {

        System.out.println("Method with integer parameter");
       
    }
   
    void print()
    {
        System.out.println("Default method");
       
    }
   
    // with different return type
    int show(int u)

    {
        int a= 5;
        return a;
       
    }
   
    void show()
    {
        System.out.println("default method with different return type ");
    }
   
   
   
    public static void main(String[] args) {
       
        System.out.println("Welcome to Sterlite");
       
        // first we make reference of class
        MethodOverloading methodOverloading;
        // now we create object of that class
        methodOverloading= new MethodOverloading();
       
        // now we call the method inside class
        methodOverloading.print(); // default call
        methodOverloading.print(4);
       
       
        methodOverloading.show();
       
         
    }
   

}


*************************** OUTPUT ***************************************

Welcome to Sterlite
Default method
Method with integer parameter
default method with different return type





*****************************************************************************
Thus, method overloading works with different return types and with different parameter as arguments.












Use of split function

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WordSplit;

import java.util.Arrays;

/**
 *
 * @author SHASHI
 */
public class WordsSplit {
   
   
    public static void main(String[] args) {
       
        String sentences=  "Generates HTML. Building HTML from a helper class is\n" +
"probably not really worth it for real projects (JSP is\n" +
"better), but we haven’t covered logic in servlets yet. But\n" +
"the general principle still holds: if you are doing the same\n" +
"thing in several servlets, move the code into shared class";
        String[] words = sentences.split("[\\n .(),]");      // as many punctuation we put we receive as many seperation point on the sentences.
       
        System.out.println(" In string form"+Arrays.toString(words)  );
       
        for (int i = 0; i < words.length; i++) {
            System.out.println(" "+words[i]);
           
           
        }
       
       
       
    }
   
   
}


#########################OUTPUT##############################################

run:
 In string form[Generates, HTML, , Building, HTML, from, a, helper, class, is, probably, not, really, worth, it, for, real, projects, , JSP, is, better, , , but, we, haven’t, covered, logic, in, servlets, yet, , But, the, general, principle, still, holds:, if, you, are, doing, the, same, thing, in, several, servlets, , move, the, code, into, shared, class]
 Generates
 HTML

 Building
 HTML
 from
 a
 helper
 class
 is
 probably
 not
 really
 worth
 it
 for
 real
 projects

 JSP
 is
 better


 but
 we
 haven’t
 covered
 logic
 in
 servlets
 yet

 But
 the
 general
 principle
 still
 holds:
 if
 you
 are
 doing
 the
 same
 thing
 in
 several
 servlets

 move
 the
 code
 into
 shared
 class
BUILD SUCCESSFUL (total time: 0 seconds)















Use of Static keyword


package dice;
import java.util.Random;

public class Dice {
static int no_of_sides = 6;
int face_value = 0;
int roll() {
Random r = new Random();
this.face_value = r.nextInt(no_of_sides) + 1;
return this.face_value;
}
static class FirstDice {
static String color = "red";
}
static class SecondDice {
static String color = "black";
}
public static void main(String[] args) {
Dice d = new Dice();
System.out.println("The first die has color " + FirstDice.color + " and has face value after rolling as " + d.roll());
System.out.println("The second die has color " + SecondDice.color + " and has face value after rolling as " + d.roll());
}
}


/**    comments
Here, we have used the static keyword to call the variable(colour ) directly in main method.
We made the inner class(firstDice) static and then the variable colour static to display the colour of  first dice in main method.
Also, in the main method which is static, any variable which needs to be accessed should be static and for the non-static, the variable, function or method, which needs to be  accessed should be accessed by creating an instance of the class, which we have done for calling the function roll in the main method.

**/

About HTTP/2

About HTTP/2 HTTP/2 is an advance version of HTTP/1.x . It has lots of advantages over its previous versions.. It supports multiplexing, binary message framing,server push, header compression and decompression, prioritization, re-prioritization of request, flow control, congestion control and many more... Initially, between client and server, a connection is established by sending a header frame which contains "headers", "h2"or "h2c". Where h2 refers to connection security(mainly of TLS/SSL) i.e, a negotiation between TLS-ALPN extension. In this negotiation, a list of protocol is sent from client to server .Now, server select the protocol and send the selected protocol certificate, server key and certification request.
From the client side it accept these things and send client key, confirmation of certificate verification. After that the handshake is complete and both endpoint negotiate to exchange data on verified protocol. In "h2c" it checks that the client request is cleartext or not. After header frame, the settings franme, containing 64 bit octet is sent from client . Finally, a connection preface frame is sent from one endpoint and client start sending headers frames before waiting from other endpoint the connection preface to come . This way connection is established in HTTP/2.

Two way interaction of client server in java

// here from both ends the message will be sent and read


//client code

public class TwoWayInteractionClient {

   
    public static void main(String[] args) throws IOException {
       
        Socket obj = new Socket("localhost",8844);
        DataOutputStream dout = new DataOutputStream(obj.getOutputStream());
        dout.writeUTF("This message is from client side");
        dout.flush();
       
       
        //ServerSocket rec = new ServerSocket(8134);
        DataInputStream din = new DataInputStream(obj.getInputStream());
        String newdata = (String)din.readUTF();
        System.out.println(" the new msg is " +newdata);
       
    }
   
   
}

output
the new msg is This msg is send from server


//server code

public class TwoWayInteractionServer {
     public static void main(String[] args) throws IOException {
       
    ServerSocket obj1 = new ServerSocket(8844);
        Socket obj = obj1.accept();
        DataInputStream din = new DataInputStream(obj.getInputStream());
        String str = (String)din.readUTF();
        System.out.println("The message from client is  " +str);
       
       // while two way interaction no need to create new port
        DataOutputStream dout =  new DataOutputStream(obj.getOutputStream());
        dout.writeUTF("This msg is send from server");
        dout.flush();
     }
   
   
}

output
The message from client is  This message is from client side











Client server callback of message

//code for client

public class MyClient {
 
 
    public static void main(String[] args) throws IOException {
     
        Socket obj = new Socket("localhost",8040);
        DataOutputStream dout = new DataOutputStream(obj.getOutputStream());
        dout.writeUTF("This message is from client side");
        dout.flush();
     
     
    }
}





// code for server

public class MyServer {
    public static void main(String[] args) throws IOException {
     
        ServerSocket obj1 = new ServerSocket(8040);
        Socket obj = obj1.accept();
        DataInputStream din = new DataInputStream(obj.getInputStream());
        String str = (String)din.readUTF();
        System.out.println("The message from client is  " +str);

     
    }
 
 
 
}

output (in server console)
This message is from client side



//here first we have to run server code then client code ..
//the message sent by the client will be readed in server concole
// the message are delivered through port no which is listened at sockets














Sequence Input Output Stream

import java.io.*;


// the purpose this api is to combine content of two input stream file  together
public class SequenceInputStreamEx    {
    public static void main(String[] args) throws Exception {
     
        FileOutputStream file1 = new FileOutputStream("F:\\file1.txt");
     
        FileOutputStream file2 = new FileOutputStream("F:\\file2.txt");

        String s1 = "He is awaken";
        byte b[]= s1.getBytes();
        file1.write(b);
        String s2 = "He will conquer all";
        byte c[]=s2.getBytes();
        file2.write(c);
        file1.close();
         file2.close();


// will put the above data in two files respectively
     

*********************************************************************************
// will combine the two file data , here we display in console and write in file also.     

 public static void main(String[] args) throws Exception {

        FileInputStream  file1 = new FileInputStream("F:\\file1.txt");
        FileInputStream  file2 = new FileInputStream("F:\\file2.txt");
     
        FileOutputStream fout = new FileOutputStream("F:\\SeqFile.txt");
     
        SequenceInputStream seqFile = new SequenceInputStream(file1, file2); // the two file data are combined together
     
        int i;
     
        while((i=seqFile.read())!=-1)
        {
            fout.write(i);          //writting the combined data in differnt file
         
            System.out.print((char)i);
        }
     

     
    }
}


output

He is awakenHe will conquer all

Use of Buffered , ByteArray Input and Output Stream



import com.sun.xml.internal.messaging.saaj.util.ByteInputStream;
import java.io.*;


public class BufferOutputStreamrExample {


    public static void main(String[] args) throws FileNotFoundException, IOException {

        FileOutputStream  file = new FileOutputStream("F:\\check.txt");
     
     
        BufferedOutputStream bout = new BufferedOutputStream(file); //collection of data //here it is now connected to fileoutputStream to flush large amount of data together
        String s = "shashi is not dead";
        byte b[] = s.getBytes();
        bout.write(b);
        bout.flush();//it is used for flushing the buffer output stream data .
        bout.close();
        file.close();
       
    }
   
*********************************************************************************
    // whereas in byte array output stream we can write it to a different file

    public static void main(String[] args) throws FileNotFoundException, IOException {

        FileOutputStream  file = new FileOutputStream("F:\\check.txt");
     
     ByteArrayOutputStream bout1 = new ByteArrayOutputStream();
        bout1.write(65); // byte gives the ascii code so 65==A
        bout1.writeTo(file);


    // like  bout.writeTo(file1);
   
}

*********************************************************************************

   
     public static void main(String[] args) throws FileNotFoundException, IOException {
        FileInputStream  file = new FileInputStream("F:\\check.txt");
        BufferedInputStream bin = new BufferedInputStream(file); //collection of data //here it is now connected to fileoutputStream
     
     int i=0 ;
         while((i=bin.read())!=-1)
         {
             char ch =(char)i;
             System.out.println(ch);
           
         }
       
        bin.close();
        file.close();
       
         
}

******************************************************************************

public static void main(String[] args) throws FileNotFoundException, IOException {

byte []g = {35,37,38}; // be spefic while using byte as it has differnt code for different symbols.
      ByteArrayInputStream bin = new ByteArrayInputStream(g);// it will only read the byte data
 int i=0 ;
         while((i=bin.read())!=-1)
         {
             char ch =(char)i;
             System.out.println(ch);
           
         }
        }

output :- #
%
&


*******************************************************************************
}

File Input Output Stream




import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author SHASHI
 */
public class FileOutputStream1 {
    public static void main(String[] args) throws IOException {
        try {
            FileOutputStream file = new FileOutputStream("F:\\check.txt"); // will create file with specified name and in given location
 
            file.write(35); //be specific while writting the byte values .. it has different id  for diferent symbols
            file.close(); // a good practise
        } catch (FileNotFoundException ex) {
            Logger.getLogger(FileOutputStream1.class.getName()).log(Level.SEVERE, null, ex);
        }

FileInputStream f = new FileInputStream("F:check.txt"); // will check for this file
 int i =f.read();  // for reading u have to specify the content i.e, u r going to read integer content
        System.out.println(" the content is " +i);
     
    }
   
   
}
OUTPUT

the content is  17// whatever written in the file

Thread Priority


public class ThreadPriority extends Thread {
   
    public void run (){
        try {
            for (int i = 0; i < 4; i++) {
                 Thread.sleep(1000);
                  System.out.println("The current thread is  " +i+"  ," +Thread.currentThread().getName());
            }
         
        } catch (InterruptedException ex) {
            Logger.getLogger(ThreadPriority.class.getName()).log(Level.SEVERE, null, ex);
        }
 
}
    public static void main(String[] args) {
        ThreadPriority obj = new ThreadPriority();
         ThreadPriority obj1 = new ThreadPriority();
        obj.setPriority(Thread.MIN_PRIORITY);
        obj1.setPriority(Thread.MAX_PRIORITY);
       
        obj.start();
        obj1.start();
        //its all about priotising the threads
    }
   
}

output

The current thread is  0  ,Thread-1
The current thread is  0  ,Thread-0
The current thread is  1  ,Thread-1
The current thread is  1  ,Thread-0
The current thread is  2  ,Thread-1
The current thread is  2  ,Thread-0
The current thread is  3  ,Thread-1
The current thread is  3  ,Thread-0
BUILD SUCCESSFUL (total time: 4 seconds)


//see the priority of ececution of thread 1 .. it always start before thread 0

Thread Join



public class ThreadJoin extends Thread{
   
    public void run(){
        for (int i = 0; i < 4; i++) {
         
        try {
            Thread.sleep(1000);
            System.out.println("thread sleep "+i);
            System.out.println(" current thread name "+ Thread.currentThread().getName()); // getting current thread name
        } catch (InterruptedException ex) {
            Logger.getLogger(ThreadJoin.class.getName()).log(Level.SEVERE, null, ex); // not for beginners
        }}}   
    public static void main(String[] args) {
       
   
        try {
            ThreadJoin obj = new ThreadJoin();
            ThreadJoin obj1 = new ThreadJoin();
            ThreadJoin obj2 = new ThreadJoin();
            ThreadJoin obj3 = new ThreadJoin();
            System.out.println("thread 1 name "+obj.getName());  // getting and setting of Thread name
            obj.start();
            obj.join(); // used to emphasis that any thread which has to run will run after this thread completion
           
             obj1.start();
              obj1.join(5000);// it is just a priority checker
             obj2.start();
             obj3.start();
// we now set the thread name
            obj.setName("sj");
            System.out.println("after name change " + obj.getName());// here we access the thread name
        } catch (InterruptedException ex) {
            Logger.getLogger(ThreadJoin.class.getName()).log(Level.SEVERE, null, ex);
        }
       
       
    }
}

OUTPUT


thread 1 name Thread-0
thread sleep 0
 current thread name Thread-0
thread sleep 1
 current thread name Thread-0
thread sleep 2
 current thread name Thread-0
thread sleep 3
 current thread name Thread-0
thread sleep 0
 current thread name Thread-1
thread sleep 1
 current thread name Thread-1
thread sleep 2
 current thread name Thread-1
thread sleep 3
 current thread name Thread-1
after name change sj
thread sleep 0
thread sleep 0
 current thread name Thread-2
 current thread name Thread-3
thread sleep 1
thread sleep 1
 current thread name Thread-3
 current thread name Thread-2
thread sleep 2
thread sleep 2
 current thread name Thread-2
 current thread name Thread-3
thread sleep 3
thread sleep 3
 current thread name Thread-3
 current thread name Thread-2
BUILD SUCCESSFUL (total time: 12 seconds)





Thread Sleep




public class ThreadSleep extends Thread {
 
   
    public void run (){
       
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000) ;
                System.out.println("thread is about to sleep"+i); // repeated for 1 sec interval
            } catch (Exception e) {
                System.out.println(e);
            }
         
        }
}
    public static void main(String[] args) {
        ThreadSleep obj = new ThreadSleep();
       // obj.start();
     
   
        //obj.start();// this shows that we can start a thread twice but only by taking different references
       //obj.stop();
   
         ThreadSleep obj1 = new ThreadSleep();
        //when two run method are called simultaneously then they are treated as seperate object and are executed seperately
         obj.run();
        obj1.start();
        // calling run method directly will run the run method directly and if we call 2 run methods they will run one by one
// obj.run();
     //   obj1.run();
    }
 
}


OUTPUT

thread is about to sleep0
thread is about to sleep1
thread is about to sleep2
thread is about to sleep3
thread is about to sleep4
thread is about to sleep0
thread is about to sleep1
thread is about to sleep2
thread is about to sleep3
thread is about to sleep4
BUILD SUCCESSFUL (total time: 10 seconds)