Tutorialspoint

Java Internalization - Set Min/Max Precision

import java.text.NumberFormat;
import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");  

      NumberFormat numberFormat = NumberFormat.getInstance(enLocale);
      numberFormat.setMinimumIntegerDigits(2);
      numberFormat.setMaximumIntegerDigits(3);

      numberFormat.setMinimumFractionDigits(2);
      numberFormat.setMaximumFractionDigits(3);

      System.out.println(numberFormat.format(12234.763443));
   }
}

Java Internalization - Format Percentages

import java.text.NumberFormat;
import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");        

      NumberFormat numberFormat = NumberFormat.getPercentInstance(enLocale);

      System.out.println(numberFormat.format(0.76));    
   }
}

Java Internalization - Format Currencies

import java.text.NumberFormat;
import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");  
      Locale daLocale = new Locale("da", "DK");

      NumberFormat numberFormat = NumberFormat.getCurrencyInstance(daLocale);

      System.out.println(numberFormat.format(100.76));

      numberFormat = NumberFormat.getCurrencyInstance(enLocale);

      System.out.println(numberFormat.format(100.76));
   }
}

Java Internalization - NumberFormat Class

import java.text.NumberFormat;
import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale enLocale = new Locale("en", "US");  
      Locale daLocale = new Locale("da", "DK");

      NumberFormat numberFormat = NumberFormat.getInstance(daLocale);

      System.out.println(numberFormat.format(100.76));

      numberFormat = NumberFormat.getInstance(enLocale);

      System.out.println(numberFormat.format(100.76));
   }
}

Java Internalization - Locale Language

import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale defaultLocale = Locale.getDefault();
      Locale enLocale = new Locale("en", "US");  
      Locale frLocale = new Locale("fr", "FR");  
      Locale esLocale = new Locale("es", "ES");

      System.out.println(defaultLocale.getDisplayLanguage(enLocale));
      System.out.println(defaultLocale.getDisplayLanguage(frLocale));
      System.out.println(defaultLocale.getDisplayLanguage(esLocale));
   }
}

Java Internalization - Locale Details

import java.util.Locale;

public class I18NTester {
   public static void main(String[] args) {
      Locale locale =Locale.getDefault();  

      System.out.println("Default Locale Properties:\n");

      System.out.println(locale.getDisplayCountry());  
      System.out.println(locale.getDisplayLanguage());  
      System.out.println(locale.getDisplayName());  
      System.out.println(locale.getISO3Country());  
      System.out.println(locale.getISO3Language());  
      System.out.println(locale.getLanguage());  
      System.out.println(locale.getCountry());  

      Locale frenchLocale = new Locale("fr","fr");

      System.out.println("\nfr Locale Properties:\n");
      System.out.println(frenchLocale.getDisplayCountry());  
      System.out.println(frenchLocale.getDisplayLanguage());  
      System.out.println(frenchLocale.getDisplayName());  
      System.out.println(frenchLocale.getISO3Country());  
      System.out.println(frenchLocale.getISO3Language());  
      System.out.println(frenchLocale.getLanguage());  
      System.out.println(frenchLocale.getCountry());  
   }
}

JSON with Ajax Example

<html>
   <head>
      <meta content = "text/html; charset = ISO-8859-1" http-equiv = "content-type">
		
      <script type = "application/javascript">
         function loadJSON(){
            var data_file = "http://www.tutorialspoint.com/json/data.json";
            var http_request = new XMLHttpRequest();
            try{
               // Opera 8.0+, Firefox, Chrome, Safari
               http_request = new XMLHttpRequest();
            }catch (e){
               // Internet Explorer Browsers
               try{
                  http_request = new ActiveXObject("Msxml2.XMLHTTP");
					
               }catch (e) {
				
                  try{
                     http_request = new ActiveXObject("Microsoft.XMLHTTP");
                  }catch (e){
                     // Something went wrong
                     alert("Your browser broke!");
                     return false;
                  }
					
               }
            }
			
            http_request.onreadystatechange = function(){
			
               if (http_request.readyState == 4  ){
                  // Javascript function JSON.parse to parse JSON data
                  var jsonObj = JSON.parse(http_request.responseText);

                  // jsonObj variable now contains the data structure and can
                  // be accessed as jsonObj.name and jsonObj.country.
                  document.getElementById("Name").innerHTML = jsonObj.name;
                  document.getElementById("Country").innerHTML = jsonObj.country;
               }
            }
			
            http_request.open("GET", data_file, true);
            http_request.send();
         }
		
      </script>
	
      <title>tutorialspoint.com JSON</title>
   </head>
	
   <body>
      <h1>Cricketer Details</h1>
		
      <table class = "src">
         <tr><th>Name</th><th>Country</th></tr>
         <tr><td><div id = "Name">Sachin</div></td>
         <td><div id = "Country">India</div></td></tr>
      </table>

      <div class = "central">
         <button type = "button" onclick = "loadJSON()">Update Details </button>
      </div>
		
   </body>
		
</html>

Bootstrap Default Pager

<!DOCTYPE html>
<html>
   <head>
      <title>Try v1.2 Bootstrap Online</title>
      <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <script src="/bootstrap/scripts/jquery.min.js"></script>
      <script src="/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <ul class="pager">
        <li><a href="#">Previous</a></li>
        <li><a href="#">Next</a></li>
      </ul>
   </body>
</html>

Bootstrap Non-nav Links

<!DOCTYPE html>
<html>
   <head>
      <title>Try v1.2 Bootstrap Online</title>
      <link href="/bootstrap/css/bootstrap.min.css" rel="stylesheet">
      <script src="bootstrap/scripts/jquery.min.js"></script>
      <script src="/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <nav class = "navbar navbar-default" role = "navigation">
         <div class = "navbar-header">
            <a class = "navbar-brand" href = "#">TutorialsPoint</a>
         </div>
         <div>
            <p class = "navbar-text navbar-right">
               Signed in as 
               <a href = "#" class = "navbar-link">Thomas</a>
            </p>
         </div>
      </nav>
   </body>
</html>

JSON array object

<html>
   <head>
      <title>Creation of array object in javascript using JSON</title>
		
      <script language = "javascript" >

         document.writeln("<h2>JSON array object</h2>");

         var books = { "Pascal" : [ 
            { "Name"  : "Pascal Made Simple", "price" : 700 },
            { "Name"  : "Guide to Pascal", "price" : 400 }],  
				
            "Scala"  : [
               { "Name"  : "Scala for the Impatient", "price" : 1000 }, 
               { "Name"  : "Scala in Depth", "price" : 1300 }]    
         }    

         var i = 0
         document.writeln("<table border = '2'><tr>");
			
         for(i = 0;i<books.Pascal.length;i++){	
            document.writeln("<td>");
            document.writeln("<table border = '1' width = 100 >");
            document.writeln("<tr><td><b>Name</b></td><td width = 50>" + books.Pascal[i].Name+"</td></tr>");
            document.writeln("<tr><td><b>Price</b></td><td width = 50>" + books.Pascal[i].price +"</td></tr>");
            document.writeln("</table>");
            document.writeln("</td>");
         }

         for(i = 0;i<books.Scala.length;i++){
            document.writeln("<td>");
            document.writeln("<table border = '1' width = 100 >");
            document.writeln("<tr><td><b>Name</b></td><td width = 50>" + books.Scala[i].Name+"</td></tr>");
            document.writeln("<tr><td><b>Price</b></td><td width = 50>" + books.Scala[i].price+"</td></tr>");
            document.writeln("</table>");
            document.writeln("</td>");
         }
			
         document.writeln("</tr></table>");

      </script>

   </head>
	
   <body>
   </body>
	
</html>

Previous 1 ... 4 5 6 7 8 9 10 ... 1926 Next
Advertisements
Loading...