Create a new extension in Hybris

To create an extension we will use ant extgen command and yempty template .

1. Go to platform directory .
2. Run setantenv.bat commad.
3. Run ant extgen
4. Extgen prompts you to enter extension name . Enter extension name and press Enter.
5. Enter package name as desired .
6. New Extension will be created in custom folder in your hybris /bin directory.

7. Add Extension name to localExtensions.xml.

8. Run ant clean all.

Difference between ant all and ant clean all in hybris

ant clean all
ant all
 Delete all model classes create again.
Does not delete model classes but create new ones if required.
It checks whether config,log,data,temp etc folders are available inside hybris folder.
If this folder structure is not available then it creates the folder structure
It assumes folder structure is already exist
 If there is no build, It will create a build from scratch, if there is any build exist, It will delete and recreate it
If there is no build, it will create a build from scratch, if there is any build exist, it will modify it rather than recreating it.
Slower than ant all as it delete classes and folders and regenerate them.
Faster than ant clean all
Is advised to use only when there are changes in items.xml file
Is advised to use for every build.

How to run multiple hybris instance in one machine?

So many times you need you run more than 1 server of hybris on same machine , like if you want to run your customized code and OOTB Hybris Store as well . You just need to add the following properties in local.properties File.


Then do ant all and start the hybris server :

tomcat.http.port=7001
tomcat.ssl.port=7002
tomcat.ajp.port=7009
tomcat.jmx.port=7003
tomcat.jmx.server.port=7004

solrserver.instances.default.port=8986

tomcat.debugjavaoptions=-XXaltjvm=dcevm -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=6001,suspend=n


This will help you to run hybris server in debug mode as well on port 6001





How can you add values to a collection type attribute and Map from Impex in Hybris ?

1. For Collection type attribute you can use comma separated values which are to be inserted.

eg. INSERT_UPDATE UserGroup;uid[unique=true];groups(uid)[mode=append];readableLanguages(isocode);writeableLanguages(isocode);
;base-electronics-cmsmanagergroup;basecmsmanagergroup;ja,en,de,zh;ja,en,de,zh



Here , both readableLanguages and writeableLanguages are of type LanguageCollection .

2. Also you can use mode=append in header for Collection Type attribute .



3. For Map type attribute by default you have to use -> delimiter within key and value pair .

INSERT_UPDATE myProduct;myAttribute
;myKey->myValue

How to make cronjob run on some servers(in case of load balancer or cluster ) and but not on others?

This scenario can be achieved using Nodes concept in hybris.

1. First you need to define applicable nodes in local.properties using cluster.node.groups property such as


cluster.node.groups = backoffice,storefront .


2. Assign the cronjob to group of nodes by 2 ways :

 a) When you define the cronjob then use method .setNodeGroup("nameofnodegroup") like .setNodeGroup("storefront ").

b) Using Impex :


INSERT_UPDATE CronJob; code[unique=true];job(code);nodeGroup
;myCronJob;myJob;storefront


Whenever next time the cronjob is going to it will trigger on the nodeGroup defined .

Model service create method vs new operator - Hybris Interview question



ModelService is a Service provided by Hybris Out of the Box . It has many predefined methods such as create() , save () ,saveAll() .




When we try to create a new instances of an item type programmatically, there are two ways




1 . Using the Traditional new operator

2. or the hybris way, using the ModelService.create()




For Example

ProductModel product1 = new ProductModel();

ProductModel product2 = modelService.create(ProductModel.class);

The advantages of using model service method are below:
The model service create method will generate and assign the pk for product object.
The create method will initialize the default values, defined in items.xml for mandatory attributes.
While calling save all method, the object is already attached to context, and will be saved. While product1 needs to attach explicitly.

Play Video File Android Example

Now, Moving forward in Android Examples ,Today you are going to learn a new Android Example of Play Video File Android Example with code . If you are a beginner Please go through the tutorial from very start from here .Play Video File in Android is very simple and easy to code .You can also incorporate  Play Video File Android Example in your project or app. For Play Video File Android Example ,we used Android Studio you can use any other Android IDE as well.

Play Video File Android Example
Play Video File Android Example






Steps of Play Video File Android Example are  explained below :




Step 1 : Create a new Project -PlayVideo and Activity 

Play Video File Android Example
Play Video File Android Example

Step 2 : Create Activity xml 
You 
Add a button and Video View in activity xml file for Play Video File Android Example with code.


<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
         android:orientation="vertical"    
         android:layout_width="fill_parent"   
         android:layout_height="fill_parent"    >

    <Button android:id="@+id/button"
        android:layout_width="fill_parent"     
        android:layout_height="wrap_content"   
        android:text="PLAY Video"        />


    <VideoView 
          android:id="@+id/videoview"
          android:layout_width="fill_parent"
         android:layout_height="wrap_content"        />


</LinearLayout>

Step 3 : Project Structure

For Play Video File You need to place a video file ,as I placed test.mp4 file under raw directory as shown below :

Play Video File Android Example
Play Video File Android Example



Step 4 : Create Java Activity


package javainhouse.com.playvideo;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.PixelFormat;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Button;
import android.widget.VideoView;

public class PlayVideoActivity extends Activity implements SurfaceHolder.Callback{


    SurfaceView surfaceView;
    SurfaceHolder surfaceHolder;
    boolean pausing = false;;


    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_video);

        Button buttonPlayVideo = (Button)findViewById(R.id.button);

        getWindow().setFormat(PixelFormat.UNKNOWN);

        //Displays a video file.        VideoView mVideoView = (VideoView)findViewById(R.id.videoview);



        Uri uri = Uri.parse("android.resource://javainhouse.com.playvideo/raw/"+R.raw.test);

        mVideoView.setVideoURI(uri);
        mVideoView.requestFocus();
        mVideoView.start();



        buttonPlayVideo.setOnClickListener(new Button.OnClickListener(){

            @Override            public void onClick(View v) {

                // VideoView refference see main.xml                VideoView mVideoView = (VideoView)findViewById(R.id.videoview);



                Uri uri = Uri.parse("android.resource://javainhouse.com.playvideo/raw/test.mp4");
                mVideoView.setVideoURI(uri);
                mVideoView.requestFocus();
                mVideoView.start();


            }});
    }

    @Override    public void surfaceChanged(SurfaceHolder holder, int format, int width,
                               int height) {
        // TODO Auto-generated method stub
    }

    @Override    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
    }

    @Override    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub
    }
}

Top 30 Java Interview Programs


1. Program to reverse a String in Java .

2. Program to print Fibonacci series in java.

3.Program to print Fibonacci series in java using recursive method .

4.Program in java to find a String in a sentence.

5. Program to count no.of times a word repeats in String in Java

6. Program to find Prime number in java

7. Program to remove a particular character from a sentence

8. Count the Number of Vowels in Java String

9. Find the substring count from a string without string functions in java

10. Program in java to split String without using split() method

11. Program in java to check whether a String is palindrome or not

12. Program to find largest and smallest numbers among N numbers using an array

13 . How to remove duplicate characters from String in Java.

14. Program for Shifting character in a String eg. String "abcde" should be printed as "eabcd"

15. Program to find  Position of a String in another String.

16. How to sort and reverse an array list without using sort method

17. How to find first non-repeated character of a string in Java.

18. Bubble Sort in Java

19. How to find duplicate numbers in list in Java (using Collection)

20. How to Print numbers for 1 to 100 without using for Loop

21. Java program to find smallest substring in specified characters

22. Write a program to find out all possible unique subString present in a given string

23. How To Count Occurrences Of Each Character In String In Java

24. How to reverse a String using recursion

25. Equilibrium index of an array

26. Java Program to print numbers in pyramid shape

27. Java Program To Remove Duplicate Elements From ArrayList without using Collections

28. Java Program To find factorial of a number .

29. Java Program to find two highest number in an array 

30. How to remove duplicate characters from String in Java.

Find top two highest numbers in a array java


  • Hi Friends today we will discuss about how to find top two maximum numbers in an array using java program.
  • For this we have written separate function to perform logic
  • findTwoMaxNumbers method takes integer  array as an argument
  • Initially take two variables to find top to numbers and assign to zero.
  • By using for each loop iterating array and compare current value with these values
  • If our value is less than current array value then assign current value to max1 
  • And assign maxone to maxtwo because maxtwo should be second highest.
  • After completion of all iterations maxone will have top value and maxtwo will have second maximum value.
  • Print first maximum and second maximum values.
  • So from main method create array and pass to findTwoMaxNumbers(int [] ar)



package com.javainhouse;


public class FindTopTwo { public void findTwoMaxNumbers(int[] array){ int maxOne = 0; int maxTwo = 0; for(int i:array){ if(maxOne < i){ maxTwo = maxOne; maxOne =i; } else if(maxTwo < i){ maxTwo = i; } } System.out.println("First Maximum Number: "+maxOne); System.out.println("Second Maximum Number: "+maxTwo); } public static void main(String a[]){ int num[] = {4,23,67,1,76,1,98,13}; FindTopTwo obj = new FindTopTwo(); obj.findTwoMaxNumbers(num); obj.findTwoMaxNumbers(new int[]{4,5,6,90,1}); }

Output:




First Maximum Number: 98
Second Maximum Number: 76
First Maximum Number: 90
Second Maximum Number: 6

Finding Factorial of a number in Java

  • This interview question is mainly asked to freshers in Java Interviews.  
  • It also represents an example of recursion.
  • Factorial number means multiplication of all positive integer from one to that number.
  • Two factorial:   2!=  2*1=2
  • Three factorial: 3!= 3*2*1=6.
  • Eight factorial:   8!= 8* 7*6*5*4*3*2*1=40320



where ' ! ' sign represents the factorial .


package com.javainhouse;

import java.util.Scanner; public class FactiorialProgram { public static void main(String args[]){ Scanner in = new Scanner(System.in); System.out.println("Enter a number to find factorial"); int n= in.nextInt(); int fact=1; for (int i = 1; i < n; i++) { fact=fact*i; } System.out.println("Factorial of "+n+" is "+fact); } }



Output:

Enter a number to find factorial
5
Factorial of 5 is 24