
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 9150 Articles for Object Oriented Programming

2K+ Views
To swap the contents of two strings (say s1 and s2) without the third.First of all concatenate the given two strings using the concatenation operator “+” and store in s1 (first string).s1 = s1+s2;The substring method of the String class is used to this method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or up to endIndex – 1, if the second argument is given.Now using the substring() method of the String class store the ... Read More

151 Views
This class is used Join a sequence of characters separating using the delimiter.Examplepublic class StringJoinerSample { public static void main(String[] args){ StringJoiner sj = new StringJoiner(", "); sj.add("Krishna"); sj.add("Raju"); sj.add("Satish"); sj.add("Pruthvi"); System.out.println(sj); } }OutputKrishna, Raju, Satish, Pruthvi

665 Views
The String class of the java.lang package represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings are constant, their values cannot be changed after they are created.The StringBuffer and StringBuilder classes are used when there is a necessity to make a lot of modifications to Strings of characters.Unlike Strings, objects of type StringBuffer and String builder can be modified over and over again without leaving behind a lot of new unused objects.The StringBuilder class was introduced as of Java 5 and the main difference between the StringBuffer and StringBuilder ... Read More

213 Views
The java.util.StringTokenizer class allows an application to break a string into tokens.This class is a legacy class that is retained for compatibility reasons although its use is discouraged in new code.Its methods do not distinguish among identifiers, numbers, and quoted strings.This class methods do not even recognize and skip comments.Example Live Demoimport java.util.*; public class StringTokenizerDemo { public static void main(String[] args) { // creating string tokenizer StringTokenizer st = new StringTokenizer("Tutorialspoint is the best site"); // counting tokens System.out.println("Total tokens : " + st.countTokens()); } }OutputTotal tokens : 5

167 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 of the given variables not values.The equals() method of the String class accepts a String as parameter and it compares the current string to the specified object. The result ... Read More

3K+ Views
Java Swing is a set of APIs that provides a graphical user interface (GUI) for the java programs. The Java Swing was developed based on earlier APIs called Abstract Windows Toolkit (AWT). The Java Swing provides richer and more sophisticated GUI components than AWT. The GUI components are ranging from a simple level to complex tree and table. The Java Swing provides the pluggable look and feels to allow look and feel of Java programs independent from the underlying platform.Features of Java SwingThe Java Swing is platform independent and follows the MVC (Model View and Controller) framework.Pluggable look and feel − The Java ... Read More

315 Views
We can define a property of an object using Dot and Bracket notations. There is also another way in which a property called Object.defineProperty() is used to define a property. It usually takes 3 parameters they are object name, property name, property descriptor.syntaxObject.defineProperty(object name, property name, property descriptor)Lets' define a property with this method.ExampleIn the following example, initially, the object has only one property named 'one'. Later on, another property named 'two' is added. Now when we tried to display all the properties, only the first property was displayed but not the added property as shown in the output.Live Demo ... Read More

121 Views
The java.lang.StringBuffer class is a thread-safe, mutable sequence of characters. Following are the important points about StringBuffer −A string buffer is like a String, but can be modified.It contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls.They are safe for use by multiple threads.Every string buffer has a capacity.Example Live Demoimport java.lang.*; public class StringBufferDemo { public static void main(String[] args) { StringBuffer buff = new StringBuffer("tutorials "); System.out.println("buffer = " + buff); // appends the string argument to ... Read More

146 Views
Java provides three shift operators namely −Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand.Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand.Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.Example Live Demopublic class Test { public static void main(String args[]) { int a = 60;/* 60 = 0011 1100 */ ... Read More

3K+ Views
The this is a keyword in Java which is used as a reference to the object of the current class, with in an instance method or a constructor. Using this you can refer the members of a class such as constructors, variables and methods.Using “this” you can −Differentiate the instance variables from local variables if they have same names, within a constructor or a method.class Student { int age; Student(int age) { this.age = age; } }Call one type of constructor (parametrized constructor or default) from other in a class. It is known as ... Read More