Posts

Showing posts from May, 2017

magical vowels problems

Consider following letters :  a, e, i, o, u print Magical subsequence of the string that contains all five vowels in order.  import java.util.regex.Matcher; import java.util.regex.Pattern; public class OnMobile { public static int i=1; static char getNext(){ i=i+1;     String s2="aeiou";     if(i>s2.length()){         i=i-2;     }     else if(i==s2.length()){         i=i-1;     }     return s2.charAt(i);      }     static int longestSubsequence(String s) {      Pattern pattern = Pattern.compile(".a.e.i.o.u.");      Matcher matcher = pattern.matcher(s);      boolean matchFound = matcher.matches();      if(!matchFound){      return 0;      }             int count=0;

Windows cannot be installed to this disk. The selected disk is not of the GPT partition style

Image
Installing using the MBR or GPT partition style "Windows cannot be installed to this disk. The selected disk is not of the GPT partition style" Step:         Exit your Windows Setup     Press shift + f10   ( command prompt will open) Enter :   diskpart                list disk               select disk 0               clean               exit Your are done Process with windows installation

java program to rotate an array n time

 Rotating an array n number of time public class ArrayRotation { public static void main(String[] args) { int rotate= 5; int arr2[]={0,1,2,3,4,5,6,7,8,9,10}; int temp=0; int a; int b; while(rotate!=0){ for(int i=0;i<arr2.length;i++){ if(i==0) { a=arr2[i]; arr2[i]=arr2[arr2.length-1]; } else a=temp; if(i<arr2.length-1)  b=arr2[i+1]; else b=0; temp=b; if(i<arr2.length-1) arr2[i+1]=a; System.out.print(arr2[i]+" "); } rotate--; System.out.println(); } } } Output 10 0 1 2 3 4 5 6 7 8 9  9 10 0 1 2 3 4 5 6 7 8  8 9 10 0 1 2 3 4 5 6 7  7 8 9 10 0 1 2 3 4 5 6  6 7 8 9 10 0 1 2 3 4 5 

java environment setup

download and install java ( Click to Download ) windows admin user Select Start, select Control Panel. double click System, and select the Advanced tab. Or go to your computer in the address bar copy paste ( Control Panel\System and Security\System ) Click Environment Variables In the Edit System Variable new add variable name JAVA_HOME                 variable value C:\Program Files\Java\jdk1.8.0_111 Edit PATH  Add at the end of PATH variable ;  ';'  symbol add %JAVA_HOME%\bin; Ok Non admin user Select Start, select Control Panel. double click System, and select the Advanced tab. Or go to your computer in the address bar copy paste ( Control Panel\System and Security\System ) Click  Environment Variables In the Edit User Variables

Introduction to java

Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation). Java is "write once, run anywhere" meaning that compiled Java code can run on all platforms that support Java without the need for recompilation. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM).

volatile keyword in Java best explanation

Image
volatile Keyword use to maintain a variable in Main memory .      class text      {           static int i= 6;      } Suppose that two threads are working on text.i If two threads run on different processors, If one thread modifies its value the change reflect to other threads and in the original main memory. volatile variables are not create local copy. volatile would not be sufficient to make thread-safe, synchronization would still be needed. Using volatile variables reduces the risk of memory, because any write to a volatile variable establishes a happens-before relationship with subsequent reads of that same variable. This means that changes to a volatile variable are always visible to other threads. read more about mutual exclusion , visibility and Atomic .

Cryptography Engine Classes

The following engine classes are available: SecureRandom : used to generate random or pseudo-random numbers.              SecureRandom secureRandom = new SecureRandom()              secureRandom.getInstance();              secureRandom.getInstanceStrong()              synchronized public void setSeed(byte[] seed)              public void setSeed(long seed)              synchronized public void nextBytes(byte[] bytes)              byte[] generateSeed(int numBytes) MessageDigest : used to calculate the message digest (hash) of specified data. Signature : initialized with keys, these are used to sign data and verify digital signatures. Cipher : initialized with keys, these used for encrypting/decrypting data. There are various types...

Introduction to Cryptography

         Cryptography is the practice and study of hiding and secure information such as security, including language safety, cryptography, public key infrastructure, authentication, secure communication, and access control.

java program to read text from html file

import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.net.URLConnection; import java.io.*; import java.net.*; import javax.swing.text.*; import javax.swing.text.html.*; public class ReadTextFromHTML { public static void main(String[] args) throws Exception{  EditorKit kit = new HTMLEditorKit();         Document doc = kit.createDefaultDocument();         // The Document class does not yet handle charset's properly.         doc.putProperty("IgnoreCharsetDirective", Boolean.TRUE);         // Create a reader on the HTML content.         Reader rd = getReader("http://theprogrammersfirst.blogspot.com/2016/06/javalangexception-error-getting-all.html");         // Parse the HTML.         kit.read(rd, doc, 0);       ...

java reading xml from http

import java.io.File; import java.net.URL; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class ReadXml { public static void main(String[] args) { try {          String path="http://theprogrammersfirst.blogspot.com/sitemap.xml";          DocumentBuilderFactory dbFactory              = DocumentBuilderFactory.newInstance();          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();          Document doc = dBuilder.parse(new URL(path).openStream());          doc.getDocumentElement().normalize();          System.out.println("Root element :"              + doc.getDocumentElement().ge...

Website URL name regular expression validator

Java Best Website URL name regular expression validator public class Utility { public static boolean isValidURL(String url)   { String urlPattern = "^http(s{0,1})://[a-zA-Z0-9_/\\-\\.]+\\.([A-Za-z/]{2,5})[a-zA-Z0-9_/\\&\\?\\=\\-\\.\\~\\%]*";     if (url.matches(urlPattern))       return true;     else return false;   } }

Understanding Java cookies with example

Cookies are process stored data on the client computer browser and they are kept for various information tracking purpose. Static content are form server side pushed into client machine, so that its process and load data faster. Step to Sending Cookies to the Client Sending cookies to the client involves three steps 1. Creating a Cookie object:       You call the Cookie constructor with a cookie name and a cookie value, both of which are strings. 2. Setting the maximum age:       If you want the browser to store the cookie on disk instead of just keeping it in memory, you use         setMaxAge to specify how long (in seconds) the cookie should be valid. 3. Placing the Cookie into the HTTP response headers:     You use response.addCookie to accomplish this. If you forget this step, no cookie is sent to the            browser

robert bosch payslip

java static keyword best explanation

Image
Java static keyword:               static keyword to create fields and methods that belong to the class, rather than to an instance of the class. The static can be used in: variable method block nested class Example: class Test{ static int a = 10;          int b = 10;  public static void main(String args[]){

class loader Example

Java Class.forName( ) Example

irctc multiple ticket cancellation

How to cancel 2 tickets out of 4 tickets from IRCTC website? how to cancel 1 ticket out of 2 in irctc? Yes, It is possible . You can cancel a single passenger from ticket from irctc Follow these steps Login to IRCTC 1. Go to Services > Cancel Ticket 2. Cancel E-ticket option on irctc website 3. Select the ticket and click on Cancel ticket button  (Now a window will open with passenger names and a check box on right hand side) 4. Click on the checkbox for the passengers for whom ticket is to be cancelled 5. Click on cancel ticket button below.