Skip to content

Instantly share code, notes, and snippets.

@RashidJorvee
RashidJorvee / TrimToSize.java
Last active January 5, 2019 15:19
How to use trimToSize() method in Java?
package rashid.jorvee;
public class TrimToSize {
public static void main(String[] args) {
StringBuffer copyText=new StringBuffer();
copyText.append("trim to size method in java");
System.out.println(copyText +", and length of StringBuffer copyText is:" +copyText.length());
System.out.println("Capacity of copyText is::"+copyText.capacity());
copyText.trimToSize();
@RashidJorvee
RashidJorvee / MethodWithNParameters.java
Last active January 5, 2019 15:18
Method which accept n number of parameters in Java
package rashid.jorvee;
import java.util.Map;
/*
* Method which accept n number of parameters.
*/
public class MethodWithNParameters {
public static void main(String[] args) {
String name="Rashid";
@RashidJorvee
RashidJorvee / ReturnMultipleValueFromMethod.java
Last active January 5, 2019 15:30
Return list of objects from a method in Java
package rashid.jorvee;
import java.util.Arrays;
import java.util.List;
public class ReturnMultipleValueFromMethod {
public static void main(String[] args) {
List<Object> list=getQuestionAndViewType("M", "Survey");
System.out.println(list);
@RashidJorvee
RashidJorvee / GenerateRandomNumber.java
Created January 5, 2019 17:02
How to generate and get a random number in Java?
package rashid.jorvee;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Collections;
public class GenerateRandomNumber {
public static void main(String[] args) {
ArrayList<Integer> list = new ArrayList<Integer>();
@RashidJorvee
RashidJorvee / ComponentContext.java
Last active January 6, 2019 16:32
How to read configuration from Apache Felix console?
@Activate
protected void activate(final ComponentContext componentContext) throws Exception {
final Map<String, String> properties = (Map<String, String>) componentContext.getProperties();
if (properties != null) {
String uName = PropertiesUtil.toString(properties.get("userName"), "");
int age = PropertiesUtil.toInteger(properties.get("age"), "");
String[] hobbies = PropertiesUtil.toStringArray(properties.get("hobbies"), "");
}
}
@RashidJorvee
RashidJorvee / GenerateThreeDigitsRandomNumber.java
Created January 7, 2019 04:34
How to generate three digits random number in java
package rashid.jorvee;
import java.lang.Math;
import java.util.ArrayList;
import java.util.Collections;
public class GenerateThreeDigitsRandomNumber {
public static void main(String[] args) {
int random = (int )(Math.random()* 900 + 000);
@RashidJorvee
RashidJorvee / FizzBuzzProgram.java
Created January 7, 2019 04:45
Write a function that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.
package rashidjorvee;
public class FizzBuzzProgram {
public static void main(String[] args) {
for(int i=1; i<=100; i++){
if(i%3 == 0){
System.out.println("Fizz");
}
else if (i%5 == 0){
Get all the pages which have property
SELECT * from [cq:Page] AS t
where ISDESCENDANTNODE('/content') and
contains(t.*, 'componentName or URL')
SELECT * FROM [cq:Page] AS parent
INNER JOIN [nt:base] AS child ON ISDESCENDANTNODE(child, parent)
WHERE ISDESCENDANTNODE(parent, '/content/') AND child.[jcr:title]='config'
@RashidJorvee
RashidJorvee / executeAProcedure
Last active June 12, 2019 07:12
Create a simple procedure in Oracle
BEGIN
procedureName;
END;
function third(val, callback){
callback(val*2, false);
}
function second(val, callback){
callback(val*2, false);
}
function first(val, callback){
callback(val*2, false);
}