Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Email Address from given string java

Hello everyone, Can anyone help me with the below query- I want a code packet in java to check if a given string has an email address if yes then return the email address or return empty string.  

Why are annotations used in Java?

I have certain queries regarding annotations in Java. What is the usage of annotations in java? What are the major applications where we can use it? Can these be used to replace XML based configuration completely and is it language specific...

Convert bytes to human readable form Android Java

Convert bytes data to human readable form. 1.  I initialized the byte with random number; long bytes = 123456; 2.  Initialize String[] of data types. String[] types = {"kb", "Mb", "GB", "TB", "PB", "EB"}; 3. initial...

Default methods and static methods uses in Interface.

We know that interface provide methods without body or functionality but in abstract class we can provide default functionality of methods. So in interface we can't give method body and can't declare ant static method. But in Java 8 no...

RMI Registery java.rmi.connectexception connection refused to host

Below is my code:   import java.rmi.*; import java.rmi.server.*; import java.net.*; import java.io.*; import javax.swing.*; import java.awt.event.*; import java.lang.*; import java.awt.*; import javax.swing.filechooser.FileSyst...

Solve null pointer exception

Here is my Code: import java.sql.*; public class dbcon { Connection con; Statement st; ResultSet rs; dbcon() { try { Class.forName("net.ucanaccess.jdbc.UcanaccessDriver"); Connection con = DriverManager.getConnection(...

count pixels under each finger in multi touch in android

Hello I need to count pixels that are covered by each fingers in multi-touch.When fingers down one by one it should plus pixels in count and finger up it should subtract pixels of that finger.I have did this but it is not getting exact counts i d...

How to delete rows from a JTable using swingworker?

Am trying to create an application that sends messages(SMS) to a list of people in the JTable and each time a message is sent to the recipient who is a row in the JTable i want that row to be deleted and i want the sending of the message to be do...

Comparator Interface in Java

Comparator:- Comparator interface  found in java.util package and it contains equals() and compare() method. It use the multiple sorting technique to write our own comparison logic and is used to sort the e...

Desktop application like word web (http://wordweb.info/free/)

I need to make a Desktop Application with following features : Once installed, it gets launched at the time user logs in and runs in the background. If the user selects some text from browser or from notepad and clicks a particular key combinat...

Comparable Interface in Java

Comparable:- Comparable interface  found in java.lang package and it contains only compareTo() method. It use the single sorting technique to write our own comparison logic and is used to sort the elements on the basis of...

How to prevent and USSD code from running in android?

I want to see how can I prevent a specific USSD code from running in android java? for example if the user dials *1234# an error pops or just make it not working. I want to create an application that prevents dangerous USSD codes from runni...

Autofill functionality for website forms

I have a website whose source code cannot be changed.It has several forms which has repetitive fields so for reducing manual filing of repetitive fields i want autofill functionality.I will have another website from where data will be stored and ...

Facebook OAuth Authentication using Java

Hi, This blog is to help you to get Facebook Authentication through OAuth using Java. As Facebook is not offering any SDK for Java clients so with the use of a Json parser we are going to develop a small web application in order to u...

Sorting singly linked list which takes only one argument

I want to write a recursive method which sorts the singly linked list and takes only one argument. And do not write another auxiliary method to support this recursive method.

ThreadGroup Class

ThreadGroup in Java: It represents combination of threads within a group. A thread group can also include other thread groups .With the help of thread group we can easily suspend, resume or interrupt group of threads by a single method call. ...

Synchronized block

Synchronized block: Synchronized block is mainly used when there is a sharing of resources and it is used to lock an object for any shared resource so that at a particular time only one object can use that resource. By using synchronized block...

Main Thread in java

Main Thread: When we run a Java program  then main thread begins running immediately. It is created automatically. The main thread is the first as well as last thread in a java program to end. It is the main thread from which other chi...

HashSet Class

HashSet Class: It extends AbstractList class and implements List interface. It uses hashing technique to store data. It contains only unique elements. We can use HashSet class by importing java.util package. Example: import java.util.*...

LinkedList class

LinkedList class: It provides a linked-list data structure. It uses doubly linked-list to store elements. It extends the AbstractList class and implements List  interface. We can use LinkedList class by importing java.util package. Exa...

Convert object to xml

i want to make a program that will create automatically XML data structures. I will not know from the beginning which is the class, and which the attributes so i cant use JAXB. For example, if the input is: Employee, name,id Employeelist, co...

find the longest sub-arraythat all of its elements are less or equalA[i]

I have an array A[1,...,n] of positive numbers, for example: [1, 2, 5, 3, 7, 2, 8, 4] I need to build an array S[1,...,n] according to the definition: S[i] = max {k|ik <ji :A[j] A[i] and k i} It means ...

NOT LIKE in Hibernate Criteria

The Hibernate Criteria Not like, selects the records that don't match to the matching string given in like parameter. Example: Criteria criteria=session.createCriteria(Tickit.class); //Here you can pass class on which you want to perf...

Formatting date in different format in java

Formatting Date in java: There is a predefined format for dealing with dates in java , but suppose if you want the date in some other format other than the default one then you can use the SimpleDateFormat class of the java.text ...

Getting object values from json data

Getting object values from Json: If you have a data in Json format and you need to retrieve the object values from that day, it can be easily done using Java.   Lets see an example,  If you are using maven add the following ...

Pass Element ID that Triggers `onclick` Event to the Event Handling Function

When we apply onclick event to an element, sometimes we need to pass ID of that element to the event handling function. We can do this by passing id to function as this.id or we can pass the element itself. Example: In the below example I&...

Getting current url in jQuery

Sometimes we need to identify which is the current URL of JSP page to perform some functionality. We can do this very easily by adding the below line in you on load function:   $(function(){ var url = window.location.href; ...

Creating object in Json format using java

Json object: You easily write your object in json format with java . Json format is used because it becomes easy to exchange information in this form. It is easy to understand and easy to write. Lets see an example,  If yo...

Static and Dynamic binding in java

Static Binding: It determines the the type of object at early stage during the compilation itself, i.e. it tells that the object belongs to which class during the compile time of the program.  There is no ambiguity in deciding the type...

Printing current Date in Java

Date Class in java: There is a Date class in java under java.util package which can be used to print the current dates. There can be various ways to print the current date. Lets see with the help of example: import java.util.Date; ...

Convert Xml to Json format using java

Xml to Json conversion: Lets see with the help of example. Following jars are required for conversion: apache-commmons json-lib ezmorph Suppose we have the xml file with name demo.xml with the following data: ...

Setting limit for the no. of words per record in solr while fetching

Fetching records in solr: Once you have finished with indexing in solr, now you can perform search on your records with the help of queries. Go to the url: http://localhost:8983/solr/#/collection/query  There is box with q,&...

Instance Initializer block in java

Instance Initializer Block: There are two types of data members: static and instance data members.  Instance data members are those that belongs to instance of a class. i.e objects. Here comes the role of instance initializer block. It...

How to use Custom Exception in android

Custom Exception is user-defined exception. It is used to customize the exception according to the user requirement. Here In step one we have defined own exception . In step second Using the custome defined exception extends "Exception"...

Is it possible to run program without main method?

Can we execute a program without using main? Answer is yes, we can run a program without using main with the help of static block. Lets see about static block first. Static Block: It is block which can be used to give initial values to t...

Export from a list containing objects to excel file in java

Suppose you have a list containing objects. You can export it to the excel file.  You will require the following jars for this: xmlbeans-2.3.0.jar poi-3.9-20121203.jar poi-ooxml-3.9-20121203.jar poi-ooxml-schemas-3.9-20121203....

Deleting documents in solr collection

Deleting documents: Suppose, you have collection with the name of demo and you have indexed your file in the server in this collection but you want to delete all the documents or some of them, then it is possible by two ways: Deletion by So...

Indexing in Solr Server

Indexing: Solr gives you a quick response and results because of indexing. What does this mean? It means that it searches index instead of the text to retrieve the results for you. In book , you search for the index in the index page of the...

Program to print pascal's triangle using a 2D array in java

Pascal's Triangle:   Program to print Pascal's triangle: import java.io.*; public class Pascal{ public static void main(String []args)throws IOException{ InputStreamReader isr=new InputStreamReader(S...

Solr update using solrTemplate for incremental value

In previous blog Solr Atomic update with incremental popularity, we have updated the solr incremental field using SolrDocument.    Now we will update it through solrTemplate. Here is the sample code: PartialUpdate update =...

How to disable mongoDB java driver logging

Go to mongodb configuration file and add following lines of code. @Configuration public class SpringMongoConfig extends AbstractMongoConfiguration{ static Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); sta...

Fetching String of specified length in solr

For fetching a string for a specific value and length, here are 2 ways to do that. First using @Query and another using solr Criteria. In the below code it first searches for the string match and then suing filters we have defined the length o...

Adding multipli core in spring with custom solr repository

Repository take solrtemplate to execute solr operations. Since we have multiple cores so we need to create multiple template and multiple repositories for each core. Following example explains it with 2 solr core Repository and custom imp...

How to make AJAX call in jQuery?

Sometimes we need to make AJAX call in our Web page. The purpose of AJAX call is that you want to get/submit data without refreshing your page or you want to submit your form by calling an API. We can do this very easily by using ajax() method of...

Statement interface

Statement interface: It provides methods to interact with database means using Statement interface we can execute SQL queries.The createStatement() is present in java.sql.Connection interface and it does not take any argument. To use Statem...

Solr Atomic update with incremental popularity

In solr we can create a field which can update as the related doc is searched by user. For that we need to add a field in schema.xml as: <field name="popularity" type="long" indexed="true" stored="true"/> In the below code we hav...

How to generate unique number for an email in JAVA?

Sometimes we need to generate a unique number for an emailId, for example when a user register then we need to generate a number by using that user can verify his EmailId. For this we can use SHA1 encoding method. Example - In the below method...

How to encode string using MD5 in Java?

Generally we need to encode the password in our Applications for security purpose and we can use MD5 for this purpose. Example - In the below method I'm encoding sting by using MD5 import java.security.MessageDigest; import java.secu...

How to sort ArrayList in Java?

Sometimes we want to sort a List based on some property. Suppose we have a List of UserModel and we want to sort List by firstName then we can do that easily by using Collections.sort() and Comparator interface. Example: In the below example I...

How to get year from a date in Java?

To get only year from a date you can use the below code. You can pass any date that you wan to change, I'm getting year from the date in the below example:    /** * Get year from Date * * @param createDate *...
1 3 8
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: