Posts

JAVA :: Arrays

Arrays Arrays in Java are different than they are in other languages. Arrays in Java are actual objects that can be passed around and treated just like other objects. Arrays are a way to store a list of items. Each element of the array holds an individual item, and you can place items into and remove items from those slots as you need to. Arrays can contain any type of value (base types or objects), but you can’t store different types in a single array. You can have an array of integers, or an array of strings, or an array of arrays, but you can’t have an array that contains, for example, both strings and integers. To create an array in Java, you use three steps: 1. Declare a variable to hold the array. 2. Create a new array object and assign it to the array variable. 3. Store things in that array. Declaring Array Variables  The first step to creating an array is creating a variable that will hold the array, just as you would any other variable. Array variab...

What Is Java?

Image
What Is Java? A Beginner’s Guide to Java and Its Evolution   Java is a general-purpose, concurrent, object-oriented, class-based, and the runtime environment(JRE) which consists of JVM  which is the cornerstone of the Java platform. This blog on What is Java will clear all your doubts about why to learn java, features and how it works. In this What is Java blog, I would be covering following topics:        What is Java?    History of Java    What is Java used for?        Features of Java     Components in Java History of Java Java is a programming language developed by James Gosling with other team members named Mike Sheridan and  Patrick Naughton also called as Green Team in 1995 for Sun Microsystems for digital devices such as set-top boxes, televisions etc. Now, let us see in detail what is Java. What is Java? It is an object-oriented language ...

Java Interview Questions updated on May 2019

Java Interview Questions updated on May 2019 1.What is JVM? The Java interpreter along with the runtime environment required to run the Java application in called as Java virtual machine(JVM) 2. What do you mean by platform independence? Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc). 3. What is the difference between a JDK and a JVM? JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM. 4. What is the most important feature of Java? Java is a platform independent language. 5. What is the base class of all classes? java.lang.Object 6. What are the states associated in the thread? Thread contains ready, running, waiting and...

string-is-palindrome

string-is-palindrome Question: Implement a method that checks whether a string is a palindrome or not. problem is to break the String into a char array, then comparing the chars from two ends. This algorithm runs in O(n) time. Java public static boolean isPalindrome ( String input ) { // Break into a char array char [ ] charArray = input . toCharArray ( ) ; // Compare front and end character until meet at middle for ( int i = 0 , j = charArray . length - 1 ; i < charArray . length / 2 ; i ++ , j -- ) { if ( charArray [ i ] != charArray [ j ] ) return false ; } return true ; }