Add two numbers without using operators

Given two numbers, find sum of them without using arithmetic operators.

Explanation:

Lets assume we have two numbers "a" & "b". In while loop, repeatedly increment the number "a" and subtract number "b" until it becomes zero.

Java program to find sum of two numbers without using arithmetic operators:



Output:
Enter two numbers : 4   5
Sum is : 9

Enter two numbers : 6   8
Sum is : 14

Smallest of three integers without comparison operators

Given three numbers, find Smallest of three integers without comparison operators. Do not make use of mathematical operators in this problem.

Explanation:

Take a count variable and initialize it with 0. In while loop, repeatedly subtract the three numbers with 1. The number which becomes 0 first, then it is the smallest number.


Java Program to find smallest of three integers without comparison operators


Output:
Enter 3 numbers : 1     2      3
Smallest Number : 1

Enter 3 numbers : 4    3    6
Smallest Number : 3

Find angle between hour and minute hand (Clock Angle Problem)

Clock Angle Problem: Given time in HH:MM format, calculate the smallest angle between Hour hand and Minute hand.

Few examples shown in the table
Time1:002:307:0010:3011:203:405:158:45
Angle30°105°150°135°140°130°67½°7½°

In the above picture, small angle between hour and minute hand is 30° when the time is 1'o clock.

Explanation:

  • In 12 hours, hour hand rotates 360° , then in 1 hour it rotates 360°/12 = 30°
                                12 hours ---> 360° 
                                1 hour    ---> 360°/12 = 30°
  • In 60 minutes, minute hand rotates 360° , then in 1 minute it rotates 360°/60 = 6°
                                60 minutes ---> 360°
                                1 minute    ---> 360°/60 = 6°
  • Difference between these two angles is the angle between Hour hand & Minute hand.
  • If the angle is greater than 180° , then subtract it from 360° as we need small angle.

Java program to find angle between Hour and Minute hands :



Output :
Enter Time: 1:00
Small Angle b/w Hour and Min Hands : 30.0

Enter Time: 2:30
Small Angle b/w Hour and Min Hands : 105.0

Converting Decimal to Roman Numeral

In this post we will write a java program to convert a decimal number to equivalent Roman numeral.  Before we step in to the program, we will see what are the Roman symbols and its decimal values.


Roman Symbols and its values:
Roman SymbolDecimal value
I1
IV4
V5
IX9
X10
XL40
L50
XC90
C100
CD400
D500
CM900
M1000


Decimal Forming Rules:

1. When a symbol appears after a larger or equal symbol, then it is added
  • VI = V + I = 5 + 1 = 6
  • XXI = X + X + I = 10 + 10 + 1 = 21
2. But if the symbol appears before a larger symbol, the it is subtracted
  • IV = V - I = 5 - 1 = 4
  • IX = X - I = 10 - 1 = 9

Program :
With the below program, we can covert up to the maximum value 3000. If you want to covert more than 3000, just add more roman symbols in the thousands array.


Output:

Enter a decimal : 9
Roman is : IX

Enter a decimal : 30

Roman is : XXX

Enter a decimal : 2001

Roman is : MMI

Converting Roman Numerals To Decimal

In this post we will write a java program to convert Roman Number to Decimal. Before start our program, lets see what are the roman numbers and its decimal values below.

Roman Numbers and its decimal values:
Roman Symbol
Decimal value
I
1
IV
4
V
5
IX
9
X
10
XL
40
L
50
XC
90
C
100
CD
400
D
500
CM
900
M
1000

Decimal Forming Rules:

1. When a symbol appears after a larger or equal symbol, then it is added

  • VI = V + I = 5 + 1 = 6
  • XXI = X + X + I = 10 + 10 + 1 = 21

2. But if the symbol appears before a larger symbol, the it is subtracted

  • IV = V - I = 5 - 1 = 4
  • IX = X - I = 10 - 1 = 9
Java Program:


Output:
Enter roman value : VI
It's Decimal value : 6

Enter roman value : XC
It's Decimal value : 90

Enter roman value : MCMLXXXIV
It's Decimal value : 1984

BPEL Example

In this post we will create one more BPEL example. In the earlier HelloWorld example we have created a xsd file first and used it in the BPEL process. But we can also generate the xsd file while creating the bpel process. ie. BPEL process automatically creates a xsd file if you don't specify any existing file.

Lets create a simple BPEL process to calculate length of a input string.
We will send some string as input to the BPEL and it will calculate and returns the length of it.

This example includes 4 steps:

  1. Creating a SOA application and project
  2. BPEL creation
  3. Deploy the project
  4. Testing the project



1. Creating  a SOA application and project:

You can create a new SOA application and project by referring below old post
Create SOA Application and Project
Created StringLengthSoaApplication & StringLengthSoaProject

2. BPEL Creation :

Let's create a new BPEL process which returns string length.
1. Open StringLengthSoaProject (composite.xml) file.

2. Right click on the StringLengthSoaProject (Composite.xml) file --> Insert -->BPEL process.

3. Give a name for BPEL process, select "Synchronous BPEL process" and keep the remaining fields as it is with default values. Click on OK

4.  It will generate 3 files. BPEL process file, xsd file and wsdl file

5. In the generated xsd file you can observe both input and result are String types.

6. Open the BPEL file. Drag and drop Assign component between receiveInput and callbackClient.

7. Open Assign component by double clicking on it. Drag and drop Expression component on the result variable.

8. Expression builder dialog box opens. In the expression field add below expression to calculate length of a string.
concat('The Length is : ', string-length($inputVariable.payload/client:input))

I have used concat() & string-length() functions in the "string functions" section to in the above expression.
Click on OK.

9. Click on Apply and OK buttons on the "Edit Assign" dialog.

10. Save all your changes. BPEL has been created successfully.

3. Deploy the project :

Deploy the project by following below post.
After successfully deployed the project, you can test the flow.

4. Testing the project:

Test the deployed project by following below post.
Testing SOA project

Request: 

Response:

Testing SOA project


In this post we will see how to Test SOA composite flow.



Login into url -> http://localhost:7101/em   with your weblogic login credentials. (You have given credentials while creating a domain)

Next at left hand side, expand SOA and click on soa-infra
Next Select Deployed Composites tab and select our SOAHelloWorldProject.

Next click on Test button.

Now on Request tab, enter request details in the input fields and click on Test Web Service button located at bottom.

Now you can observe the Hello World message on Response tab.
full name --> firstname and lastname are appended.
message --> Hello World.

Deploying SOA Project

In this post we will see how to deploy the SOA project.

Before you deploy the project make sure weblogic server  is already running.

Now right click on the project and click on deploy by selecting the project.

Click on Next in Deployment Action dialog.


select check box "Overwrite any existing composites with the same revision ID." and click on Next in "Deploy configuration" dialog.

click on Next in Select Server dialog.


click on Next in SOA Servers dialog.


click on Finish in Summary dialog.

Verify is SOA build success in SOA tab.

Verify is deployment success in Deployment tab.

Creating SOA Application and Project

In this post we will see how to create a SOA Application and project.

I'm using Jdeveloper 12C

File -> New -> Application


Select SOA Application

Enter application name and click Next
Enter project name and click Next
Select Empty Composite and click on Finish

We have created SOA application and SOA project as of now.

Oracle SOA Hello World Example

Let's create a new BPEL process for showing a simple HelloWorld message.
Using Jdeveloper 12c and its integrated weblogic.
First we will create a new SOA application and new SOA project.

Oracle SOA Hello World Example Process steps:


File -> New -> Application


Select SOA Application

Enter application name and click Next
Enter project name and click Next
Select Empty Composite and click on Finish

We have created SOA application and SOA project as of now.

XSD file creation:

First lets create XSD file with request and response.
Right click on schemas folder -> New -> From Gallery



From New Gallery window, select XML Schema.


Enter XML schema name and click OK

Create elements like below in the xsd fle.
This xsd source look like this below.

<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="HelloWorldRequest">
    <xsd:annotation>
      <xsd:documentation>A sample element</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="firstname" type="xsd:string"/>
        <xsd:element name="lastname" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="HelloWorldResponse">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="fullname" type="xsd:string"/>
        <xsd:element name="message" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

BPEL process creation:

Right click on composite.xml design view and select BPEL process.

1)- Enter BPEL process name 
2)- Select Template as "Synchronous BPEL Process"
3)- Click on search button
4)- Select recently created XSD request and response types.



BPEL process looks like below in composite.xml after creation.

Now right click on BPEL process and click on Edit.



After BPEL process file is opened, 
1.Drag Assign component from components palette.
2.drop between receiveInput and receiveOutput.




Double click on Assign component and from right hand side drag functions button and drop on fullname element.
And use string concat() function to concat firstname & lastname.



 Again drag functions button from right hand side and drop on message element.
And enter message as "Hello World".

The Assignment from input and output looks like below.

Click Apply and click on OK.
Save all your changes.


Deploy the project:

Before you deploy the project make sure weblogic server  is up and running.
Now right click on the project and click on deploy by selecting the project.

Click on Next in Deployment Action dialog.


select check box "Overwrite any existing composites with the same revision ID." and click on Next in "Deploy configuration" dialog.

click on Next in Select Server dialog.


click on Next in SOA Servers dialog.


click on Finish in Summary dialog.

Verify is SOA build success in SOA tab.

Verify is deployment success in Deployment tab.


Test our BPEL process:

Login into url -> http://localhost:7101/em   with your weblogic login credentials. (You have given credentials while creating a domain)

Next at left hand side, expand SOA and click on soa-infra
Next Select Deployed Composites tab and select our SOAHelloWorldProject.

Next click on Test button.

Now on Request tab, enter request details in the input fields and click on Test Web Service button located at bottom.

Now you can observe the Hello World message on Response tab.
full name --> firstname and lastname are appended.
message --> Hello World.