Generate Alpha Numeric String for the given size


import java.util.Random; import java.util.Scanner; public class GenerateAlphaNumericStringUsingGivenNo { public static void main(String[] args) { Scanner sc=null; int size=0; System.out.println("Enter the size"); sc=new Scanner(System.in); //taking the size from the keyboard size=sc.nextInt(); //calling the method to generate AlphaNumericString System.out.println(generate(size)); } //method for generating AlphaNumericString public static String generate(int size) { Random rand=null; StringBuffer sb=null; String numAndChars=null; //all string which will be choosen to generate numAndChars="abcdefghijklmnopqrstuvwxyz" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +"0123456789"; rand=new Random(); sb=new StringBuffer(""); for(int i=0;i<(size);i++) { //logic to generate AlphaNumeric String int index=(int)(numAndChars.length()*Math.random()); //appending the characters one by one sb.append(numAndChars.charAt(index)); } //returning the AlphaNumeric String return sb.toString(); } }
Share:

Java program to find a given number is prime or not


import java.util.Scanner; public class PrimeOrNot { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter any valid integer :"); int num=sc.nextInt(); if(isPrime(num)) { System.out.println(num+" is a prime number."); } else System.out.println(num+" is not a prime number."); } private static boolean isPrime(int num) { if(num<=0) return false; else if(num==2) return true; else { for(int i=3;i<(num);i++) { if(num%i==0) { return false; } } } return true; } }
Share:

Java program to reverse a String without using predefined methods


import java.util.Arrays; import java.util.Scanner; public class StringReverse { public static void main(String[] args) { String str; //taking string Scanner sc=new Scanner(System.in); System.out.println("Enter the String :"); str=sc.nextLine(); //calling method strReverse(str); } private static void strReverse(String str) { //converting string to character char ch[]=str.toCharArray(); char reverse[]=new char[ch.length]; //logic for reverse a string for(int i=0;i<(ch.length);i++) { reverse[i]=ch[ch.length-i-1]; } //printing the reversed string System.out.println("Reversed String :"); System.out.println(new String(reverse)); } }

Share:

Java program to find two Strings are anagrams or not


import java.util.Arrays; import java.util.Scanner; public class TwoStringAnagram { public static void main(String[] args) { String str1; String str2; //taking values Scanner sc=new Scanner(System.in); System.out.print("Enter first String :"); str1=sc.nextLine(); System.out.print("Enter second String :"); str2=sc.nextLine(); int count=0; //converting to character array char ch1[]=str1.trim().toCharArray(); char ch2[]=str2.trim().toCharArray(); //logics for anagrams if(ch1.length==ch2.length) { //sorting Arrays.sort(ch1); Arrays.sort(ch2); for(int i=0;i<(ch1.length);i++) { if(ch1[i]==ch2[i]) { count++; } } if(count==ch1.length) { System.out.println("Two strings are anagrams"); } else System.out.println("Not anagrams!!!!"); } else { System.out.println("!!!Insert valid Strings or string of same size!!!"); } } }
Share:

All occurences of character present in Given String


import java.util.HashMap; import java.util.Map; import java.util.Scanner; import java.util.concurrent.SynchronousQueue; public class StringOccurence { public static void main(String[] args) { String str; Scanner sc; System.out.print("Enter the string :"); sc=new Scanner(System.in); str=sc.next(); //Method Call printOccurence(str); } //method for printing occurences private static void printOccurence(String str) { //creating one map HashMap map=new HashMap(); char[] charArr=str.replaceAll("\\s","").toLowerCase().toCharArray(); //logic to detect and store all occurences for(char c:charArr) { if(map.containsKey(c)) { map.put(c,map.get(c)+1); } else { map.put(c,1); } } //logics to print all the occurences for(Map.Entry entry:map.entrySet()) { System.out.print("Key :"+entry.getKey()+" "+"Value :"+entry.getValue()); } } }
Share:

How to disable DVD/CD in Windows

If you can open your computer case, you can pull the plug on your DVD-ROM or CD-ROM drive by literally pulling the plug on its power cable or its data cable. However, it's a pain, and you have to reverse the process if you ever want to use the drive again. It's much easier to disable the device from the Device Manager utility in Windows. That way, you can still insert and remove CDs or DVDs, but you can't read or write discs.
Step 1:- ------------

Right click on My Computer/This Pc and then click on properties then go to the device manager on left side of the window.All devices installed on your system are displayed as a list.

Step 2:- ------------

Double-click the "DVD/CD-ROM drives" node to expand it and display all drives installed on your computer. Note that virtual drives are also listed here. The drives contain the name of their manufacturer, so you can quickly locate the drive you want to disable. Virtual drives usually contain the word "virtual" in their name.

Step 3:- ------------

Double-click the drive to open its Properties window and then click the "Driver" tab to view more information about the device's driver. The driver helps the Windows operating system communicate with hardware devices and control them.

Step 4:- ------------

Click the "Disable" button to disable the device and "Yes" to confirm. Click "OK" to close the Properties window and then close the Control Panel.


Watch Full Video

Please do Like,Share and Suscribe, Thanks

Share:

Spring Web MVC flow

  1. Prgrammer deploys the spring web MVC application to the web-server or Application Server.
  2. Deployment actions takes place on the DispatcherServlet & its supplied IOC container.
  3. Then browser gives request by having url.
  4. As FrontController configured with url-pattern as directory match or extension match, it will traps and takes the request and applies common system services.
  5. Then it hand overs the request to the Handler mapping component, and Handler mapping component will maps that rquest URI to the specific Handler class.
  6. And return the bean id of Handler class to DispatcherServlet.
  7. Then the DispatcherServlet managed IOC container will call the getBean() method and gets Handler class object.
  8. Then DispatcherServlet calls Handler class method on Handler class object, and delegates the request to Handler class.
  9. If request from form page(having request params) then Handler class internally writes the form data to the command class object(a kind of Java bean).
  10. Handler class either directly process the rquest or passes the request to the service for request processing and keeps the generated result/output and Logical view name in ModelAndView class object.
  11. Then method of Handler class returns MAV(ModelAndView) object to DispatcherServlet.
  12. After receiving MAV object DispatcherServlet collects results from MAV object and keeps in request scope and then collects logicalview name for passing to ViewResolver component.
  13. Then DispatcherServlet passes the (logical view name) to ViewResolver.
  14. ViewResolver resolves the name, location and technology of View Resource like jsp page and returns view object having physical view name & location to DispatcherServlet.
  15. After receiving view object from ViewResolver, DispatcherServlet calls render() method on it.
  16. After calling the render() method on view object, it transfers the control to Physical view resource component like(jsp, html pages).
  17. Physical view Resource collects results data from request scope and formats it to send to browser as response.
  18. Browser receives the response and displays it as web page.


Share:

9 Key Interfaces of Collection Framework

     1.Collection :-
    • If we want to represent a group of individual objects as a single entity then we should go for  Collection.
    • Collection interface defines the most common methods which are applicable for any Collection object.
    •  In general  collection interface is considered as root interface of Collection framework.
    • Note:- there is no concrete class which implements collection interface directly.
      2. List :-
    •  List is child interface of Collection.
    • If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order preserved then we should go for List.


f             3. Set :-
    • Set is child interface of Collection.
    • If we want to represent a group of individual objects as a single entity where duplicates are not allowed and insertion order are not preserved then we should go for Set.
              4. SortedSet :-
    •  SortedSet is child interface of Set.
    • If we want to represent a group of individual objects as a single entity where duplicates are not allowed but all objects should be inserted according to some sorting order then we should go for SortedSet
              5. NavigableSet :-
    •      It is the child interface of SortedSet.
    •      It defines several methods for navigable purpose.

            


              6Queue:-

    •      It is child interface of Collection.
    •     If we want to represent a group of individual objects prior to processing then we should go for Queue.
    •     Ex: before sending a mail all mail id’s we have to store somewhere and in which order we saved in the same order mail’s should be delivered(First in First out) for this requirement 
    •      Queue concept is the best choice.
                     Note:-

    •       All the above interfaces (Collection, List, Set, SortedSet, NavigableSet and Queue) meant for representing a group of individual objects.
    •       If we want to represent a group of objects as key value pairs the we should go for Map Interface.
             7. Map
    •         Map is not he child interface of Collection.
    •         If we want to represent a group of individual objects as key value pairs then we should    go for Map. Ex : Roll no. Name
          •         102 Shivaji
          •         103 Anil
          •         104 Chandra
    •         Both key and value are objects.
    •         Duplicated keys are not allowed but values can be duplicated.


                         8. SortedMap

              •         It is the child interface of map.
              •         If we want to represent a group of key value pairs according to some sorting order of keys then we should go for SortedMap.



                         9. NavigableMap(I)

              •            It is the child interface of sorted map, it defines
              •            Several utility methods for navigation purpose.
              •            TreeMap is the implementation class for NavigableMap.





            Share:

            Remote Desktop Connection from Android


            Get started with Remote Desktop on Android. You can use the Remote Desktop client for Android to work with Windows apps and desktops directly from your Android device. Get the RD client and start using it.

            Follow these steps to get started with Remote Desktop on your Android device:

            Step 1:- ------------

            Download the Remote Desktop client from Google Play.

            Step 2:- ------------

            Set up your PC to accept remote connections.

            Step 3:- ------------

            Add a Remote Desktop connection or a remote resource. You use a connection to connect directly to a Windows PC and a remote resource to use a RemoteApp program, session-based desktop, or virtual desktop published on-premises.

            Step 4:- ------------

            Create a widget so you can get to Remote Desktop quickly.

            Step 5:- ------------

            Add a Remote Desktop connection

            Share:

            Collection Framework Overview


            Collection:-
            A collection (sometimes called a container) is simply an object that groups multiple elements into single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data. Typically, they represent data items that form a natural group, such as a poker hand (a collection of cards), a mail folder (a collection of letters), or a telephone directory (a mapping of names to phone numbers).

            What is a Collections Framework?
            • A collections framework is a unified architecture for representing and manipulating collections. 

            All collections frameworks contain the following-
            • Interfaces: These are abstract data types that represent collections. Interfaces allow collections to be manipulated independently of the details of their representation.
            • Implementations: These are the concrete implementations of the collection interfaces. In essence, they are reusable data structures.
            • Algorithms: These are the methods that perform useful computations, such as searching and sorting, on objects that implement collection interfaces. The algorithms are said to be polymorphic: that is, the same method can be used on many different implementations of the appropriate collection interface. In essence, algorithms are reusable functionality.

            Benefits of Collections Framework:-
            • Reusability: Java Collections Framework provides common classes and utility methods than can be used with different types of collections. This promotes the reusability of the code. A developer does not have to re-invent the wheel by writing the same method again.
            • Quality: Using Java Collection Framework improves the program quality, since the code is already tested and used by thousands of developers.
            • Speed: Most of programmers report that their development speed increased since they can focus on core logic and use the generic collections provided by Java framework.
            • Maintenance: Since most of the Java Collections framework code is open source and API documents is widely available, it is easy to maintain the code written with the help of Java Collections framework. One developer can easily pick the code of previous developer.
            Difference between Collection and Collections :-
            • Collection is an interface which can be used to represent a group of individual objects as single entity.
            • Collections is an utility class present in java.util.package to define several utility methods (like sorting, searching) on collection objects.


            Share:

            Dispatcher-Servlet Load-On-Startup Activities



            When programmers deploy the Spring web MVC application to web server or application server then deployment actions takes place :

            Part-1
            • web.xml file is loaded and checked for well formness and valid or not.
            • If it is valid and wellformed then in-memory Meta Data will be created for web.xml.
            • Then it will check for Listener, if available then creates listener's object if not left.
            • Then it will create servlet context object.
            • Then it will check for filter, if available then creates the filter's object and do the filtering tasks.
            • Then it will crate servlet config object.
            • If load-on-startup is enabled in web.xml then it will crate an object of DispatcherServlet(means Eager Instantiation of DispatcherServlet).

            Part-2

            • Then init() method of DispatcherServlet is called and creates the IOC container of XmlWebApplicationContext.
            • and after that IOC Container takes dispatcher-servlet.xml of WEB-INF folder as spring bean cfg file.
            • Then it checks for wellformness and valid, if wellformed and valid then its in-memory Meta Data will be created.
            • Then because the container is ApplicationContext Container the pre-instantiation of singleton scope spring beans and injections will takes place.
            Share:

            Serialization and Deserialization in Java with Example

            • Serialization is a mechanism of converting a java object into byte stream.
            • Deserialization is reverse of serialization in which byte stream is converted back to a java object in memory.
            • Byte stream created is platform independent so, the object serialized on one platform can be deserialized on other platform.
            • For making java object serializable we must have to implements java.io.Serializable interface.
            • We can serialize an object from writeObject() method which is defined in ObjectOutputStream class.
            • We can deserialize an object from readObject() method which is defined in ObjectInputStream class.


                Serialization and De-Serialization Example :-

            import java.io.*; 
            class Emp implements Serializable { 
             private static final long serialversionUID =129348938L; 
             transient int a; 
             int b; 
             String name; 
             int age; 
             public Emp(String name, int age, int a, int b) 
             { 
              this.name = name; 
              this.age = age; 
              this.a = a; 
              this.b = b; 
             } 
            }
            

            public class SerialExample { 
               public static void printdata(Emp object1) 
               { 
                 System.out.println("name = " + object1.name); 
                 System.out.println("age = " + object1.age); 
                 System.out.println("a = " + object1.a); 
                 System.out.println("b = " + object1.b); 
               } 
               public static void main(String[] args) 
               { 
                 Emp object = new Emp("ab", 20, 2, 1000); 
                 String filename = "shubham.txt"; 
                 // Serialization 
                 try { 
                       // Saving of object in a file 
                       FileOutputStream file = new FileOutputStream(filename); 
                       ObjectOutputStream out = new ObjectOutputStream(file); 
                       // Method for serialization of object 
                       out.writeObject(object); 
                       out.close(); 
                       file.close(); 
                       System.out.println("Object has been serialized\n"
                        + "Data before Deserialization."); 
                       printdata(object); 
                       // value of static variable changed 
                       object.b = 2000; 
                  } 
                  catch (IOException ex) 
                  { 
                       System.out.println("IOException is caught"); 
                  }
                  object = null; 
                  // Deserialization 
                  try { 
                        // Reading the object from a file 
                        FileInputStream file = new FileInputStream(filename); 
                        ObjectInputStream in = new ObjectInputStream(file); 
                        // Method for deserialization of object 
                        object = (Emp)in.readObject(); 
                        in.close(); 
                        file.close(); 
                        System.out.println("Object has been deserialized\n"
                          + "Data after Deserialization."); 
                        printdata(object); 
                        // System.out.println("z = " + object1.z); 
                   } 
                   catch (IOException ex) { 
                        System.out.println("IOException is caught"); 
                   } 
                   catch (ClassNotFoundException ex) { 
                        System.out.println("ClassNotFoundException" + 
                          " is caught"); 
                   } 
                } 
            }
            
            Share:

            Quote of the day

            Popular Posts

            Featured Post

            Collection Framework Overview

            Collection:- A collection (sometimes called a container) is simply an object that groups multiple elements into single unit. Collect...

            Youtube Page

            Facebook Page

            Recent Posts

            About

            I am Shivaji Chandra and I'm a Computer Science Engineer. I love to write poems, jokes and quotes. click here →