Thursday, 13 April 2023

Networ{k|th} - Tutorials

 Network Commands


1. ipconfig /all  will return  bio-data of your n/w 


C:\Users\rmcme>ipconfig  /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : LaptopDELL
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : cable.rcn.com
Unknown adapter Local Area Connection:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : TAP-Windows Adapter V9
   Physical Address. . . . . . . . . : 00-FF-86-58-B1-15
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
Wireless LAN adapter Local Area Connection* 1:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   Physical Address. . . . . . . . . : 7C-67-A2-80-DA-69
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
Wireless LAN adapter Local Area Connection* 2:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2
   Physical Address. . . . . . . . . : 7E-67-A2-80-DA-68
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
Wireless LAN adapter Wi-Fi:
   Connection-specific DNS Suffix  . : cable.rcn.com
   Description . . . . . . . . . . . : Intel(R) Dual Band Wireless-AC 3165
   Physical Address. . . . . . . . . : 7C-67-A2-80-DA-68
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::7a8a:c454:b45:988b%16(Preferred)
   IPv4 Address. . . . . . . . . . . : 192.168.0.34(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Lease Obtained. . . . . . . . . . : Thursday, April 13, 2023 2:37:54 PM
   Lease Expires . . . . . . . . . . : Friday, April 14, 2023 2:37:53 PM
   Default Gateway . . . . . . . . . : 192.168.0.1
   DHCP Server . . . . . . . . . . . : 192.168.0.1
   DHCPv6 IAID . . . . . . . . . . . : 159147938
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-28-A7-A0-21-7C-67-A2-80-DA-68
   DNS Servers . . . . . . . . . . . : 208.59.247.45
                                       208.59.247.46
   NetBIOS over Tcpip. . . . . . . . : Enabled
Ethernet adapter Bluetooth Network Connection:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   Physical Address. . . . . . . . . : 7C-67-A2-80-DA-6C
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
C:\Users\rmcme>


2.nslookup ipaddress


C:\Users\rmcme>nslookup ycrash.io

Server:  ns2.dns.rcn.net
Address:  208.59.247.45
Non-authoritative answer:
Name:    ycrash.io
Addresses:  52.8.222.182
          52.8.184.141

C:\Users\rmcme>nslookup 142.251.163.100

Server:  ns2.dns.rcn.net
Address:  208.59.247.45
Name:    wv-in-f100.1e100.net
Address:  142.251.163.100


 3. ping amazon.com

Pinging amazon.com [205.251.242.103] with 32 bytes of data:

Reply from 205.251.242.103: bytes=32 time=125ms TTL=236
Reply from 205.251.242.103: bytes=32 time=35ms TTL=236
Reply from 205.251.242.103: bytes=32 time=37ms TTL=236
Reply from 205.251.242.103: bytes=32 time=34ms TTL=236
Ping statistics for 205.251.242.103:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 34ms, Maximum = 125ms, Average = 57ms


4. tracert google.com


Tracing route to amazon.com [205.251.242.103]
over a maximum of 30 hops:

  1     8 ms    16 ms    21 ms  192.168.0.1
  2   171 ms    62 ms    46 ms  172.30.0.1
  3    38 ms    96 ms    48 ms  216.80.78.77
  4    12 ms    33 ms   215 ms  207.172.17.3
  5   133 ms    16 ms    33 ms  hge0-0-0-6.border1.eqnx.il.rcn.net [207.172.19.243]
  6    36 ms    37 ms    35 ms  99.83.94.240
  7     *        *        *     Request timed out.
  8     *        *        *     Request timed out.
  9     *        *        *     Request timed out.
 10    37 ms    33 ms    30 ms  150.222.212.43
 11     *        *        *     Request timed out.
 12     *        *        *     Request timed out.
 13     *        *        *     Request timed out.
 14     *        *        *     Request timed out.
 15     *......

5. netstat -a 

    
Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            LaptopDELL:0           LISTENING
  TCP    0.0.0.0:445            LaptopDELL:0           LISTENING
  TCP    0.0.0.0:3648           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:5040           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:6646           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:7070           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:7680           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:7779           LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49664          LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49665          LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49666          LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49667          LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49668          LaptopDELL:0           LISTENING
  TCP    0.0.0.0:49670          LaptopDELL:0           LISTENING
  TCP    127.0.0.1:27015        LaptopDELL:0           LISTENING
  TCP    127.0.0.1:50051        LaptopDELL:0           LISTENING
  TCP    127.0.0.1:55500        LaptopDELL:0           LISTENING
  TCP    192.168.0.34:139       LaptopDELL:0           LISTENING
  TCP    192.168.0.34:55453     relay-e24ffb83:https   ESTABLISHED
  TCP    192.168.0.34:55467     52.159.126.152:https   ESTABLISHED
  TCP    192.168.0.34:55518     20.25.241.18:https     ESTABLISHED
  TCP    192.168.0.34:55616     ec2-54-175-191-204:https  ESTABLISHED
  TCP    192.168.0.34:55635     52.96.170.82:https     ESTABLISHED
  TCP    192.168.0.34:55647     104.26.3.186:https     ESTABLISHED
  TCP    192.168.0.34:55846     52.96.79.226:https     ESTABLISHED
  TCP    192.168.0.34:55855     gb-in-f188:5228        ESTABLISHED
  TCP    192.168.0.34:55856     bg-in-f188:5228        ESTABLISHED
  TCP    192.168.0.34:56650     a23-7-28-47:https      ESTABLISHED
  TCP    192.168.0.34:56950     132.145.172.253:https  ESTABLISHED
  TCP    192.168.0.34:56985     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:56986     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:56987     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:56988     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:56989     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:56990     a23-193-200-115:https  CLOSE_WAIT
  TCP    192.168.0.34:57038     bi-in-f191:https       ESTABLISHED
  TCP    192.168.0.34:57081     wv-in-f91:https        ESTABLISHED
  TCP    192.168.0.34:57134     lga34s30-in-f3:https   ESTABLISHED
  TCP    192.168.0.34:57205     bl-in-f156:https       TIME_WAIT
  TCP    192.168.0.34:57221     bl-in-f95:https        TIME_WAIT
  TCP    192.168.0.34:57243     ord37s43-in-f6:https   CLOSE_WAIT
  TCP    192.168.0.34:57251     bg-in-f138:https       ESTABLISHED
  TCP    192.168.0.34:57284     ord38s28-in-f6:https   TIME_WAIT
  TCP    192.168.0.34:57285     bj-in-f156:https       TIME_WAIT
  TCP    192.168.0.34:57286     ord38s30-in-f2:https   TIME_WAIT
  TCP    192.168.0.34:57291     ww-in-f99:https        TIME_WAIT
  TCP    192.168.0.34:57296     ec2-54-175-191-203:https  TIME_WAIT
  TCP    192.168.0.34:57302     e2a:https              TIME_WAIT
  TCP    192.168.0.34:57310     bh-in-f94:https        ESTABLISHED
  TCP    192.168.0.34:57311     ww-in-f102:https       ESTABLISHED
  TCP    192.168.0.34:57312     bl-in-f139:https       ESTABLISHED
  TCP    192.168.0.34:57315     kix06s05-in-f3:https   ESTABLISHED
  TCP    192.168.0.34:57321     wv-in-f113:https       ESTABLISHED
  TCP    192.168.0.34:57322     wv-in-f113:https       TIME_WAIT
  TCP    192.168.0.34:57332     wv-in-f119:https       ESTABLISHED
  TCP    192.168.0.34:57333     47:https               ESTABLISHED
  TCP    192.168.0.34:57337     ord38s33-in-f10:https  ESTABLISHED
  TCP    192.168.0.34:57338     bg-in-f95:https        ESTABLISHED
  TCP    192.168.0.34:57339     ec2-3-17-93-252:https  ESTABLISHED
  TCP    192.168.0.34:57341     bl-in-f102:https       ESTABLISHED
  TCP    192.168.0.34:57343     lga25s71-in-f3:https   ESTABLISHED
  TCP    192.168.0.34:57345     ec2-54-175-191-203:https  ESTABLISHED
  TCP    192.168.0.34:57347     13.68.233.9:https      ESTABLISHED
  TCP    [::]:135               LaptopDELL:0           LISTENING
  TCP    [::]:445               LaptopDELL:0           LISTENING
  TCP    [::]:3648              LaptopDELL:0           LISTENING
  TCP    [::]:7680              LaptopDELL:0           LISTENING
  TCP    [::]:7779              LaptopDELL:0           LISTENING
  TCP    [::]:49664             LaptopDELL:0           LISTENING
  TCP    [::]:49665             LaptopDELL:0           LISTENING
  TCP    [::]:49666             LaptopDELL:0           LISTENING
  TCP    [::]:49667             LaptopDELL:0           LISTENING
  TCP    [::]:49668             LaptopDELL:0           LISTENING
  TCP    [::]:49670             LaptopDELL:0           LISTENING
  TCP    [::1]:49669            LaptopDELL:0           LISTENING
  UDP    0.0.0.0:123            *:*
  UDP    0.0.0.0:500            *:*
  UDP    0.0.0.0:4500           *:*
  UDP    0.0.0.0:5050           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5355           *:*
  UDP    0.0.0.0:6646           *:*
  UDP    0.0.0.0:50001          *:*
  UDP    127.0.0.1:1900         *:*
  UDP    127.0.0.1:49664        *:*
  UDP    127.0.0.1:60146        *:*
  UDP    127.0.0.1:64458        *:*
  UDP    127.0.0.1:64459        *:*
  UDP    192.168.0.34:137       *:*
  UDP    192.168.0.34:138       *:*
  UDP    192.168.0.34:1900      *:*
  UDP    192.168.0.34:60145     *:*
  UDP    [::]:123               *:*
  UDP    [::]:500               *:*
  UDP    [::]:4500              *:*
  UDP    [::]:5353              *:*
  UDP    [::]:5353              *:*
  UDP    [::]:5353              *:*
  UDP    [::]:5355              *:*
  UDP    [::1]:1900             *:*
  UDP    [::1]:60144            *:*
  UDP    [fe80::7a8a:c454:b45:988b%16]:1900  *:*
  UDP    [fe80::7a8a:c454:b45:988b%16]:60143  *:*


6. arp -a


Interface: 192.168.0.34 --- 0x10
  Internet Address      Physical Address      Type
  192.168.0.1           0c-cb-85-f9-ad-ad     dynamic
  192.168.0.11          ec-b5-fa-0e-03-39     dynamic
  192.168.0.22          dc-9a-7d-21-b3-4b     dynamic
  192.168.0.255         ff-ff-ff-ff-ff-ff     static
  224.0.0.22            01-00-5e-00-00-16     static
  224.0.0.251           01-00-5e-00-00-fb     static
  224.0.0.252           01-00-5e-00-00-fc     static
  239.255.102.18        01-00-5e-7f-66-12     static
  239.255.255.250       01-00-5e-7f-ff-fa     static
  255.255.255.255       ff-ff-ff-ff-ff-ff     static



7. C:\Users\rmcme>route print

===========================================================================
Interface List
 11...00 ff 86 58 b1 15 ......TAP-Windows Adapter V9
 12...7c 67 a2 80 da 69 ......Microsoft Wi-Fi Direct Virtual Adapter
  7...7e 67 a2 80 da 68 ......Microsoft Wi-Fi Direct Virtual Adapter #2
 16...7c 67 a2 80 da 68 ......Intel(R) Dual Band Wireless-AC 3165
 14...7c 67 a2 80 da 6c ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
===========================================================================

IPv4 Route Table
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0      192.168.0.1     192.168.0.34     55
        127.0.0.0        255.0.0.0         On-link         127.0.0.1    331
        127.0.0.1  255.255.255.255         On-link         127.0.0.1    331
  127.255.255.255  255.255.255.255         On-link         127.0.0.1    331
      192.168.0.0    255.255.255.0         On-link      192.168.0.34    311
     192.168.0.34  255.255.255.255         On-link      192.168.0.34    311
    192.168.0.255  255.255.255.255         On-link      192.168.0.34    311
        224.0.0.0        240.0.0.0         On-link         127.0.0.1    331
        224.0.0.0        240.0.0.0         On-link      192.168.0.34    311
  255.255.255.255  255.255.255.255         On-link         127.0.0.1    331
  255.255.255.255  255.255.255.255         On-link      192.168.0.34    311
===========================================================================
Persistent Routes:
  None

IPv6 Route Table
===========================================================================
Active Routes:
 If Metric Network Destination      Gateway
  1    331 ::1/128                  On-link
 16    311 fe80::/64                On-link
 16    311 fe80::7a8a:c454:b45:988b/128
                                    On-link
  1    331 ff00::/8                 On-link
 16    311 ff00::/8                 On-link
===========================================================================
Persistent Routes:
  None

C:\Users\rmcme>

8. C:\Users\rmcme>systeminfo


Host Name:                 LAPTOPDELL
OS Name:                   Microsoft Windows 10 Home
OS Version:                10.0.19044 N/A Build 19044
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Workstation
OS Build Type:             Multiprocessor Free
Registered Owner:          rmcmeera@gmail.com
Registered Organization:   N/A
Product ID:                00325-96142-21539-AAOEM
Original Install Date:     9/23/2021, 12:24:43 PM
System Boot Time:          4/2/2023, 1:29:43 PM
System Manufacturer:       Dell Inc.
System Model:              Inspiron 13-7378
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: Intel64 Family 6 Model 142 Stepping 9 GenuineIntel ~2901 Mhz
BIOS Version:              Dell Inc. 1.27.0, 1/18/2019
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC-06:00) Central Time (US & Canada)
Total Physical Memory:     12,158 MB
Available Physical Memory: 4,834 MB
Virtual Memory: Max Size:  20,862 MB
Virtual Memory: Available: 11,273 MB
Virtual Memory: In Use:    9,589 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              \\LAPTOPDELL
Hotfix(s):                 18 Hotfix(s) Installed.
                           [01]: KB5022502
                           [02]: KB4562830
                           [03]: KB5003791
                           [04]: KB5012170
                           [05]: KB5025221
                           [06]: KB5006753
                           [07]: KB5007273
                           [08]: KB5011352
                           [09]: KB5011651
                           [10]: KB5014032
                           [11]: KB5014671
                           [12]: KB5015895
                           [13]: KB5016705
                           [14]: KB5018506
                           [15]: KB5020372
                           [16]: KB5022924
                           [17]: KB5023794
                           [18]: KB5005699
Network Card(s):           3 NIC(s) Installed.
                           [01]: Intel(R) Dual Band Wireless-AC 3165
                                 Connection Name: Wi-Fi
                                 DHCP Enabled:    Yes
                                 DHCP Server:     192.168.0.1
                                 IP address(es)
                                 [01]: 192.168.0.34
                                 [02]: fe80::7a8a:c454:b45:988b
                           [02]: Bluetooth Device (Personal Area Network)
                                 Connection Name: Bluetooth Network Connection
                                 Status:          Media disconnected
                           [03]: TAP-Windows Adapter V9
                                 Connection Name: Local Area Connection
                                 Status:          Media disconnected
Hyper-V Requirements:      VM Monitor Mode Extensions: Yes
                           Virtualization Enabled In Firmware: Yes
                           Second Level Address Translation: Yes
                           Data Execution Prevention Available: Yes

9. pathping 127.0.0.1


Tracing route to LaptopDELL [127.0.0.1]
over a maximum of 30 hops:
  0  LaptopDELL [127.0.0.1]
  1  LaptopDELL [127.0.0.1]

Computing statistics for 25 seconds...
            Source to Here   This Node/Link
Hop  RTT    Lost/Sent = Pct  Lost/Sent = Pct  Address
  0                                           LaptopDELL [127.0.0.1]
                                0/ 100 =  0%   |
  1    0ms     0/ 100 =  0%     0/ 100 =  0%  LaptopDELL [127.0.0.1]

Trace complete.


pathping ycrash.io


Tracing route to ycrash.io [52.8.222.182]
over a maximum of 30 hops:
  0  LaptopDELL.cable.rcn.com [192.168.0.34]
  1  192.168.0.1
  2  172.30.0.1
  3  216.80.78.77
  4  207.172.17.1
  5  207.172.17.79
  6  lag-107.ear4.Chicago2.Level3.net [4.26.123.5]
  7     *        *     ae2.3608.ear7.Chicago2.level3.net [4.69.142.178]
  8  52.95.217.36
  9  15.230.18.69
 10  52.95.62.31
 11     *        *        *

Computing statistics for 250 seconds...............

Source to Here   This Node/Link
Hop  RTT    Lost/Sent = Pct  Lost/Sent = Pct  Address
  0                                           LaptopDELL.cable.rcn.com [192.168.0.34]
                                3/ 100 =  3%   |
  1   92ms     4/ 100 =  4%     1/ 100 =  1%  192.168.0.1
                                0/ 100 =  0%   |
  2   11ms    99/ 100 = 99%    96/ 100 = 96%  172.30.0.1
                                0/ 100 =  0%   |
  3   56ms     7/ 100 =  7%     4/ 100 =  4%  216.80.78.77
                                0/ 100 =  0%   |
  4  ---     100/ 100 =100%    97/ 100 = 97%  207.172.17.1
                                0/ 100 =  0%   |
  5   95ms     5/ 100 =  5%     2/ 100 =  2%  207.172.17.79
                                0/ 100 =  0%   |
  6  129ms     3/ 100 =  3%     0/ 100 =  0%  lag-107.ear4.Chicago2.Level3.net [4.26.123.5]
                                1/ 100 =  1%   |
  7  126ms     4/ 100 =  4%     0/ 100 =  0%  ae2.3608.ear7.Chicago2.level3.net [4.69.142.178]
                               96/ 100 = 96%   |
  8  ---     100/ 100 =100%     0/ 100 =  0%  52.95.217.36
                                0/ 100 =  0%   |
  9  ---     100/ 100 =100%     0/ 100 =  0%  15.230.18.69
                                0/ 100 =  0%   |
 10  ---     100/ 100 =100%     0/ 100 =  0%  52.95.62.31

Trace complete.


10. C:\Users\rmcme>hostname

LaptopDELL


11. C:\Users\rmcme>getmac


Physical Address    Transport Name
=================== ==========================================================
7C-67-A2-80-DA-68   \Device\Tcpip_{AA418031-63C2-4732-8243-7417259E49D6}
7C-67-A2-80-DA-6C   Media disconnected
00-FF-86-58-B1-15   Media disconnected

C:\Users\rmcme>

Wednesday, 12 April 2023

JVM - Garbage Collection GC #002

 Garbage Collection : GC#2

GC traverses the object  graph to find the dead objects.
Many types of GC collectors in Java. How to choose the right one.

Serial : Simplest, designed for small apps and on single thread.GC events are conducted serially in                      1 thread. Stop the world approach. So it is not used in real time.

Parellel : Multiple threads are used for minor gC in young generation. A single thread is used for                           Major GC. Most suitable for Multiple thread environment where a lot of work to be                               done, long pauses are accepted..(ie : running a batch job)
       It is the default since JDK 7

Concurrent Mark Sweep :

Concurrent low pause collector, multiple threads are used for minor garbage collection.

Major GC is multi threaded and runs concurrently alongside application. Use more CPUS.

If you can allocate ore CPU, the CMS GC is a preferre3d chice for better performance.


Garbage Firs (G1):

Replacement for CMS

Designed for multi-threaded apps that have large heap size available (>4 GB)

                 Does not have separate regions for young and old generations.

Partition the heap in to a set of equal size regions and use multiple[le threads to scan them.

After mark phase is over, G1 knows which regions contains the most garbage objects and performs GC on those regions first.


Experimental Garbage Collectors.


Epsilon : a -do- nothing (no-op) GC release as part of JDK 11.  Does not implement any memory                          reclamation mechanism. Not preferable. Once Heap is exhausted, the JVM shuts down

Shenandoah: Release as part of JDK 12. GC cycle works currently with application threads. Can                                 relocate objects concurrently. More CPU intensive.

ZGC : Release as part of JDK 11. Low latency, scalability and ease of use. Allows to application                        to continue running while it performs all garbage collection operations.

 

How to choose :

Factors : Most of the default setting will work.

Serial is fine for small data setup (>=100 MB) and or it will be run on a sigle processor with no-pause time requirements.

Parallel is preferable for peak performance for apps  and with no-pause time requirements or pauses for 1 sec or longer are acceptable.

CMS/G1 is preferable is response time is important than overall throughput and garbage collection pauses must be kept shorter than approximately 1 sec.

 

Advantages of GC :

Makes code simple, java memory efficient. Don't worry about mem management (C++                            should be manual not automatic mem management) .
Frees the heap mem to accommodate new objects.
Options for tuning the GC to improve its efficiency.

Best Practice:

It is possible to manually run the GC with System.gc() or Rintime.gc() methods.

If u don't have enough memory to run your application, you will experience slowdowns,                        hangs, long collection times, :stop the world" events, and eventually out of memory errors.                     You can take the help of monitoring tool like jstat or Java Flight recorder to see if the heap                       usage grows indefinitely, which might indicate a bug in your code.

If small, default settings will work.

Best approach to tuning JAVA garbage collection is settings flags on the JVM.

JVM - Garbage Collection - GC#001

 Garbage Collection - GC#1


Process of reclaiminh the runtime unused memory by destroying the un used objects

Methods like free() in C and deletete() in c++ are used to perform clean garbage.

In Java, GC is automatic during the life time of a program

At any point of RT, heap memory consistes of 2 types of objects:

Live : Being used and referenced

Dead : not used and not referenced currently.

How to derefernce objects:

By making a reference null { object o1 = null;}

By assigning a reference to another { object o1 = o2;}

By using an anonymous object { new Object;}


How GC Works:

       Many Versions of JVM. has its own implementation of GC .

       Any version of JVM can be used but should meet the std spec like :

: mark the unreachable objects

: Destroy them    

: Compacting the memory.


GC Roots: to identify the live and dead objects

Local vars and input paramas

        Active Threads

  Static Fields of the Loaded classes

JNI In(ref)ferences


It traverse the full object graph in mem and marks live objects(visited). ALl not reacheble(not visited) by grtaph are identified as dead objects.


Sweep Phase and compact phase ( Fragmented mem blocks are made as contiguos blocks)


Generational GC strategy:


Marking will take a longer GC Time. All objects are mostly short lived.

Heap : (eden, S1, S2)

        Young Generation : Newly 

-Eden Space : all new objects start here, and initial mem is allocated to them

-Survivor Spaces : (S to S)  - Objects are moved here from Eden after surviving one garbage collection cycle.

        When eden space if filled , aminor GC is performed and all the survivir objects are moved to one of the survivor spaces.

Minor GC checks also the survivor space. All the dead objects are reoved when Minir GC is performed.

Second time Minor GC, is used Eden and Survivor space. At any point of time Survivor space is empty.


        Old Generation : Long lived objects are eventually moved from the Young generation to the Old Generation.

This is also known as Tenured generation and conatins objects that have maintained in  the survivor spaces for a long time.

When objects are garbage collected here, it is called as majot garbage collection event.

Permenant Generation :

Metat data such as classes and methods are stored in Perm Genearation

Classes thar are no longer in use may be GC from the permenant generation.

Now Metaspace memory soppace replaced the permenant generation. Heap is now automatically resized. Avoids the the pbm of apps going out of memory due to the limited size of 

PermGen space of heap.

Classes that are no longer used is automatically cleaned when the metaspace searches its maximum size.


JVM - Basics #01

JVM

Java Virtual Machine implements Write once Run Anywhere approach 

Supports many Scala, Kotlin in addition to Java

-> VM -> OS -> Application 

Virtual M/C : H/W-> Hypervisor-> -> VM -> OS -> App.. 

-> VM -> OS -> App..

Java - Compiler - SC (Java) - > Byte code (class) -> 

       

JVM

Class Loader : Prepares the java classes and loads them into main memory.

Run Time Mem/ Data Area: Holds the the rT vars and Data

Execution Engine : Executes the code


Class Loader : 

Loading :  Boot strap Loader, Extension Class Loader, Application Class Loader

        Bin representation :

         Boot Strap Loader . Root Class Loader .. 

Super class of Extension loads the std java packages like java.lang, java.net, java.util, java.io                 etc.

The above are available in rt.jar file

         Extension Class Loader : Sub class of Bootstrap and the super class of thge Application class                                                            Loader.

Loads the files present in $JAVA_HOME/jre/lib/ext directory

Application Class Loader : subclass extensions loader, Loads the files present on the class                                                                  path

By Default, the class path is set to the current directory of th application.

Linking :  

Verification : Verify, Prepare and Resolve : check the structureal correctness of the .class file                                        by checking it against a set of constraint rules . Check for Verify                                                             Exception..

Preperation  : JVM allocates memory for stat fields of a class or interface. Initializes them                                          with default values.

Resolution   : Symbolic reference are substituted with direct references present in RT constant                                        pool.

         Initialization : 

Clinit .

                        Assigning values, constructor call, stat block exec, 
final stage of class loading. Also check for concurrency issues.
Handle thread safety issues for secured process.


Run Time Data Area:


Method Area : 

Class level data as RT Constant Pool, field and code for methods. Memory is insufficent for the startup, JVM throws outofMemoryError

Memory for class instances  and arrays is allocated.

Heap Area   :

All the objects and their corresponding instance varaiables and arrays are stored here. Created on startup. Only one heap Area/JVM

Stack Area  :

Local varsiables and temp results are stored here.
For every method call,  one entry is made into stack frame:
 Further divided in to local vars, operand stack, frame data    

PC Register : Program Counter Register. JVM supports multiple threads. Each thread has its own                                 PCR, to hold the address of currently executing JVM Instruction.

      Once executed, PCR is updated

Native Method Stack : JVM supports native methods. ( written in c/C++)

 

Execution Engine :

Byte code is loaded then interpreter 

       Reads BC line by line.
       JIT compiler : When EE finds the repeated code, it uses JIT-C, tot compile the en tire BC and                                        change it to native code.
JITC Consists of 3 components : Intermediate code Generator, Code Optimizer, Target Code                                                                      Generator.

Garbage Collector:

GC collects and removes un referenced objects.
Involves 2 phases : Mark and Sweep. Done automaticall by GC.
3 types of JC in KJVM, Serial, Parellel(through put)  and G1 (for large heap sizes > 4 GB)

  Java Native Interface 

Supports execution of native code via JNI (c, C++ or ASM files).

Tuesday, 11 April 2023

Better Teacher

3 Steps

Focus on Learning of students rather than teaching 

  1. One rule is that people learn faster and better with varied repetition. Children who practice the piano twice a day are almost always better piano players than children who practice once a week. The same is true of speaking a foreign language, solving quadratic equations, and writing persuasive essays.
  1. A second rule is that people learn faster and better when they receive frequent feedback on their performance. (A corollary to this rule is that prompt feedback is more effective than delayed feedback.)
  1. A third rule is that incentives can play a crucial role in the classroom


Teachers can quiz students weekly and reveal the correct answers immediately. In this way, students receive prompt and frequent feedback. They also have an incentive to complete assigned readings and pay attention in class.


Finally, teachers can take a page from video-gaming companies. Video gaming is a learned skill, and many gamers perform at a very high level. The makers of popular video games like Angry Birds and Super Mario exploit basic principles of learning. Players receive instantaneous feedback on their performance. They also gain expertise through repetition with variation. And leveling up is rewarding!

Key:

  • Teachers should think less about how to teach and more about how students learn.
  • Studies have identified potent enablers of learning such as varied repetition, prompt feedback, and mental elaboration.
  • Teachers can put these principles to work when they build courses, assignments, and tests


From Source

Tuesday, 21 March 2023

KIVY Crash course : Handson Exercises

 Ex 1 kivyApp1.py


from kivy.app import App
from kivy.uix.label import Label


class MainApp(App):
    def build(self):
        label = Label(text='Hello from Kivy',
                      size_hint=(.5, .5),
                      pos_hint={'center_x': .5, 'center_y': .5})

       
        return label
       

if __name__ == '__main__':
    app = MainApp()
    app.run()

Output


Ex 2:  kivyApp2.py

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import Screen


class Demo(MDApp):

    def build(self):
        # defining screenpip
        screen = Screen()

        # defining 1st label
        l = MDLabel(text="Hello!!", pos_hint={'center_x': 0.6,
                                              'center_y': 0.8},
                    theme_text_color="Custom",
                    text_color=(0.5, 0, 0.5, 1),
                    font_style='H1')

        # defining 2nd label
        l1 = MDLabel(text="Hello Kivy Welcome!", pos_hint={'center_x': 0.6,
                                                           'center_y': 0.6},
                     theme_text_color="Custom",
                     text_color=(0.5, 0, 0.5, 1),
                     font_style='H2')

        # defining 3rd label
        l2 = MDLabel(text="Hello Kivy Welcome!", pos_hint={'center_x': 0.6,
                                                           'center_y': 0.4},
                     theme_text_color="Custom",
                     text_color=(0.5, 0, 0.5, 1),
                     font_style='H3')

        screen.add_widget(l)

        screen.add_widget(l1)
        screen.add_widget(l2)
        return screen


if __name__ == "__main__":
    Demo().run()

Output 



EX 3 : kivyApp3.py

# Program to Show how to use textinput (UX widget) in kivy

# import kivy module
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
from kivy.uix.scatter import Scatter
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.label import Label
import kivy

from kivy.app import App

kivy.require('1.9.0')

# Create the App class


class TutorialApp(App):
    def build(self):
        b = BoxLayout(orientation='vertical')

        # Adding the text input
        t = TextInput(font_size=50,
                      size_hint_y=None,
                      height=100)

        f = FloatLayout()

        s = Scatter()

        l = Label(text="      Hello !",
                  font_size=50)

        f.add_widget(s)
        s.add_widget(l)

        b.add_widget(t)
        b.add_widget(f)

        # Binding it with the label
        t.bind(text=l.setter('text'))

        return b


# Run the App
if __name__ == "__main__":
    TutorialApp().run()

Output : 


Ex 4 : kivyApp4.py using .kv file

import kivy

from kivy.app import App

kivy.require('1.9.1')


class kvfileApp(App):
    pass


kv = kvfileApp()  # kvfile.kv

kv.run()

kvfile.kv 

Label:
    text: "Hello"

Output



ex 5 : kivyApp5.py

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
###############################################
# creating the root widget used in .kv file


class KVBL(BoxLayout):
    '''
            no need to do anything here as
            we are building things in .kv file
    '''
    pass

#################################################
# class in which name .kv file must be named KVBoxLayout.kv.


class KVBoxLayoutApp(App):

    def build(self):
        # returning the instance of KVBL class
        return KVBL()

##################################################


# creating the object root for BoxLayoutApp() class
root = KVBoxLayoutApp()

# run function runs the whole program
root.run()

KVBoxLayout.kv

<KVBL>:
    orientation: 'vertical'
#########################################################

    # defining the buttons in the box layout format
    # and adding colour, size etc to it.
    # you can use accordingly
    Button:
        text: "B1"
        background_color: 0, 1, 1, 1
        font_size: 20
       
    Button:
        text: "B2"
        background_color: 0, 1, 0, 1
        font_size: 20
       
    Button:
        text: "B3"
        background_color: 0, 0, 1, 1
        font_size: 20
       
    Button:
        text: "B4"
        background_color: 1, 0, 1, 1
        font_size: 20
       
    Button:
        text: "B5"
        background_color: 1, 0, 0, 1
        font_size: 20

Output:


Ex 6 : kivyApp6.py

import logging
from kivy.logger import Logger
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.app import App
import kivy

kivy.require("1.9.1")

Logger.setLevel(logging.TRACE)

# Creating a widget class
# through this we add button
# the commands of the class is in .kv file


class Button_Widget(Widget):

    def __init__(self, **kwargs):

        # Python super() function allows us to
        # refer to the parent class explicitly.

        super(Button_Widget, self).__init__(**kwargs)

        # creating Button
        btn1 = Button(text='Hello World 1', font_size="15sp",
                      background_color=(1, 1, 1, 1),
                      color=(1, 1, 1, 1),
                      # size =(32, 32),
                      # size_hint =(.2, .2),
                      pos=(300, 250))

        # Arranging a callback to a button using
        # bind() function in kivy.
        btn1.bind(on_press=self.callback)
        self.add_widget(btn1)

    # callback function tells when button pressed
    # It tells the state and instance of button.
    def callback(self, instance):
        print("Button is pressed ")
        print('The button % s state is <%s>' % (instance, instance.state))

# create App class


class ButtonApp(App):

    def build(self):
        # return the widget
        return Button_Widget()


# run the App
if __name__ == "__main__":
    ButtonApp().run()

output



Once you click hello world1 button, it changes to blue.


Ex 7 kivyApp7.kv

from kivy.uix.pagelayout import PageLayout
import kivy

# base Class of your App inherits from the App class.
# app:always refers to the instance of your application
from kivy.app import App
kivy.require('1.9.0')

# The PageLayout class is used to create
# a simple multi-page layout,
# in a way that allows easy flipping from
# one page to another using borders.

# creating the root widget used in .kv file


class PageLayout(PageLayout):
    pass

# creating the App class in which name
# .kv file is to be named PageLayout.kv


class PageLayoutApp(App):
    # defining build()
    def build(self):
        # returning the instance of root class
        return PageLayout()


# creating object of PageLayoutApp() class
plApp = PageLayoutApp()

# run the class
plApp.run()

pagelayout.kv 

# creating simple Pagelayout using.kv


# creating simple Pagelayout using.kv

# creating page Layout
<PageLayout>:

    # Creating Page 1
   
    # Using BoxLayout inside PageLayout
    BoxLayout:

        # creating Canvas
        canvas:
            Color:
                rgb: 0, .5, .95, 1
            Rectangle:
                pos: self.pos
                size: self.size

        # Providing orientation to the BoxLayout
        orientation: "vertical"

        # creating Button
        Button:
            text: "Page 1"
            size_hint_y: .4

        # Adding Label to Page 1
           
        Label:
            markup: True
            text: "RMC"
            color: 0, 0, 0, 1
            outline_color: 0, 0.5, 0.5, 1
            font_size: 30


    # Creating Page 2
    BoxLayout:
        orientation: "vertical"
       
        canvas:
            Color:
                rgba: 109 / 255., 8 / 255., 57 / 255., 1
            Rectangle:
                pos: self.pos
                size: self.size
        Label:
            markup: True
            text: " Kivy[b]PageLayout[/b]!!!!! "
            color: 0, 0, 0, 1
            outline_color: 0, 0.5, 0.5, 1
            font_size: 30

           
        Button:
            text: "Page 2"
            size_hint_y: .2


    # Creating Page 3
    BoxLayout:
       
        orientation: 'vertical'

        canvas:
            Color:
                rgba: 100 / 555., 9 / 155., 37 / 455., 1
            Rectangle:
                pos: self.pos
                size: self.size

        Label:
            text: 'page 3'

        # This Image is directly from the websource
        # By using AsyncImage you can use that
        AsyncImage:
            source: 'http://kivy.org/logos/kivy-logo-black-64.png'
       


    # Creating Page 4
    Button:
        # Adding image
        # image must be .png
        # and present at the same folder where
        # .kv and main file is saved
        Image:
            source: "download.png"
            center_x: self.parent.center_x
            center_y: self.parent.center_y


output:



You can go to any page by pulling the pages.



Pl refer kivy Tutorials : 

1. Tutorials — Kivy 2.1.0 documentation

2. Kivy Tutorial - GeeksforGeeks













Making Prompts for Profile Web Site

  Prompt: Can you create prompt to craft better draft in a given topic. Response: Sure! Could you please specify the topic for which you...