Wednesday, 4 December 2013

Unknown

Palindrome Number


/*
 This program shows how to check for in the given list of numbers
 whether each number is palindrome or not
 */

public class JavaPalindromeNumberExample {

    public static void main(String[] args) {
//array of numbers to be checked
        int numbers[] = new int[]{121, 13, 34, 11, 22, 54};
//iterate through the numbers
        for (int i = 0; i < numbers.length; i++) {
            int number = numbers[i];
            int reversedNumber = 0;
            int temp = 0;
            /*
             * If the number is equal to it's reversed number, then
             * the given number is a palindrome number.
             *
             * For ex,121 is a palindrome number while 12 is not.
             */
//reverse the number
            while (number > 0) {
                temp = number % 10;
                number = number / 10;
                reversedNumber = reversedNumber * 10 + temp;
                
            }
            if (numbers[i] == reversedNumber) {
                System.out.println(numbers[i] + " is a palindrome");
            } else {
                System.out.println(numbers[i] + " not a palindrome ");
            }
        }
    }
}
/*
Output of Java Palindrome Number Example would be
121 is a palindrome number
13 is not a palindrome number
34 is not a palindrome number
11 is a palindrome number
22 is a palindrome number
54 is not a palindrome number
*/
Read More
Unknown

Fibonacci Series


/* Fibonacci Series Java Example
 This Fibonacci Series Java Example shows how to create and print
 Fibonacci Series using Java.
 */

public class JavaFibonacciSeriesExample {

    public static void main(String[] args) {
//number of elements to generate in a series
        int limit = 20;
        long[] series = new long[limit];
//create first 2 series elements
        
        series[0] = 0;
        series[1] = 1;
//create the Fibonacci series and store it in an array
        for (int i = 2; i < limit; i++) {
            series[i] = series[i - 1] + series[i - 2];
        }
//print the Fibonacci series numbers
        System.out.println("Fibonacci Series upto " + limit);
        for (int i = 0; i < limit; i++) {
            System.out.print(series[i] + " ");
        }
    }
}
/*
Output of the Fibonacci Series Java Example would be
Fibonacci Series upto 20
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
*/
Read More
Unknown

Determine If Year Is Leap Year


/*
Determine If Year Is Leap Year Java Example
This Determine If Year Is Leap Year Java Example shows how to
determine whether the given year is leap year or not.
*/
public class DetermineLeapYearExample {
    public static void main(String[] args) {

        //year we want to check
        int year = 2004;
        //if year is divisible by 4, it is a leap year
        if(year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))
            System.out.println("Year " + year + " is a leap year");
        else
            System.out.println("Year " + year + " is not a leap year");
    }
}
/*
Output of the example would be
Year 2004 is a leap year
*/
Read More
Unknown

Compare Two Numbers using else-if


/*
 Compare Two Numbers Java Example
 This Compare Two Numbers Java Example shows how to compare two numbers
 using if else if statements.
 */

public class CompareTwoNumbers {

    public static void main(String[] args) {
//declare two numbers to compare
        int num1 = 324;
        int num2 = 234;
        if (num1 > num2) {
            System.out.println(num1 + " is greater than " + num2);
        } else if (num1 < num2) {

            System.out.println(num1 + " is less than " + num2);
        } else {
            System.out.println(num1 + " is equal to " + num2);
        }
    }
}
/*
Output of Compare Two Numbers Java Example would be
324 is greater than 234
*/
Read More
Unknown

Factorial of a number


/*
 This program shows how to calculate
 Factorial of a number.
 */

public class NumberFactorial {

    public static void main(String[] args) {
        int number = 5;
        /*
         * Factorial of any number is! n.
         * For example, factorial of 4 is 4*3*2*1.
         */
        int factorial = number;
        for (int i = (number - 1); i > 1; i--) {
            4

        }
        {
            factorial = factorial * i;
        }
        System.out.println("Factorial of a number is " + factorial);
    }
}
/*
Output of the Factorial program would be
Factorial of a number is 120
*/
Read More
Unknown

To Display the List of even numbers


public class ListEvenNumbers {

        public static void main(String[] args) {
               
                //define limit
                int limit = 50;
               
                System.out.println("Printing Even numbers between 1 and " + limit);
               
                for(int i=1; i <= limit; i++){
                       
                        // if the number is divisible by 2 then it is even
                        if( i % 2 == 0){
                                System.out.print(i + " ");
                        }
                }
        }
}

/*
Output of List Even Numbers Java Example would be
Printing Even numbers between 1 and 50
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50
*/
Read More

Tuesday, 3 December 2013

Unknown

How To Open Notepad Using Java Code

import java.util.*;
import java.io.*;
class Notepad {
public static void main(String[] args) {
Runtime rs = Runtime.getRuntime();
try {
rs.exec("notepad");
}
catch (IOException e) {
System.out.println(e);
}
}
}
Explanation:
getRunTime method is used to get reference of current RunTime object, exec method can be used to execute commands. You can also specify a file while opening notepad such as exec("notepad programming.txt") where xist in current working directory then a dialog box will be displaye'programming.txt' is the file you wish to open, if the file doesn't ed to create file. You can launch other applications using exec method, for is present in a directory which is not set in environment varia example exec("calc") will launch calculator application. If an application ble PATH then you can specify complete path of application. If you are still using Notepad for Java development it is recommended to switch
to some advanced text editor like Notepad++ or use a development IDE.
Read More
Unknown

Programming Jokes On RajiniKanth

    Rajnikanth can override a final function/variable.
  • Rajinikanth is the super class of all classes in Java (including Object class).
  • Rajnikanth can serialize static data members of any class.
  • Rajnikanth can serialize transient variables.
  • Rajnikanth can extend interfaces in classes.
  • Rajnikanth can “force” garbage collector to run..and guess what .. GC runs as higher priority thread n starts collecting garbage.
  • Rajnikanth can make a class abstract and final both at same time.
  • Rajnikanth never gets stackOverFlowexception.
  • Rajnikanth never faces any exception (Rather, Java can face RajnikanthException for any exception conditions) (Improved from earlier).
  • Rajnikanth never “try” any code, he directly “catch” the exceptions.
  • Rajnikanth can divide by zero. – (older one)
  • Rajnikanth can run Java byte code on “any” machine (Including but not limited to Java Virtual Machine).
  •  Rajnikanth Can use Pointers in JAVA
  • Rajnikanth access all PRIVATE data of any class
  • Rajnikanth use Operator Overloading in Java
  • Rajnikanth pass losts of Parameter using “Pass By Reference”
  • Rajnikanth is only person who use printf() in java
  • Rajnikanth can Declare function body in INTERFACE.
  • Rajnikanth can do MULTIPLE inheritance in JAVA straightfoward.
  • Rajnikanth Run Thread Program without Thread LIFECYCLE
  • In catch box if u write catch(Rajnikant e) it will catch all exceptions including EXCEPTION E
Read More
Unknown

Roles Of JRE

JRE
  • Java Runtime Environment (JRE) The Java Runtime Environment (JRE) provides the libraries, the Java Virtual Machine, and other components to run applets and applications written in the Java programming language. In addition, two key deployment technologies are part of the JRE: Java Plug-in, which enables applets to run in popular browsers; and Java Web Start, which deploys standalone applications over a network. It is also the foundation for the technologies in the Java 2 Platform, Enterprise Edition (J2EE) for enterprise software development and deployment. The JRE does not contain tools and utilities such as compilers or debuggers for developing applets and applications.
  • Java Runtime Environment contains JVM, class libraries, and other supporting files. It does not contain any development tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the class libraries, and other supporting files provided in JRE. If you want to run any java program, you need to have JRE installed in the system
  • It's needed to run Java programs. You can't compile Java programs with it .For example: a regular computer user who wants to run some online games then will need JRE in his system to run Java programs.
  • JRE: is the execution environment for a java application.ie, it only support runtime dependencies including jvm for compiled program. If we want to compile a java program we need jdk. 



Read More
Unknown

Task or Functionality or Job Of JVM

JVM
  • It is a virtual machine that can execute Java bytecode. It is the code execution component of the Java software platform.
  • The Java Virtual machine (JVM) is the virtual machine that run the Java bytecodes. The JVM doesn't understand Java typo, that's why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM. It's also the entity that allows Java to be a "portable language" (write once, run anywhere). Indeed there are specific implementations of the JVM for different systems (Windows, Linux, MacOS,), the aim is that with the same bytecodes they all give the same results.
  • As we all aware when we compile a Java file, output is not an ‘exe’ but it’s a ‘.class’ file. ‘.class’ file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code depending upon the underlying operating system and hardware combination. It is responsible for all the things like garbage collection, array bounds checking, etc… JVM is platform dependent.
  • The JVM is called “virtual” because it provides a machine interface that does not depend on the underlying operating system and machine hardware architecture. This independence from hardware and operating system is a cornerstone of the write-once run-anywhere value of Java programs.
  • There are different JVM implementations are there. These may differ in things like performance, reliability, speed, etc. These implementations will differ in those areas where Java specification doesn’t mention how to implement the features, like how the garbage collection process works is JVM dependent, Java spec doesn’t define any specific way to do this.
  • this actually means the byte code interpreter .It is platform dependent. For eg: in Windows platform the 'java.exe' or 'javaw.exe' precess is the jvm process.
Read More