In this post we will learn how to add top and bottom border to view.In this example we will take as sample view and add borders to it.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “AddBorderTopAndBottom”Step 2 − Open Main.storyboard add a UIView to it as shown below.Step 3 − Add one @IBOutlet for the view, name it centerView.Step 4 − We will write separate method to add borders to this view. To add borders to this view we will create two layers with desired thickness. We will set the frame of ... Read More
In this post we will learn how to change the background color of view with animation.In this example we will change background color of view on click of a button. On clicking the button the background color will change to red, then on next click it would change to blue, on next click to red again.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “ChangeBGColor”Step 2 − Open Main.storyboard add a button as shown belowStep 3 − Add one @IBAction for touchUpInside of ‘Change Background’ button. Name the function as changeBackgroundClicked.Step 4 − ... Read More
Converting one data type to others in Java is known as casting.Up casting − If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).Example Live Demoimport java.util.Scanner; public class NarrowingExample { public static void main(String args[]){ char ch = (char) 67; System.out.println("Character value of the given integer: "+ch); } }OutputCharacter value of the given integer: CDown casting − If you convert a lower datatype to a higher data type, it is known as widening (assigning lower data type ... Read More
There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the text from the given PDF document to use this.Load an existing PDF document using the static method load() of the PDDocument class.Instantiate the PDFTextStripper class.Retrieve.read the contents of the PDF page to a String using the getText() method of the PDFTextStripper class.Finally, close the document using the close() method of ... Read More
The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More
The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample { public static void main(String[] args) { String str = new String("Hello how are you"); System.out.println("Contents of the String: "+str); } }OutputHello how are youStrings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the ... Read More
The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More
You can find whether a String contains a specified sequence of characters using any of the methods −The indexOf() method − The indexOf() method of the String class accepts a string value and finds the (starting) index of it in the current String and returns it. This method returns -1 if it doesn’t find the given string in the current one.The contains() method − The contains a () method of the String class accepts a sequence of characters value and verifies whether it exists in the current String. If found it returns true else it returns false.In addition to these, you ... Read More
The split() method of the String class accepts a String value representing the delimiter and splits into an array of tokens (words), treating the string between the occurrence of two delimiters as one token.For example, if you pass single space “ ” as a delimiter to this method and try to split a String. This method considers the word between two spaces as one token and returns an array of words (between spaces) in the current String.If the String does not contain the specified delimiter this method returns an array containing the whole string as an element.Example Live Demopublic class SplitExample ... Read More
No, while defining multiple classes in a single Java file you need to make sure that only one class among them is public. If you have more than one public classes a single file a compile-time error will be generated.ExampleIn the following example we have two classes Student and AccessData we are having both of them in the same class and declared both public. Live Demoimport java.util.Scanner; public class Student { private String name; private int age; Student(){ this.name = "Rama"; this.age = 29; } Student(String name, int age){ ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP