Pages

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Saturday, July 15, 2017

Difference Between Interface And Abstract Class In JAVA

Difference Between Interface And Abstract Class In JAVA



Read more »

Tuesday, June 27, 2017

Disable Java Browser Plugin to Improve Browser Security

Disable Java Browser Plugin to Improve Browser Security


disable java on browser

The Java runtime environment has become one of the most exploited of each operating system. Even the Department of Homeland Security United States warns users to disable Java unless
they have a good reason to use it. For most of the days of the Web sites that require Java applets has long since passed. However, there are still a number of desktop applications in Java in a simple uninstall is not practical. Instead, a good way to minimize risk is to disable Java browser plugin. This is the main attack vector, or as Java is exploited, in most cases, and closing the door that will significantly improve the security of your device.

The plugin can be disabled in most modern browsers. Below are the instructions for how to disable the Java plugin for the popular Internet browsers.

Internet Explorer

  1. Open Internet Explorer and click on the gear icon on the far right side of the window.
  2. Select Manage Add-ons.
  3. While the Toolbars and Extensions section is selected, change the Show box to All add-ons.
  4. Scroll down through the add-on list until you get to the Oracle America, Inc. section.
  5. Right click on each Oracle add-on and select Disable.
  6. Click close when you are finished and then close and restart Internet Explorer.
It is important to understand that this will disable applications from running in the browser but be very careful of any applications that launch as a download since those bypass IE completely.

Chrome

  1. Open Google Chrome and navigate to chrome://plugins/
  2. Locate the Java plug-in and click Disable.
  3. Restart Chrome.

Firefox

  1. Open Firefox and hit Ctrl + Shift + A to bring up the Add-ons Manager.
  2. Select the Plugins category.
  3. Locate all java related plugins and click the Disable Button.
  4. Restart Firefox.
Read more »

Friday, May 12, 2017

Difference between Dynamic Binding Static Binding in Java

Difference between Dynamic Binding Static Binding in Java


Dynamic Binding vs Static Binding in Java


Dynamic Binding or Late Binding

Dynamic Binding refers to the case where compiler is not able to resolve the call and the binding is done at runtime only. Lets try to understand this. Suppose we have a class named SuperClass and another class named SubClass extends it. Now a SuperClass reference can be assigned to an object of the type SubClass as well. If we have a method (say someMethod()) in the SuperClass which we override in the SubClass then a call of that method on a SuperClass reference can only be resolved at runtime as the compiler cant be sure of what type of object this reference would be pointing to at runtime.

...
SuperClass superClass1 = new SuperClass();
SuperClass superClass2 = new SubClass();
...
superClass1.someMethod(); // SuperClass version is called
superClass2.someMethod(); // SubClass version is called
....

Here, we see that even though both the object references superClass1 and superClass2 are of type SuperClass only, but at run time they refer to the objects of types SuperClass and SubClass respectively. 

Hence, at compile time the compiler cant be sure if the call to the method someMethod() on these references actually refer to which version of the method - the super class version or the sub class version.Thus, we see that dynamic binding in Java simply binds the method calls (inherited methods only as they can be overriden in a sub class and hence compiler may not be sure of which version of
the method to call) based on the actual object type and not on the declared type of the object
reference.

Static Binding or Early Binding

If the compiler can resolve the binding at the compile time only then such a binding is called Static Binding or Early Binding. All the instance method calls are always resolved at runtime,but all thestatic method calls are resolved at compile time itself and hence we have static binding for static method calls. Because static methods are class methods and hence they can be accessed using the class name itself (in fact they are encourgaed to be used using their corresponding class names only and not by using the object references) and therefore access to them is required to be resolved during compile time only using the compile time type information. Thats the reason why static methods can not actually be overriden. 

For example:-class SuperClass{
...
public String someVariable = "Some Variable in SuperClass";
...
}
class SubClass extends SuperClass{
...
public String someVariable = "Some Variable in SubClass";
...
}
...
...
SuperClass superClass1 = new SuperClass();
SuperClass superClass2 = new SubClass();
System.out.println(superClass1.someVariable);
System.out.println(superClass2.someVariable);
...

Output:-
Some Variable in SuperClass
Some Variable in SuperClass

We can observe that in both the cases, the member variable is resolved based on the declared type of the object reference only, which the compiler is capable of finding as early as at the compile time only and hence a static binding in this case. Another example of static binding is that of private methods as they are never inherited and the compile can resolve calls to any private method at compile time only.
Read more »

Wednesday, April 12, 2017

Developing Java EE applications with Maven NetBeans and Glassfish

Developing Java EE applications with Maven NetBeans and Glassfish


I have been working with EE 6 stack lately, and I find it quite pleasant and productive. For my own learning purpose, I intend to explore more deeper on some of the major components available on the EE stack.

I have started a java-ee6-examples project in GitHub, and I plan to add my examples and working demo code there, along with some blog posts whenever I can. The project is seperated into sub-modules that a typical EE application would organized: a parent module, a common library jar module and one or more web modules etc. The project is buildable using Maven 3 tool on command line, and you may use any major IDE that supports Maven (I will try out NetBeans for these demos).

I will also be testing my examples application mainly on Glassfish Server. Glassfish Server is an open source EE application server, and its current 4.x release supports EE 7 already (GF 3.x is for EE 6). We should able to run any EE 6 applications on GF 4.x without much problems, so for my learning purpose, I will restrict my examples to use EE 6 for now (you will notice that I have to set EE 6 version as dependency in Maven pom file!)

So if you are interested in these, watch this blog for future updates.

To help you started with EE development, I jot down few useful links here.

Downloads:
JDK 7
NetBeans IDE
Glassfish Application Server 
(Oracle also provides convenient package download that includes all 3 above!)

References:
EE 6 Tutorial
EE 6 Technologies
EE 6 API
JDK 7 API


Read more »

Monday, April 10, 2017

Disable Java on Libreoffice at Lubuntu

Disable Java on Libreoffice at Lubuntu


Lubuntu 12.04 is not shipped with Java runtime environment (JRE) installed by default. You need to install JRE via Synaptic package manager to use Java in websites or local software.
Famous office suite Libreoffice require JRE (Java Runtime Environment) to run several macros in Calc and writer. An expert user may need JRE to use some extra feature. But if you do not need JAVA then you can disable it. General uses can be done with no hasitation.
Java runtime environment required at libreoffice startup
Java runtime environment required at libreoffice startup
When you run LibreOffice first it will show the warning message that says:
Libreoffice requires a Java runtime environment (JRE) to perform this task. Please install JRE and restart LibreOffice.
Click OK to go through. You may see this message at least 6 times. Every time click on OK button to start LibreOffice.

LibreOffice Tools Options
LibreOffice Tools Options
After start LibreOffice go directly to Tools menu. Click Tools, a drop down menu will appear. Click on Options.
LibreOffice Options
LibreOffice Options
Click on JAVA at LibreOffice index. See that there is a TICK mark at Use a Java runtime environment text.
disable java in libreoffice
disable java in libreoffice
Click on the radio button of the left side of Use a Java runtime environment text. Now click on OK. Now LibreOffice will not ask for java at every next start.
Read more »

Thursday, April 6, 2017

Developing Java EE applications with Maven and WebLogic 12c

Developing Java EE applications with Maven and WebLogic 12c


The WebLogic Server 12c has very nice support for Maven now. The doc for this is kinda hidden though, so here is a direct link http://docs.oracle.com/middleware/1212/core/MAVEN

To summarize the doc, Oracle did not provide a public Maven repository manager hosting for their server artifacts. However they do now provide a tool for you to create and populate your own. You can setup either your local repository (if you are working mostly on your own in a single computer), or you may deploy them into your own internal Maven repository manager such as Archiva or Nexus.

Here I would show how the local repository is done. First step is use a maven plugin provided by WLS to populate the repository. I am using a MacOSX for this demo and my WLS is installed in $HOME/apps/wls12120. If you are on Windows, you may install it under C:/apps/wls12120.

$ cd $HOME/apps/wls12120/oracle_common/plugins/maven/com/oracle/maven/oracle-maven-sync/12.1.2/

$ mvn install:install-file -DpomFile=oracle-maven-sync.12.1.2.pom -Dfile=oracle-maven-sync.12.1.2.jar

$ mvn com.oracle.maven:oracle-maven-sync:push -Doracle-maven-sync.oracleHome=$HOME/apps/wls12120 -Doracle-maven-sync.testingOnly=false

The artifacts are placed under your local $HOME/.m2/repository/com/oracle. Now you may use Maven to build Java EE application with these WebLogic artifact as dependencies. Not only these are available, the push also populated some additional maven plugins that helps development more easy. For example, you can generate a template project using their archetype plugin.

$ cd $HOME
$ mvn archetype:generate
    -DarchetypeGroupId=com.oracle.weblogic.archetype
    -DarchetypeArtifactId=basic-webapp
    -DarchetypeVersion=12.1.2-0-0
    -DgroupId=org.mycompany
    -DartifactId=my-basic-webapp-project
    -Dversion=1.0-SNAPSHOT

Type Y to confirm to finish. Notice that pom.xml it generated; it is using the "javax:javaee-web-api:6.0:provided" dependency. This is working because we setup the repository earlier. Now you may build it. 

$ cd my-basic-webapp-project
$ mvn package

After this build you should have the war file under the target directory. You may manually copy and deploy this into your WebLogic server domain. Or you may continue to configure the maven pom to do this all with maven. Here is how I do it. Edit the my-basic-webapp-project/pom.xml file and replace the weblogic-maven-plugin plugin like this:

      <plugin>
        <groupId>com.oracle.weblogic</groupId> 
        <artifactId>weblogic-maven-plugin</artifactId> 
        <version>12.1.2-0-0</version> 
        <configuration> 
          <middlewareHome>${oracleMiddlewareHome}</middlewareHome>
          <adminurl>${oracleServerUrl}</adminurl>
          <user>${oracleUsername}</user> 
          <password>${oraclePassword}</password>
          <source>${project.build.directory}/${project.build.finalName}.${project.packaging}</source>
          <targets>${oracleServerName}</targets>
          <verbose>true</verbose> 
          <name>${project.build.finalName}</name>
        </configuration>
      </plugin>  

With this change, you may deploy the webapp into WebLogic server (well, assuming you already started your "mydomain" with "myserver" server running locally. See my previous blog for instructions)

$ cd my-basic-webapp-project
$ mvn weblogic:deploy -DoracleMiddlewareHome=$HOME/apps/wls12120 -DoracleServerName=myserver -DoracleUsername=admin -DoraclePassword=admin123

After the "BUILD SUCCESS" message, you may visit the http://localhost:7001/basicWebapp URL.

Revisit the WLS doc again and you will find that they also provide other project templates (Maven calls these archetypes) for building EJB, MDB, or WebService projects. These should help you get your EE projects started quickly. 

Read more »