- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9321 Articles for Object Oriented Programming
144 Views
A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Example Live Demopublic class Test { public static void main(String args[]) { // char grade = args[0].charAt(0); char grade = 'C'; switch(grade) { case 'A' : System.out.println("Excellent!"); break; case 'B' : case 'C' : ... Read More
82 Views
We can compare Strings in Java using the compareTo() method and the == operator.comapareTo() method: The compareTo() method compares two strings lexicographically. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string.The == operator: You can compare two strings using == operator. But, it compares references to the given variables, not values.Example Live Demoimport java.lang.*; public class StringDemo { public static void main(String[] args) { String str1 = "tutorials", str2 = "point"; ... Read More
87 Views
You can compare two strings using == operator. But, it compares references of the given variables, not values.ExampleLive Demopublic class Sample { public static void main(String args[]){ String str1 = "hello"; String str2 = "hello"; System.out.println(str1 == str2); } }Outputtrue
3K+ Views
The append(char c) method of the java.lang.StringBuffer appends the string representation of the char argument to this sequence. The argument is appended to the contents of this sequence. The length of this sequence increases by 1.Example Live Demoimport java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tuts "); System.out.println("buffer = " + buff); // appends the char argument as string to the string buffer. buff.append('A'); // print the string buffer after appending ... Read More
92 Views
The equals() method of the String class compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.Example Live Demopublic class Test { public static void main(String args[]) { Integer x = 5; Integer y = 10; Integer z =5; Short a = 5; System.out.println(x.equals(y)); System.out.println(x.equals(z)); System.out.println(x.equals(a)); } }Outputfalse true false
126 Views
You can compare Strings using compareTo() method or, equals() method or, or == operator. Following example demonstrates how to initialize and compare strings in Java. Example Live Demo public class StringDemo { public static void main(String[] args) { String str1 = "tutorials"; String str2 = "point"; // comparing str1 and str2 int retval = str1.compareTo(str2); // prints the return value of the comparison if (retval < 0) { System.out.println("str1 is greater than str2"); } else if (retval == 0) { System.out.println("str1 is equal to str2"); } else { System.out.println("str1 is less than str2"); } } } Output str1 is less than str2
1K+ Views
The append() method in the StringBuffer class adds the specified String to the contents of the current String buffer. Using this method you can append a single character to a string or char array in java.Examplepublic class Test { public static void main(String args[]) { StringBuffer sb = new StringBuffer("Hi hello how are yo"); sb.append("u"); System.out.println(sb); } }OutputHi hello how are you
332 Views
Java memory pool is divided into 5 parts namely −Method area − The method area stores the class code − code of the variables and methods.Heap−The Java objects are created in this area.Java Stack− While running methods the results are stored in the stack memory.PC registers− These contain the address of the instructions of the methods.Native method stacks− Similar to Java stack, native methods are executed on the Native method stacks.
3K+ Views
Java Virtual Machine is a program/software which takes Java bytecode (.class files)and converts the byte code (line by line) into machine understandable code.JVM contains a module known as a class loader. A class loader in JVM loads, links and, initializes a program. It−Loads the class into the memory. Verifies the byte code instructions.Allocates memory for the program.The memory in the JVM is divided into five different parts namely− Method area− The method area stores the class code − code of the variables and methods. Heap − The Java objects are created in this area. Java Stack− While running methods the results are stored in ... Read More
160 Views
Following is an example which compares Strings and portion of strings in Java? Explain with an example.ExampleLive Demopublic class StringDemo { public static void main(String[] args) { String str1 = "tutorials point"; String str2 = str1.substring(10); int result = str1.compareTo(str2); // prints the return value of the comparison if (result < 0) { System.out.println("str1 is greater than str2"); } else if (result == 0) { System.out.println("str1 is equal to str2"); } else { System.out.println("str1 is less than str2"); } } }Outputstr1 is less than str2