Thursday 18 May 2023

Hello World in Java and Go


Hello World:

Java:

public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } }


Go:
package main import "fmt" func main() { fmt.Println("Hello, World!") }

Monday 15 May 2023

Go Vs Java - The Basic Comparison


Go vs Java Architecture Basic Comparison
1. Execution Model:
Go: Go follows a concurrent programming model with goroutines and channels. Goroutines are lightweight threads that can be executed concurrently, allowing for efficient utilization of resources. Channels are used for communication and synchronization between goroutines.
Java: Java follows a multithreaded programming model with threads. Threads are used for concurrent execution, and synchronization mechanisms like locks, semaphores, and monitors are used for communication and coordination.

2. Garbage Collection:
Go: Go has a concurrent garbage collector that runs concurrently with the application code, minimizing pauses. It uses a tri-color, mark-and-sweep algorithm to identify and reclaim unused memory.
Java: Java also has a garbage collector, which runs periodically to reclaim memory occupied by objects that are no longer in use. The garbage collector in Java is generational and uses techniques like mark-and-sweep, copying, and compaction.

3. Compilation:
Go: Go uses a statically-typed, ahead-of-time (AOT) compilation model. The Go code is compiled into a standalone binary executable that can be run on the target platform without any external dependencies.
Java: Java uses a just-in-time (JIT) compilation model. Java source code is compiled into bytecode, which is then executed by the Java Virtual Machine (JVM) at runtime. The JVM translates the bytecode into machine code, optimizing it based on runtime conditions.

4. Concurrency Support:
Go: Go provides built-in support for concurrency with goroutines and channels. Goroutines are lightweight, allowing for the creation of thousands or even millions of concurrent goroutines. Channels facilitate communication and synchronization between goroutines.
Java: Java supports concurrency through threads and the java.util.concurrent package. Threads can be created and managed explicitly, and synchronization primitives like locks, semaphores, and barriers are available for coordinating shared resources.

5. Type System:
Go: Go has a static type system with strong type checking. It uses type inference to determine variable types when they are declared. Go also supports interfaces, allowing for polymorphism and loose coupling between components.
Java: Java also has a static type system with strong type checking. It requires explicit type declarations for variables and supports interfaces and classes for achieving abstraction and polymorphism.

6. Performance:
Go: Go is known for its efficient performance. It has a lightweight runtime, and its compiled binaries can be optimized for specific target platforms, resulting in faster execution times. Go's concurrency model and garbage collector also contribute to its performance advantages.
Java: Java's performance has improved significantly over the years. While the initial startup time may be slower due to JIT compilation, once the bytecode is compiled, Java applications can achieve comparable performance to other languages. Java's extensive optimization features and mature runtime environment contribute to its performance.


Friday 2 August 2019

Upgrade Jdeveloper to 64 Bit JDK / Upgarde Java Version for your Jdeveloper APP



Hi All

In the below article I would like to explain how you can increase your Jdeveloper performance using 64 Bit processor and 8GB RAM


  • Download 64bit JDK 
  • Install JDK (take note pf the path of JDK installed folder)open 


1)Now Open \Oracle\Middleware\jdeveloper\ide\bin\ide.conf

Change the below settings


AddVMOption  -Xmx4096M
AddVMOption  -Xms1024M

Here I'm using 8 GB RAM ( Considering all my other application of the system uses the remaining 4GB of RAM . If you are using less RAM or more apps that consuming more than 4GB then adjust settings saccordingly like for 2GB AddVMOption  -Xmx2048M)


2) Open C:\Oracle\Middleware\jdeveloper\jdev\bin\jdev.conf

Change the below settings

AddVMOption  -XX:MaxPermSize=1024M

SetJavaHome D:\Oracle\Middleware\jdk1.7.0_80 ( Path of your JDK of 64Bit)


3) Now Replace the existing JDK  with the JDK installed path in below files


  • C:\Users\YOURUSERNAME\AppData\Roaming\JDeveloper\system11.1.1.6.38.62.29\DefaultDomain\bin\setDomainEnv.cmd
  • C:\Users\ YOURUSERNAME \AppData\Roaming\JDeveloper\system11.1.1.6.38.62.29\DefaultDomain\init-info\domain-info.xml
  • C:\Users\ YOURUSERNAME \AppData\Roaming\JDeveloper\system11.1.1.6.38.62.29\DefaultDomain\init-info\startscript.xml
  • C:\Users\ YOURUSERNAME \AppData\Roaming\JDeveloper\system11.1.1.6.38.62.29\DefaultDomain\init-info\tokenValue.properties
  • D:\Oracle\Middleware\jdeveloper\jdev\bin\jdev.conf (we have already done this )


4) Restart Jdeveloper , see the difference in performance .

* For few other settings you can check this Link

Happy Coding !!
-Krishna Prathi

Thursday 25 July 2019

Blob Upload issue in Oracle ADF 

(Cannot create an object of type:oracle.jbo.domain.BlobDomain from type:weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB)


This error you ll face when you upload a file to Blob column

The actual error description is 

oracle.jbo.domain.DataCreationException: JBO-25009: Cannot create an object of type:oracle.jbo.domain.BlobDomain from type:weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB with value:weblogic.jdbc.wrapper.Blob_oracle_sql_BLOB@c


You can  fix the issue by following the below steps:

  • Go to Data Sources -> Your Data Source -> Connection Pool -> Advanced in the below Then uncheck the Wrap Data Types
  • Save
  • Restart The server 



Cheers!!
Krishna Prathi 

Sunday 9 June 2019

Read Property files in jsff and java class in ADF project

Hi

We often have the requirement of reading properties from a file placed inside the ADF application itself . We use this mainly for easy access of properties that uses in many locations across the application.


Code to read property file  in java:

  InputStream st = null;
 Properties prop = new Properties();
 st =
    Thread.currentThread().getContextClassLoader().getResourceAsStream("/com/view/read.properties);

 try {
           prop.load(st);
          String personID=prop.getProperty("Employee") ;;

 
         }catch (Exception e) {
           logErrorStackTrace(e);
            }finally{
                try{
                    if (st !=null) {
                        st .close();
                    }
               
                }catch (Exception e) {
                    logErrorStackTrace(e);
                }
            }

*Must close the st  after usage

Code to read property file  in jsff:

Declaration / import :
 
 <c:set var="propfile"

           value="#{adfBundle['com.view.read']}"/> // read is the property file name

Usage:

            <af:outputText value="#{propfile.outputtext}"
                            id="ol1"/>


Thank You!!

Never stop learning ...

Read Property files in JAVA/ ADF from external location

Hi

We often have the requirement of reading properties from a file placed in external location of server . This always helps to make the changes in application with out down time.

Say , If you have configured a property named  "PROMOAVAILABLE" in property files and is set to ON if promotion is applicable and OFF if not applicable.
Based on this you can alter your logic in the code and there will be no re deployments necessary.


code to read property file :

 FileInputStream fileInputStream= null;

    try {

          File file=new  File("/opt/oracle/read.properties"); // Property file location
          fileInputStream= new FileInputStream(file);
          ResourceBundle resource = new PropertyResourceBundle(fileInputStream);
          String promo=resource.getString("PROMOAVAILABLE") ;

           if("ON".equalsIgnoreCase(promo)){
                         //write code
                }
        else{
                         //write code
              }

         }catch (Exception e) {
           logErrorStackTrace(e);
            }finally{
                try{
                    if (fileInputStream !=null) {
                        fileInputStream.close();
                    }
                 
                }catch (Exception e) {
                    logErrorStackTrace(e);
                }
            }

*Must close the FileInputStream after usage 

Tuesday 1 March 2016

createRow and createAndInitRow - Difference

Hi
The major difference between createRow and createAndInitRow methods  is
createAndInitRow  :
Creates and initializes a new Row object, but does not insert it into the Row Set.
This method differs from createRow() mainly in that this method allows the user to pass in a list of name-value pairs with which row attributes are initialized.
E.g:
    public void insertMethodCreateAndInitRow () {
        ViewObjectImpl vo = this.getExampleVo();
        NameValuePairs nvp = new NameValuePairs();
        try {
            nvp.setAttribute("Attr1", "ABC");
            nvp.setAttribute("Attr2", "123");
            nvp.setAttribute("Attr3", "XYZ");
            Row row = vo.createAndInitRow(nvp);
            vo.insertRow(row); // Inserts a row to the Row Set
        } catch (TooManyObjectsException e) {
            e.printStackTrace();
            }catch(DMLConstraintException e){
                e.printStackTrace();
            }
        getDBTransaction().commit();
    }
createRow  :
Creates a new Row object, but does not insert it into the Row Set.
E.g:
    public void insertMethodCreateRow() {
        ViewObjectImpl vo = this.getExampleVo();
        Row row = vo.createRow();
        try {
            row.setAttribute("Attr1", "ABC");
            row.setAttribute("Attr2", "123");
            row.setAttribute("Attr3", "XYZ");
            vo.insertRow(row); // Inserts a row to the Row Set
        } catch (TooManyObjectsException e) {
            e.printStackTrace();
            }catch(DMLConstraintException e){
                e.printStackTrace();
            }
        getDBTransaction().commit();
    }
We can use createAndInitRow instead of createRow because it sets default values of attributes in view object while creation of Row at run time using the named value pair passed to it.


Thanks
Krishna

Wednesday 7 October 2015

Attempt to set a parameter name that does not occur in the SQL : Bind variable


Hi All

Some times we will get an error

Attempt to set a parameter name that does not occur in the SQL : BindvariableName

This error comes when we have a bind variable that is not using in SQL query but using in View Criteria with required as true.


So it's a thumb rule we need to remember is that

If we are using the bind variable in SQL Query of View Object then only we need to check the required check box.

If we are not using in SQL Query but using in View Criteria it should unchecked.

So to get rid of this error uncheck required check box



Thanks
Krishna


Tuesday 18 August 2015

ADF Life Cycle


Hi All

In this Post  I would like to discuss about ADF life cycle .
When a request is sent from client to server , the application invokes ADF pagelife cycle , an extended version of JSF life cycle. The following diagram will help you to understand the extended phases of ADF life cycle compared to JSF life cycle.



So, the phases of ADF life cycle will includes

  1. Restore View
  2. ADF Init Context
  3. ADF Prepare Model
  4. Apply Request Values
  5. Process Validation
  6. Update Model Values
  7. ADF Validate Model Updates
  8. Invoke Application
  9. ADF Metadata Commit
  10. ADF Prepare Render
  11. Render Response



I will try to explain this in a simple way
When a request is sent from client to server
1)   ADF frame work will do some pre-processing. ADF frame work will provide ADFBindingFilter , which is defined on web.xml . ADFBindingFilter will find an existing Binding Context (if it is in current session)  or create a new Binding Context . Binding Context holds the mappings of pages , Page Definition files , list of data controls used etc., as a run time representation of DataBindings.cpx file.
2)      Binding Context which stores the information of ADF life cycle will be initialized with associated request and Binding Container.(The binding container contains the control bindings of a reusable units like region, page etc., Binding Container is a request scope map)
3)      During the Prepare Model phase life cycle invokes the refresh method on the Binding Container .Prepare Model will executes any executables (iterators etc.,)whose refresh property is set to prepareModel
4)      Input values will be stored in temporary location and initialized
5)   Validations on input data will be imposed (like conversion to underlying data types ,validations etc.,)
6)      The local values will be discarded and updated in the model.
7)      Validations will be done at model level , like the updated attribute value will be validated at EO level .
8)      Any action bindings will be invoked in this phase
9)      Changes to run time metadata are committed. This phase stores any run time changes made to the application using the Metadata Service (MDS)
10)   The binding container is refreshed to allow for any changes that may have occurred in the Apply Request Values or Validation phases
11)   Finally The page will appear in this Phase

Please go through the following link for more information

Thanks
Krishna





Saturday 1 August 2015

Jdeveloper Memory settings for better Performance:


Hi All

Usually we face the memory running low error with Jdeveloper . We can optimize this  by using some setting for Jdeveloper .

From different sources I have found these settings will optimize the performance

I am listing those below

1) Locate your jdev.conf file , it will be at the following path if your Jdeveloper was installed on C drive.

C:\Oracle\Middleware\jdeveloper\jdev\bin

Open jdev.conf file 

As Jdev runs on JVM we can keep some settings related to JVM to increase the performance

Add the following settings :

#optimization of  JVM for strings / text editing
AddVMOption -XX:+UseStringCache
AddVMOption -XX:+OptimizeStringConcat
AddVMOption -XX:+UseCompressedStrings

# if you are using a 64-bit system (less than 32 GB RAM) to reduce object pointer memory size we can use
AddVMOption -XX:+UseCompressedOops

# we can use aggressive garbage collector
AddVMOption -XX:+AggressiveOpts

2) Locate your ide.conf file at the path C:\Oracle\Middleware\jdeveloper\ide\bin

The default memory settings will be
AddVMOption  -Xmx800M
AddVMOption  -Xms128M

We can increase the memory of minimum and maximum heap spaces to 

AddVMOption  -Xmx1024M
AddVMOption  -Xms1024M

3) Go to Tools -> Preferences -> File Types -> Default Editors

and set Default Editor as source for html , jsf , jsp pages




4) As Oracale Themes have styles compared to windows
we can set the Look and feel to Windows  instead of Oracle @the following path
Tools -> Preferences -> Environment -> Look and Feel

* Should  Restart Your Jdeveloper once these settings are done.

Thanks
Krishna

Hello World in Java and Go

Hello World: Java: public class HelloWorld { public static void main (String[] args) { System.out.println( "Hello, W...

Popular Posts