- 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 402 Articles for Java8
542 Views
Lambda expressions In Java allows you to pass functionality as an argument to a method. You can also call an existing method using lambda expressions.list.forEach(n -> System.out.println(n));Method references are simple, easy-to-read lambda expressions to call/refer and the existing method by name in a lambda expression. In addition to the instance and static methods, you can also refer a constructor by using the new keyword.SyntaxFollowing is the syntax to reference a constructor in Java.ClassName::newExampleinterface myInterface{ Test greet(String data); } class Test{ Test(String data){ System.out.println(data); } } public class MethodReferences { public static void ... Read More
137 Views
This method retrieves the list of all the SQL keywords of the underlying database and returns in the form of a String variable which holds all the keywords separated by commas.To get the list of keywords in the database −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. Pass the URL the database and, user name, password of a user in the database, as String variables.Get the DatabaseMetaData ... Read More
261 Views
Actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin.There is only one syntax for the Action element, as it conforms to the XML standard −Action elements are basically predefined functions. The following table lists out the available JSP actions −S.No.Syntax & Purpose1jsp:includeIncludes a file at the time the page is requested.2jsp:useBeanFinds or instantiates a JavaBean.3jsp:setPropertySets the property of a JavaBean.4jsp:getPropertyInserts the property of a JavaBean into the output.5jsp:forwardForwards the requester to a new ... Read More
164 Views
The getValueX() method is used to get a value from Pair Tuple class in Java at a particular index. For example, getValue0().Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; public class Demo { ... Read More
516 Views
Tuples in Java are an ordered collection of objects of different types. To run Tuple in Java, you need to upload an external jar file. Here, we will be using Eclipse IDE to create a new Java Project and upload the JavaTuples external jar file.The JavaTuples jar file is to be downloaded. Let us first download the jar file, create an Eclipse project and import the downloaded jar file. Here are the steps −Step 1 − Download JavaTuples Jar library and save it on your system.Open the GitHib link and download the “javatuples-1.2-dist.zip” as shown below −After downloading, unzip and ... Read More
3K+ Views
There are five main memory areas which are used to various Java elements. Following is the list of the same. Class Area - This area contains the static members of the class. Method Area - This area contains the method definition and executable code. Heap Area - This area contains the objects which are dynamically allocated/deallocated. if an object is no more referenced by any live reference it is deallocated. Stack Area - This area contains the local variables. Pool Area - Contains immutable objects like string.
5K+ Views
The volatile modifier is used to let the JVM know that a thread accessing the variable must always merge its own private copy of the variable with the master copy in the memory.Accessing a volatile variable synchronizes all the cached copied of the variables in the main memory. Volatile can only be applied to instance variables, which are of type object or private. A volatile object reference can be null.Examplepublic class MyRunnable implements Runnable { private volatile boolean active; public void run() { active = true; while (active) { } } public void stop() { active = false; } }
475 Views
Public Access Modifier - PublicA class, method, constructor, interface, etc. declared public can be accessed from any other class. Therefore, fields, methods, blocks declared inside a public class can be accessed from any class belonging to the Java Universe.However, if the public class we are trying to access is in a different package, then the public class still needs to be imported. Because of class inheritance, all public methods and variables of a class are inherited by its subclasses.ExampleThe following function uses public access control −public static void main(String[] arguments) { // ... }The main() method of an application ... Read More
300 Views
Protected Access Modifier - ProtectedVariables, methods, and constructors, which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class.The protected access modifier cannot be applied to class and interfaces. Methods, fields can be declared protected, however methods and fields in a interface cannot be declared protected.Protected access gives the subclass a chance to use the helper method or variable, while preventing a nonrelated class from trying to use it.ExampleThe following parent class uses protected access control, to allow its child class override openSpeaker() ... Read More
3K+ Views
A string is Palindrome if position of each character remain same in case even string is reversed.For example 'MADAM' is a palidrome string as position of each character remain same even if string 'MADAM' is reversed.Now in order to identify a string as palindrome or not we can use library method approach and also without library method approach.But if we want to check if "Madam" is palindrome or not , it will show us that it is not a palindrome because of the upper case of first letter.Example - Without library method. Live Demopublic class Palindrome { public static void ... Read More