on Leave a Comment

Introduction to Javascript

Javascript is a client side scripting language. It is a primary used language on the web. It is lightweight and interpreted language. Javascript has ability to change HTML content. Today all modern web browsers support javascript. 

Javascript is developed by Netscape Communication at 1995. Javascript was first known as liveScript and then it changed to Javascript, may be because of popularity of Java. 

Advantage of Javascript

It is client side scripting language. Javascript code runs by the user processer and thus it saves bandwidth interaction with server.

Javascript is easy to learn and it’s much look like English language. 

Javascript has plenty of predefined function, variable thus provides greater functionality to the user.

Using javascript you can create interactive web pages that catches attraction of site visitor.

It is fast because it runs on user system and its need not be process on web server.

Limitations of Javascript

Javascript code can be used by hackers to infect user's system, so it is security issue. Modern web browsers set some restriction but still, it’s not fully secure.

Using javascript, you can't work with files on server because it is a client side scripting language.

Javascript doesn't support multithreading.

Javscript depends on browser, so it is interpreted differently on different browsers.

All browsers has option to disable javascript, so user can disable javascript. 



on Leave a Comment

Java Program to Find Duplicate Characters in a String

This java program finds duplicate characters in a string. In this program, we assign a string to a variable named "str" and this string is converted to character array using toCharArray() method and assigned to a variable "c". Then using nested for loop, we compare each character of char array to the other characters in array and if they match, we print that character.

Java Program to Find Duplicate Characters in a String

class FindDuplicateString{
 public static void main(String[] args){
  String str = "java";
  char[] c = str.toCharArray();
  System.out.print("Duplicate characters : ");
  for(int i=0; i<str.length(); i++){
   for(int j=i+1; j<str.length(); j++){
    if(c[i] == c[j]){
              System.out.print(c[i]+" ");         }
   }   
  }
 }
}

Output:

Duplicate characters : a



on Leave a Comment

Java Program to Convert String to Int

In java, we can convert string to integer using static methods like parseInt() and valueOf(). 

Java String to Int Using Integer.parseInt()

parseInt() is a static method of Integer class, this method returns a primitive int.

class StringToInt{
 public static void main(String[] args){
  String str="100";
  
  //String to Int using parseInt method
  int a = Integer.parseInt(str);
  System.out.println("Sum is "+(a+10));
 }
}

Output:

Sum is 110

Java String to Int Using Integer.valueOf()

valueOf() method returns a Integer object.

class StringToInt{
 public static void main(String[] args){
  String str="100";
  
  //String to Int using parseInt method
  Integer a = Integer.valueOf(str);
  System.out.println("Sum is "+(a+10));
 }
}

Output:

Sum is 110