30, మే 2025, శుక్రవారం

java.rmi.................securitymanager........

 

java.rmi.RMISecurityManager Class in Java


The RMISecurityManager enforces the security policy for classes that are loaded as stubs for remote objects, by overriding all of the relevant access-check methods from the SecurityManager. By default, stub objects are only allowed to perform class definition and class access operations. 

Note: 

  • If the local security manager is not an RMISecurityManager using the System.setSecurityManager() method
  • Then stub classes will only be loadable from the local file system.
java.lang.Object
java.lang.SecurityManager
java.rmi.RMISecurityManager

Syntax:

public class RMISecurityManager 
extends SecurityManager

Note: A subclass of SecurityManager used by RMI applications that use downloaded code. 

RMI's class loader will not download any classes from remote locations if no security manager has been set. RMISecurityManager does not apply to applets, which run under the protection of their browser's security manager. RMISecurityManager implements a policy that is no different than the policy implemented by SecurityManager. Therefore an RMI application should use the SecurityManager class or another application-specific SecurityManager implementation instead of this class.

How to incorporate the Security Manager class? 

To use a SecurityManager in your application, add the following statement to your code (it needs to be executed before RMI can download code from remote hosts, so it most likely needs to appear in the main method of your application)

Syntax:

System.setSecurityManager(new SecurityManager());

RMISecurityManager implements a policy identical to the policy implemented by SecurityManager. RMI applications should use the SecurityManager class or another appropriate SecurityManager implementation instead of this class. RMI's class loader will download classes from remote locations only if a security manager has been set.

Now let us move forward with the constructor of this class as follows:

  • RMISecurityManager(): Constructs a new RMISecurityManager

Implementation:

if (System.getSecurityManager() == null) 
{
    // Setting the RMISecurityManager on System
    System.setSecurityManager(new SecurityManager());
} 

Applets typically run in a container that already has a security manager, so there is generally no need for applets to set a security manager. If you have a standalone application, you might need to set a SecurityManager in order to enable class downloading. This can be done by adding the following to your code. (It needs to be executed before RMI can download code from remote hosts, so it most likely needs to appear in the main method of your application as can better be perceived from the below illustrations.

Illustration 1:

// Protected synchronized method
protected static synchronized void setSecurityManager() 
{
    if (System.getSecurityManager() == null) 
    {
        // Setting the RMISecurityManager on System
        System.setSecurityManager(new RMISecurityManager());
    }
}

Illustration 2:

// Synchronized method
synchronized static void ensureSecurityManager() 
{
    if (System.getSecurityManager() == null) 
    {
        // Setting the RMISecurityManager on System
        System.setSecurityManager(new RMISecurityManager());
    }
}

Illustration 3:  

// Protected synchronized method
protected static synchronized void setSecurityManager() 
{
    if (System.getSecurityManager() == null) 
    {
        // Setting the RMISecurityManager on System
        System.setSecurityManager(new RMISecurityManager());
    }
}

Example

// Java Program to Illustrate RMISecurityManager Class
// Via creating Registry and Rebinding Service

// Importing required classes
import java.lang.Object;
import java.lang.SecurityManager;
import java.rmi.RMISecurityManager;

// Main class
class GFG {

    // Main driver method
    public static void main(String[] args)
    {

        // Try block to check for exceptions
        try {

            // Setting the RMISecurityManager on System
            System.setSecurityManager(
                new RMISecurityManager());
            RmiService service = new RmiServiceImpl();

            // First we will be creating registry
            // using createRegistry() method
            LocateRegistry.createRegistry(6600);

            // Now rebinding the service
            // using rebind method
            Naming.rebind(
                "rmi://127.0.0.1:6600/PersonService",
                service);

            // Display message on the console for
            // successful execution of the program
            System.out.println("Service Start!");
        }

        // Catch block to handle exceptions
        catch (Exception e) {

            // Printing the line number where exception
            // occurred using printStackTrace() method
            e.printStackTrace();
        }
    }
}

Output: 

Service Start!

On console, we will land up to a display message as 

Machine Learning (ML) Traditional programming uses algorithms to produce results from data: Data + Algorithms = Results Machine learning creates algorithms from data and results: Data + Results = Algorithms #machinelearning #ArtificialIntelligence #AI #data #algorithm #deeplearning #neuralnetworks #BigData

 

21, మే 2025, బుధవారం

res post

xml concepts.............unit4

 

Sample XML and XSD Files (SAX Validator)

 

[This sample application uses a feature that was first implemented in MSXML 4.0.]

This example attempts to validate an XML data file (books.xml) against an XML schema definition file (books.xsd). According to books.xsd, each <book> element must have a <pub_date> child element. The second <book> element in books.xml does not have this required element. Therefore, when we attempt to validate the XML file , we should get a validation error.

To create books.xsd and books.xml

  1. Open Notepad.

  2. Copy the code for books.xsdand paste it into Notepad.

  3. From Notepad, save the file as books.xsd to the same folder where you are creating the SAX Validator application.

  4. Copy the code for books.xml and paste it in Notepad.

  5. Save the file as books.xml to the same folder where you are creating the SAX Validator application.

XML File (books.xml)

XML                 <?xml version="1.0"?>
<x:books xmlns:x="urn:books">
   <book id="bk001">
      <author>Writer</author>
      <title>The First Book</title>
      <genre>Fiction</genre>
      <price>44.95</price>
      <pub_date>2000-10-01</pub_date>
      <review>An amazing story of nothing.</review>
   </book>

   <book id="bk002">
      <author>Poet</author>
      <title>The Poet's First Poem</title>
      <genre>Poem</genre>
      <price>24.95</price>
      <review>Least poetic poems.</review>
   </book>
</x:books>

XSD File (books.xsd)

XML
               <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="urn:books"
            xmlns:bks="urn:books">

  <xsd:element name="books" type="bks:BooksForm"/>

  <xsd:complexType name="BooksForm">
    <xsd:sequence>
      <xsd:element name="book" 
                  type="bks:BookForm" 
                  minOccurs="0" 
                  maxOccurs="unbounded"/>
      </xsd:sequence>
  </xsd:complexType>

  <xsd:complexType name="BookForm">
    <xsd:sequence>
      <xsd:element name="author"   type="xsd:string"/>
      <xsd:element name="title"    type="xsd:string"/>
      <xsd:element name="genre"    type="xsd:string"/>
      <xsd:element name="price"    type="xsd:float" />
      <xsd:element name="pub_date" type="xsd:date" />
      <xsd:element name="review"   type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="id"   type="xsd:string"/>
  </xsd:complexType>
</xsd:schema>

16, మే 2025, శుక్రవారం

Qs&Qc in Se

 Quality assurance (QA) focuses on preventing defects by ensuring processes are effective, while quality control (QC) focuses on identifying and fixing defects after the product is createdQA is a proactive approach to maintaining quality throughout the development process, while QC is a reactive approach that checks the final product. 

Key Differences:
  • Focus:
    QA focuses on the processes and systems used to create a product, while QC focuses on the product itself. 
  • Timing:
    QA activities occur throughout the development process, while QC activities occur after the product is completed. 
  • Role:
    QA is a staff function, meaning it's a supportive function that provides expertise and guidance, while QC is a line function, meaning it's directly involved in the production process. 
  • Purpose:
    QA aims to prevent defects from occurring, while QC aims to identify and fix defects that have already occurred. 
  • Responsibility:
    QA is the responsibility of the entire team, while QC is the responsibility of specific personnel. 
In essence: QA builds confidence in the process, while QC checks the final product. Both are crucial for ensuring high-quality products and services
A Deque (Double-Ended Queue) has diverse applications in computer science, particularly in data structures and algorithms. It's versatile enough to act as both a stack and a queue, allowing insertions and deletions from either end. 
Key Applications:
  • Web Browser History:
    Dqueues can efficiently store a browser's history, allowing users to navigate back and forth. 
  • Undo/Redo Functionality:
    Many software applications utilize deques to manage a list of undo/redo operations, enabling users to revert changes. 
  • Task Scheduling:
    Dqueues can be used in task scheduling algorithms, especially in multi-processor systems. 
  • Palindrome Checking:
    A deque can be used to check if a string is a palindrome by comparing elements from both ends. 
  • Priority Queues:
    Dqueues can be used to implement priority queues where elements can be added or removed from either end,. 
  • Implementation of Stacks and Queues:
    Deques can be used to implement standard stacks and queues, providing flexibility in managing the order of elements. 
  • Sliding Window Algorithms:
    In algorithms that involve a sliding window, a deque can efficiently store and update elements within the window. 
  • Disk Scheduling:
    Dqueues can be used in disk scheduling algorithms, allowing for flexible access to data. 
  • Other Applications:
    Deques are also useful in various other scenarios where you need to add or remove elements from both ends, such as in certain graph algorithms or in managing lists of objects where order matters from both directions