Sunday, February 16, 2020

Tree Traversals Program in java ( Preorder | PostOrder | InrderOrder )


TREE PROGRAM

                      Tree Traverseral ( PreOrder | PostOrder| InOrder )

class Node{
int key;
Node left,right;
public Node(int value){
key = value;
left = right = null;
     }
     }

public class BinaryTree {
Node root;
BinaryTree(int value){
root = new Node(value);
}
BinaryTree() {
root = null;
}

public void printInorder(Node node){
if(node == null)
{
return ;
}
printInorder(node.left);
System.out.print(node.key+ " ");
printInorder(node.right);
}
  
   void printInorder() {
   System.out.println("Inorder Traversal");
   printInorder(root);

}
   void printPreOrder(Node node){
   if(node == null)
   return;
   System.out.print(node.key+" ");
   printPreOrder(node.left);
   printPreOrder(node.right);
  
   }
   void printPreOrder(){
   System.out.println("Pre-order Traversal");
   printPreOrder(root);
   }
   void printPostOrder(Node node){
   if(node == null)
   return;
 
   printPreOrder(node.left);
   printPreOrder(node.right);
   System.out.print(node.key+" ");
  
   }
   void printPostOrder(){
   System.out.println("Pre-order Traversal");
   printPostOrder(root);
   }
  
public static void main(String []args){
BinaryTree tree = new BinaryTree();
tree.root = new Node(1);
tree.root.left = new Node(2);
tree.root.right = new Node(3);
tree.root.left.left = new Node(4);

tree.root.left.right = new Node(5);
tree.root.right.left= new Node(6);
tree.root.right.right = new Node(7);

tree.printInorder();
tree.printPreOrder();
tree.printPostOrder();



}
}


 OUTPUT :
Inorder Traversal
4 2 5 1 6 3 7 Pre-order Traversal
1 2 4 5 3 6 7 Pre-order Traversal
2 4 5 3 6 7 1 



Sunday, February 9, 2020

Introduction to Java Security

Introduction to Java Security

 The Java security architecture includes a large set of application programming interfaces (APIs), tools, and implementations of commonly-used security algorithms, mechanisms, and protocols.
The Java security APIs span a wide range of areas. Cryptographic and public key infrastructure (PKI) interfaces provide the underlying basis for developing secure applications. Interfaces for performing authentication and access control enable applications to guard against unauthorized access to protected resources.
The JDK includes a number of providers that implement a core set of security services. It also allows for additional custom providers to be installed. This enables developers to extend the platform with new security mechanisms.
The JDK is divided into modules. Modules that contain security APIs include the following:

Module
Description
Defines the foundational APIs of Java SE;
 contained packages include java.securityjavax.cryptojavax.net.ssl,
Defines the Java binding of the IETF Generic Security Services API (GSS-API).
 This module also contains GSS-API mechanisms including Kerberos v5 and SPNEGO
Defines Java support for the IETF Simple Authentication and Security Layer (SASL).
Defines the Java Smart Card I/O API
Defines the API for XML cryptography




















Java Language Security and Bytecode Verification

The Java language is designed to be type-safe and easy to use. It provides automatic memory management, garbage collection, and range-checking on arrays. This reduces the overall programming burden placed on developers, leading to fewer subtle programming errors and to safer, more robust code.
A compiler translates Java programs into a machine-independent bytecode representation. A bytecode verifier is invoked to ensure that only legitimate bytecodes are executed in the Java runtime. It checks that the bytecodes conform to the Java Language Specification and do not violate Java language rules or namespace restrictions. The verifier also checks for memory management violations, stack underflows or overflows, and illegal data typecasts. Once bytecodes have been verified, the Java runtime prepares them for execution.
In addition, the Java language defines different access modifiers that can be assigned to Java classes, methods, and fields, enabling developers to restrict access to their class implementations as appropriate. The language defines four distinct access levels:
  • private: Most restrictive modifier; access is not allowed outside the particular class in which the private member (a method, for example) is defined.
  • protected: Allows access to any subclass or to other classes within the same package.
  • Package-private: If not specified, then this is the default access level; allows access to classes within the same package.
  • public: No longer guarantees that the element is accessible everywhere; accessibility depends upon whether the package containing that element is exported by its defining module and whether that module is readable by the module containing the code that is attempting to access it.

Secure Communication 

The data that travels across a network can be accessed by someone who is not the intended recipient. When the data includes private information, such as passwords and credit card numbers, steps must be taken to make the data unintelligible to unauthorized parties. 

  1. TLS and DTLS Protocols
  2. Generic Security Service API and Kerberos
  3. Simple Authentication and Security Layer (SASL)


Simple Authentication and Security Layer(SASL)
Simple Authentication and Security Layer (SASL) is an Internet standard that specifies a protocol for authentication and optional establishment of a security layer between client and server applications
                               for more detail visit Java Documentation.



Tuesday, January 21, 2020

Converting Integers to Roman Numerals - Java


     Roman Number are a system of numerical notations used by the Romans.

1= I
5= V
10= X
50= L
100= C
500= D
1000= M = I
5000V
10,000X
50,000L
100,000C = I
500,000D = V
1,000,000M = X
5,000,000V = L
10,000,000X = C
50,000,000L = D
100,000,000 C = M
500,000,000 D
1,000,000,000M
nn = 1000×nnnn = 100,000×nnnn = 1,000,000×nn

                                                                                                                                                            























import java.util.*; class RomanCounting { public static void main(String[] args) { int num; System.out.println("please the number smallest than 999999"); System.out.println("According to automated program show 5000 as |V| and 10000 as |X| " + "and \n 50000 " + "as |L| and 100000 as |C| and 500000 as |D| and last as 1000000 as |M| "); Scanner obj = new Scanner(System.in); num = obj.nextInt(); String str = String.valueOf(num); char []arr = str.toCharArray(); int len = str.length(); int count[] = new int[10]; for(int i=0;i<len;i++){ count[i] = (int)arr[i]-48; } String ones[] = new String[]{"","I","II","III","IV","V","VI","VII","VIII","IX","X"}; String tens[] = new String[]{"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC","C"}; String hundred[] = new String[]{"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM","M"}; String thousand[] = new String[]{"","M","MM","MMM","MMMM","|V|","|V|M","|V|MM","|V|MMM", "M|X|","|X|"}; String TenThousand[] = new String[]{"","|X|","|X||X|","|X||X||X|","|X||L|","|L||X|", "|L||X||X|","|L||X||X|","|C||L|","|C|"}; String[] HundredThousand = new String[]{"","|C|","|C||C|","|C||C||C|","|C||D|","|D|", "|D||C|","|D||C||C|","|D||M|","|M|"}; if(len==6){ String romancounting = HundredThousand[count[0]]+ TenThousand[count[1]]+ thousand[count[2]] + hundred[count[3]] + tens[count[4]] + ones[count[5]]; System.out.println(romancounting); } else if(len==5){ String romancounting = TenThousand[count[0]]+ thousand[count[1]]+ hundred[count[2]] + tens[count[3]] + ones[count[4]]; System.out.println(romancounting); } else if(len==4){ String romancounting = thousand[count[0]]+ hundred[count[1]] + tens[count[2]] + ones[count[3]]; System.out.println(romancounting); } else if(len==3) { String romancounting = hundred[count[0]]+tens[count[1]]+ones[count[2]]; System.out.println(romancounting); } else if(len==2){ String romancounting = tens[count[0]]+ones[count[1]]; System.out.println(romancounting); } else{ System.out.println("Sorrt But number is invalid! OutOfRange👌"); } System.out.println("Thanks for using your automated software"); } }

For Output : OUTPUT

Friday, January 17, 2020

Count the Occurrence of Character in the Linked List

~ Create an array.
~ One By One place the  character on array  on based on ASCII Value .
~ then, check the value of every index and find greater value/Occurence of Character.
public class LinkedlistOperation {

 Node head;
     class Node{
        int data;
        Node next;
           Node(int d){
               data =d;
               next = null;
       }    }


 public void OccurrenceNumber(){
    Node current= head;
    int arr[] = new int[256];
    while(current!=null){
       (arr[current.data])++;
       current =current.next;
          }
    System.out.println("Occurrence of all character are :");

    for(int i=0;i<256;i++){
        if(arr[i]>0){
          System.out.println(i+":" +arr[i]+" ");
   } } }


 public static void main(String ...args){
 LinkedlistOperation list = new LinkedlistOperation();
   list.push(1);
   list.push(1);
   list.push(3);
   list.push(4);
   list.push(2);
   list.push(2);
   list.push(15);
   list.push(20);
   list.push(1);
   list.push(1);
   list.push(3);
   list.push(4);
   list.push(5);
  list.OccurrenceNumber()  }
 OUTPUT :

Occurence of all Character are :
1:4 
2:2 
3:2 
4:2 
5:1 
15:1 
20:1 


Thursday, January 16, 2020

Insertion Node in the Linkelist.

In this post, methods to insert a new node in linked list are discussed. A node can be added in three ways
1) At the front of the linked list
2) After a given node.
3) At the end of the linked list
public class Linkedlist {
 Node head;
 class Node{
  int data;
  Node next;
  Node(int d){
   data =d;
   next=null;
  } 
 }
// INSERT THE NODE AT THE BEGIN OF LINKEDLIST.

 
 public void insertAtfront(int new_data){
  
//  Node temp = head;
  Node new_node = new Node(new_data);
  new_node.next = head;
  head = new_node;
  
 } 
// INSERT THE NODE AT THE GIVEN POSITION IN LINKEDLIST.

 public void insertAtGiven(Node prev_node,int new_data)
 {
  if(prev_node == null){
   System.out.print("previous node can't be null");
   return;
   
  }
  Node new_node = new Node(new_data);
  new_node.next = prev_node.next;
  prev_node.next = new_node;
 }
// INSERT THE NODE  AT THE END OF THE LINKEDLIST.  

 public void insertAtEnd(int new_data){
  
  Node new_node = new Node(new_data);
  new_node.next = null;
  Node last = head;
  while(last.next!=null){
   last = last.next;
  
  }
  last.next= new_node;
  return;
  
 }
// TRAVERSING THE ELEMENT OF LINKEDLIST

 
 public void showlist(){
  Node tnode= head;
  while(tnode!=null){
   System.out.print(tnode.data+" ");
   tnode = tnode.next;
  }
 }
 // MAIN FUNCTION 

public static void main(String ...args) { list.insertAtfront(10); list.insertAtfront(12); list.insertAtfront(14); list.insertAtfront(16); list.insertAtfront(18); list.insertAtfront(19); list.insertAtGiven(12,20); list.insertAtGiven(20,22); list.insertAtEnd(24); list.showlist(); } }

Thursday, December 19, 2019

Launch of 5G chipsets by Qualcomm for AR/VR Headsets

Virtual reality (VR) and augmented reality (AR) is all set to transform the way users used to access technology. The headsets can take you to places and show things that don't even exist in the real world. Qualcomm's all-new AR/VR tech brings 5G support and caters to the needs of standalone VR, AR headsets.

Qualcomm claims that the XR2 chip is in line with the company's new mobile chips, including the most awaited Snapdragon 865, 765, and 765G. These chipsets support 5G mobile network connectivity. Qualcomm believes that the future of mobile devices is an aggregate of different display technologies. The VR headsets can be used for various uses cases, right from web browsing, to recipe tutorials and even GPS navigation.

In an official statement, Qualcomm said, "Multiple OEMs are committed to commercializing devices with the Snapdragon XR2 Platform, and other customers are in various stages of prototyping and evaluation."

The XR2 5G platform is designed to support 3K x 3K displays at 90Hz. It will offer accelerated AI processing, and work with up to seven simultaneous camera feeds. The XR2 is a successor to the Snapdragon XR1 which was made especially for the low-end AR and VR headsets.

The latest iteration of the chipset targets high-end standalone headsets including Oculus Quest 2, Magic Leap 2, and similar next-generation devices. The new platform offers notable improvements. Qualcomm claims that the CPU and GPU performance by 2x, pixel throughput for video playback by 4x, and up to 6x resolution per-eye compared to Snapdragon 835.

The simultaneous camera will support advanced tracking, both for the environment and the user. Oculus Quest features four cameras that can track the position of headset and controllers. XR2 offers low-latency pass-through, which improves the pass-through video experience on high-end headsets.

C++ program to convert Sorted Array to binary search tree

Binary Search Tree is a node-based binary tree data structure which has the following properties:
  • The left subtree of a node contains only nodes with keys lesser than the node%u2019s key.
  • The right subtree of a node contains only nodes with keys greater than the node%u2019s key.
  • The left and right subtree each must also be a binary search tree.
Algorithm
The mid-value of the given sorted array would represent the root of one possible BST that can be constructed from the given array elements.
1. Find the middle element of the array and make it root(Now the array is divided into two halves left and right, where the left half is our left subtree and right half, is our right subtree)
2. Recursively do the same for the left half and right half.
       (a) Get the middle of left half and make it left child of the root created into Step 1.
       (b) Get the middle of right half and make it right child of the root created into Step 1.
3. The base condition that would terminate the recursion would then be if low boundary index            exceeds high boundary index, in which case return null.

#include<iostream> using namespace std; struct Node { int data; Node *left; //pointer points to left node Node *right; //pointer points to right node }; /*function that returns new node*/ Node *newNode(int x) { Node *temp = new Node(); //temp points to the dyanamically formed node temp->data = x; temp->left = NULL; temp->right = NULL; return temp; //return the address of the node temp is pointing } Node *arrayToBST(int *arr, int start, int end) { /* Base Case*/ if(start > end) { return NULL; } /*Get the middle element and make it root*/ int mid = (start + end)/2; Node *root = newNode(arr[mid]); /* Recursively construct the left subtree and make it left child of root */ root->left = arrayToBST(arr,start,mid-1); /* Recursively construct the right subtree and make it right child of root */ root->right = arrayToBST(arr,mid+1,end); return root; } /*Function inOrder prints inorder traversal of the tree inorder traversal prints element in sorted order
*/ void inOrder(Node *node) { if(node == NULL) return; inOrder(node->left); cout<<node->data<<" "; inOrder(node->right); } int main() { int arr[] = {2, 4, 5, 6, 7, 10, 11, 15}; /*Number of elements in the array (total size of the array / size of one element ) In this case elements are integer */ int n = sizeof(arr)/sizeof(arr[0]); Node *root = arrayToBST(arr,0,n-1); inOrder(root); return 0; }

OUTPUT:
2 4 5 6 7 10 11 15

Our inorder traversal prints elements in sorted order, so our binary search tree is correct.
Time Complexity

T(n) = 2T(n/2) + C
By Master Theorem
T(n) = O(n)

Arrays in Solidity Programming Language.

Arrays Solidity supports both generic and byte arrays. It supports both fixed size and dynamic arrays. It also supports multidimensional ...