Navigation

Saturday, 12 September 2015

Encapsulation in Practical.

Encapsulation is one of the four fundamental OOP concepts.Encapsulation is the technique  to Provide the ability to a program to hind their internal characteristics and behaviorof by  creating
private fields in class and providing access to them via public methods.
If a field is declared private, it cannot be accessed by anyone outside the class,
thereby hiding the fields within the class.So encapsulation  protect them by unauthorized access / party  by creating a protecting wrapper around your code and data.

Encapsulation can be described as a protective barrier that prevents the code and data being
randomly accessed by other code defined outside the class.
The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code. With this feature Encapsulation gives maintainability, flexibility and extensibility to our code.

For Example

We have a data class with two fields name and id

public class Result{

   private String name;
   private String remark;


   public String getName(){
      return name;
   }
  public void setName(String newName){
      name = newName;
   }
   public String getRemark(){
      return remark;
   }

   public void setRemark( int remarkPoints){
     
      if(remarkPoints>=5)
      {
         remark="good"
      }

      if(remarkPoints<5)
      {
         remark="poor"
      }
     
   }

In above example we set remarks according to remark points.But after sometime we need to add one
more remark "very good" for student who gets 10 points so we wont ask user of code to change but we will change the setter


 public void setRemark( int remarkPoints){
   
      if(remarkPoints==10)
      {
         remark="very good"
      }

      if(remarkPoints>=5 && remarkPoints<10)
      {
         remark="good"
      }

      if(remarkPoints<5)
      {
         remark="poor"
      }
     
   }


More Example :-


Like we have a class Phone with filed weight, if you will not encapsulate it someone can modify it to have –ve weight,
so it is better to encapsulate using private variable and providing setter method where you will add logic of No –ve and Not over 100 grams.


Let’s take real example of CAR, car is an well-defined composite object with lots of sub systems like transmission system,
music system, air-cooler  or heater system and may have other based on the price of the car.
Now each system has their own protecting layer and because of that transmission system is not interfering with music system
or air-cooler system but yes there is some integration such a way that transmission charges the battery and it helps to play music but no one can directly modify the behavior of other system. So this is the way they hides the complexity of a program



Benefits of Encapsulation:
1)The fields of a class can be made read-only or write-only.

2)A class can have total control over what is stored in its fields.

3)The main benefit of encapsulation is the ability to modify our implemented code without breaking the code of others who use our code because
users of a class do not know how the class stores its data. A class can change the data type of a field and users of the class do not need to change any of their code.

Monday, 7 April 2014

Deploy war on weblogic server by weblogic console

In this post we will see how to deploy a war on weblogic by using weblogic console.

1)First start the admin server of your weblogic server  for this browse to the path of domain of your weblogic server .it will be some what like

D:\Oracle\Middleware\user_projects\domains

here you will get all the domains created
so in

D:\Oracle\Middleware\user_projects\domains\Domain_name\bin

you will get  startWebLogic.cmd or startWebLogic.sh
depending on your OS Just run it and you will see a cmd console

2)Now If your weblogic server is started succssfully it will display running in console




3) After starting weblogic server succssfully . Open the weblogic console from the below linkhttp://localhost:7001/console





where localhost is the machine address on which weblogic server is running.And 7001 is the port on which weblogic admin server is running.
4)Now it will ask for username or password just enter your domain username and password
and it will redirect to a screen.




5) Now click on deployment on the left side pannel and you will se a screen asking to browse
the war file.



6)Just browse to the war file want to deploy on weblogic server.





7) Now click next and it will ask to chose the server on which you want to deploy the war from
here you can select Admin server or any other managed server(If you chose other managed server
then you have to start it seprately from nodemanager or manully)





8) Now click next and select radio button which says copy the war on every target to uplaod
war on weblogic server



9) Now if deployment is completed then it will display that sataus of deployment as Active.

Sunday, 2 March 2014

Some Advanced Ant Tasks (ANT Part-5)

In our last posts we have seen 

Sleep: If you want some gap between two tasks or want some pause then  this task is used to sleep the build process for a while. We can use milliseconds,seconds and hours also in aatribute. 

<sleep milliseconds="10"/> 

 Sql: To execute some query or after finishing a task you want to update some column in any table or want to fire any type of query then this task is used to execute SQL commands using Java JDBC connectivity. 
<sql 
 driver="jdbc driver name" 
 url="jdbc url" 
 userid="ui" 
 password="pass" 
 > 
insert 
insert into aots_users values (1, "aots1"); 
</sql> 

FTP: After creating any patch or folder you want to copy it on nay FTP to allow others to access it from another location then this task is used to ftp files to a ftp server 
 <ftp server="ftp.tcs.org" 
 remotedir="incoming" 
 userid="hemant12345" 
 password="hk@123" 
 depends="yes"> 
 <fileset dir="d:mypatch/currentpatch"/> 
 </ftp>

Sound: If you are running a build or any other task and do not want to sit and watch screen but you want to raise an alarm after finishing the task then you can use this task is to create sound during the build process for specific tasks. 
 <sound> 
 <success source="alert.wav"/> 
</sound>



Attrib: This task is used to set the properties of a file 
 <attrib file="username.properties" readonly="true" hidden="true"/> 

Sync:  To synchronize two folders we can use this task. This file will overwrite the data and also it will remove the files from the todir folder. 
<sync todir="Server"> 
 <fileset dir="local"/> 
</sync> 

LoadProperties: This task is used to load the contents of the properties file as ant properties.Means you do not need to rewrite the property file for ant in separately. 
The properties should be as key=value format 

 <loadproperties srcFile="file.properties"/>



You may also like:-

Using JConsole in java And creating memory dump by it


Heap analysis by Memory Analyzer (MAT) - Eclipse java


Main causes of Out-Of-Memory Errors in java


Five main types of Memory leaks in java


How to Reduce Garbage-Collection Pause Time?


4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?

Saturday, 1 March 2014

Some Core Ant Tasks (ANT Part-4)

In our last post we have seen 
Now we will see some core task which can be performed by using ANT. Below are some of the most useful tasks .

GUnzip: This task is used to unzip and expand the tar files with gz
extensions. These files are unziped in the current folder.

<gunzip src="abc.tar.gz" dest="aaa.tar"/> 



Gzip: This task is used to zip the source files using GZip  algorithms. The source(src) and the destination (destfile or zipfiles) attributes are mandatory 
<gzip src="aaa.tar" destfile="abc.tar.gz"/> 


Copy: Copy a file to a new file or to a new folder. 
<copy file="copythis.txt" tofile="tothis.txt"/> 


Delete: This task is used to delete a folder , file and folder's entire sub directories. the properties used with delete are includes, includesfile, excludes, excludesfile or defaultexcludes to add or 
remove files from deleting. But all these tasks are depreciated and it’s recommended to use 
resource collections. 
 <delete> 
 <fileset dir="." includes="**/*.bak"/> 
</delete> 

Ear: This task is used to create ear file for Enterprise Deployment. 
 <ear destfile="build/myproject.ear" appxml="src/metadata/application.xml"> 
 <fileset dir="build" includes="*.jar,*.war"/> 
 </ear>



Echo: This task is used to echo message during the build process. We can write the message in the console or to a specified file. We have options to setup the level of logging 
as error, warning, info, verbose and debug. 
<echo file="mylogfile.lgo" level="error"> 
build filed!!!!!!!!!!!!!!!! 
</echo> 
<echo message="Hello copied folders "/>

Jar: This task is used to create jar file from a specific folder. The includes or excludes 
properties can be used to add or prevent few files adding in the jar file 
 <jar destfile="${dist}/lib/myfirstjar.jar" 
 basedir="${build}/classes" 
 includes="com/abc/**" 
 excludes="**/TestDemo.class" 
/>

Mail: This task is used to send mail using SMTP.
<mail mailhost="smtp.gmail.com" mailport="1076" subject="Testing Mail.."> 
 <from address="hemant2422@gmail.com"/> 
 <replyto address="hemant2422@gmail.com"/> 
 <to address="myreaders@gmail.com"/> 
 <message>type your message here </message
 <attachments
 <fileset dir="thisfolder"> 
 <include name="nameoffiletobeincluded"/> 
 </fileset> 
 </attachments
</mail

Move: This task is used to move or remane a file to a new file or to a folder 
<move file="abc.txt" tofile="xyz.txt"/> - this can be also used for renaming the file

Retry: If you want to repeate a task which is faild or want to run it sevral time when it fails then you have to use this 
<retry retrycount="5"> 
 <get src="myjar.jar" 
 dest="/com/build/myjar.jar" /> 
</retry> 



You may also like:-

Using JConsole in java And creating memory dump by it


Heap analysis by Memory Analyzer (MAT) - Eclipse java


Main causes of Out-Of-Memory Errors in java


Five main types of Memory leaks in java


How to Reduce Garbage-Collection Pause Time?


4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?

Thursday, 27 February 2014

Create,Delete and Compile by ANT build file.(Ant Part-3)

In our last post we have seen 
Now we will see some core task which can be performed by using ant such as create a folder or delete folder and to compile the java source.If till now you have not got 1% idea about ANT don't worry it is not needed also just check the below XML build file.

<?xml version="1.0"?>
<project name="MyfirstAnt" default="main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="create.dir" location="D:/MyAnt/NewFolder" />
  <property name="delete.dir" location="D:/MyAnt/OldFolder" />                  
  <!-- Deletes oldFolder from the path delete.dir-->
  <target name="cleanFolder">
    <delete dir="${delete.dir}" />
  </target>

  <!-- Creates a newfolder on the path create.dir-->
  <target name="makefolder">
    <mkdir dir="${create.dir}" />
  </target>

  <!-- Compiles the java code (including the usage of library for JUnit -->
  <target name="compile" depends="cleanFolder, makefolder">                 <javac srcdir="${src.dir}" destdir="${build.dir}">
    </javac>

  </target>
  <target name="main" depends="compile">
    <description>Main target</description>
  </target>

</project> 

Here we have written three tasks first is to delete a particular folder from file system  the path which you will give in dir attribute it will clean the particular folder means it can be used to clean the class files before building .

Second task is to create a folder so you can create any folder in file system it can be temp .

and last task is to compile the the java source files here we have to give the source path of java files and destination folder where you have to keep the class files you can also set class-path for proper compilation which we will discuss in our coming posts.


You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?

Setting Apache ANT on Computer (Ant part-2)

 Setting up your machine with Ant

Follow the steps to setup the Ant in your computer.

1. Download the following  files(apache-ant-1.7.0-bin.zip) to your hard drive.

2. Unzip the file to anywhere in your hard drive in any folder.

3. Right click your My Computer icon in the Desktop and choose the properties.

4. In the properties now select the Advanced tab and open Environment Variables button.

5. Click on the New button in the System Variable options and enter the following
Variable name - ANT_HOME
Variable value – The ant path location in your system (for example C:\ant\myant)

6. Click the OK button ans save the setting

7. Set the PATH as below in your system (If you have a PATH variable exists in your system then
append the ANT_HOME to it)
set PATH=%PATH%;%ANT_HOME%\bin


Tuesday, 25 February 2014

What is Apache Ant ("Another Neat Tool") in java?(ANT Part-1)



Apache Ant ("Another Neat Tool") is a  build tool with special support for the Java programming language however it may be used for regarding everything. Ant is platform-independent. Ant is especially sensible at automating difficult repetitive tasks and so is well matched for automating standardized build processes. Ant accepts directions within the type of XML documents so is extensile and simple to take care of.So you can say it is a xml file you running by the help of Ant.

An ant build file comes within the sort of an XML document, all that's needed may be a straightforward text editor to edit the build file(s). an editor that gives XML syntax lightness is desirable. The ant installation comes with a JAXP-Compliant(Which is XML parser) ,this implies that the installation of AN external XML computer program isn't necessary

For Installation 

1)You will need to download a file apache-ant-1.7.0-bin.zip
2)Extract it 
3)Here you will get "bin" folder
4)In "bin" run the ant.bat file from cmd.


Now let us try this with a simple build.xml for this.

1)create a file in notepad or any other file editor

2)copy the below code in that

<?xml version="1.0"?>
   <project name="My First Project" default="whatsup">
       <target name="whatsup">
          <echo>Hi this is my first ant build file</echo>
       </target>
   </project>

3)Save this as build.xml file(in ant bin directory where ant.bat is present)
apache ant

4)You can run this from a DOS  command prompt by typing

  ant
Ant will search for the build file in the current directory and run the build.xml file.

5)your out put will


Buildfile: build.xml
  
  whatsup: 
     [echo] Hi this is my first ant build file!
  
  Build Successful
  Total time 0 seconds

If you have many targets which you have run or execute in series then you can use depends attribute.
The depends attribute may be enclosed within the target tag to specify that this target needs another target to be executed before being executed itself. Multiple targets may be nominal and separated with commas.

<target name="ab" depends="bc, cd,de">

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

 <project default="3">
     <target name="1">
        <echo>Running first</echo>
     </target>
  
     <target name="2" depends="1">
        <echo>Running second</echo>
     </target>
  
     <target name="3" depends="2">
        <echo>Running third</echo>
     </target>
  </project>

Buildfile: build.xml
  
  one:
     [echo] Running first
  
  two:
     [echo] Running second
  
  three:
     [echo] Running third
  
  BUILD SUCCESSFUL
  Total time: 0 seconds


Ant Task – one thing that ant will execute like a compile, copy or replace. Most tasks have much convenient default values. See the ant manual for an entire list of tasks.

Ant Target – a hard and fast series of ant tasks in an exceedingly nominal order that may depend on alternative named targets. Targets will depend solely on alternative targets, not on projects or tasks. A target represents a specific item to be created, it can be one item sort of a jar, or a group of things, like classes.

Ant Project – a set of named targets that may run in any order looking on the time stamps of the files within the file system. every build file contains one project.


Here are a few things to note:

1.The Begin and finish tags for project (<project> and </project>) MUST Begin and end the file.

2.The tag project MUST have an attribute called default which is the targets called first.

3.There should be at least one target in each build file.

4.The Begin and finish tags for <target> and </target> must  match EXACTLY.

5.Each target should  have a name.

6.Targets will only depend  on other targets and reference them by their name(target name). it NEVER depend on projects or tasks.

7.Target depends are not mandatory.

8.To print any thing in output on console write it in <echo> and </echo> tags.

9.All task has to be in a target.


You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?
http://www.casino-online.us