Our social:

Latest Post

Tuesday, 29 December 2015

Why main() has public static void syntax

The Reason behind

public static void main(String[] arg){}

In the above statement public static void main(String[] arg){} is prototype that is provided by JVM. This static method is given to programmer to write their program execution flow logic like which class we are going to load first, which method execution requires first.  By using main method we are requesting to JVM , hy!!!! jvm you start my program execution in the given fashion.

Now here one question arises that why Main method?
Actually main method is not user defined method, this method is predefined and given by jvm. By following thier prototype we are writing our logic here.
Then another question is why main method has public static void main(){} syntax.

why public?
public is because our program executed by jvm and we all know jvm resides outside of our class and package. In case we define private and protected then, the scope of main() method will be restricted and can not be accessed outside of the package or class will not be unable to execute or load in JVM. that's why we should write main() as public.

why static?
we are using main() as static, why because to execute our program we need some memory in jvm. And as we know that static is special keyword that provide memory of a method at class loading time. So at the time of public class or main method class loading jvm will provide memory to main method. Once main() method gets memory then it will starts execution of our program sequentially.

why void?
main()method not returning any values and there is also no need to return any values. It is only use to execute programs that's why it is declared as void.

NOTE:this is my analyzation and gathered from internet, if i am wrong on any point please correct me through comment then i will try to modify...
                                     Thank you(Smartyy Sunny)

Friday, 25 December 2015

Growable Array Alogrithm programming Example

Tags: How To Create Growable Array, How To Insert Element In Array,How To Insert Add In Array,How To Remove Element In Array,How To Replace Element In Array, Growable Array Algorithm Program.


This is growable Array algorithm program that is able to slove size limitation and type limitation     problem of Array. In this progran we can increase array size if required dynamically" increaseCapacity()" method is responsible to do this work. Here various methods are defined to insert, add, remove and replace to modifying array element


import java.io.*;
class ArrayCollection
{
private Object[] arrayObj=new Object[5];
private int index=0;
public int capacity(){
return arrayObj.length;
}

public int size(){
return index;
}

//Add elements to array
public void add(Object ele){
if(this.size()==this.capacity()){
increaseCapacity();
}
this.arrayObj[index]=ele;
index++;
}

//increase capacity method for arrayObject 

public void increaseCapacity(){
int newCapacity=this.capacity()+(this.capacity()/2);
Object[] tempObj=new Object[newCapacity];

for(int i=0;i<arrayObj.length; i++){
tempObj[i]=arrayObj[i];
}
arrayObj=tempObj;
}

//retriving element from collection

public Object get(int index){
if(index<size()){
return arrayObj[index];
}else{

throw new ArrayIndexOutOfBoundsException(""+index);
}
}

//replacing logic in replace method

public void replace(int index, Object ele){
if(index>=this.size()){
throw new ArrayIndexOutOfBoundsException(""+index);
}else{
this.arrayObj[index]=ele;

}
}

//code removing elements from collection

public void remove(int index){
if(index >=this.size()){
throw new ArrayIndexOutOfBoundsException(""+index);
}else{
for(;index<this.size()-1; index++){
arrayObj[index]=arrayObj[index+1];
}
arrayObj[size()-1]=null;
index--;
}
}

//inserting values in Collection

public void insert(int index, Object ele){
if(index>=size()){
throw new ArrayIndexOutOfBoundsException(""+index);
}
if(size()==capacity()){
increaseCapacity();
}
//System.out.println("hiii");
for(int i=size();i>=index;i--){
arrayObj[i+1]=arrayObj[i];
}
arrayObj[index]=ele;
this.index++;
}
// this section for testing purpose........
public static void main(String[] args) 
{
ArrayCollection ar=new ArrayCollection();
System.out.println("Capacity of this array "+ar.capacity());
System.out.println("Size of this array "+ar.size());

ar.add(1);
ar.add(2);
ar.add(3);
ar.add(4);
ar.add(5);
System.out.println("Size of this array "+ar.size());
//System.out.println("value "+ ar.get(2));
//ar.replace(2,8);
//System.out.println("after replacing index 2 value is"+ ar.get(2));
//ar.remove(2);
//System.out.println("after removing index 2 value is"+ ar.get(2));
//System.out.println(ar.size());
ar.insert(2,9);
System.out.println(ar.get(2));
System.out.println(ar.capacity());
System.out.println(ar.size());
}
//you can also test program according to requirment....
}

You can execute this program directly by just copy from here and paste in notepad and save this file with class name with .java extension. And then simply execute from command prompt...
                                                                                    Thank you(Smartyy Sunny)
                                                                                                         Happy Coding......

Thursday, 17 December 2015

Can we typecast implicit variable "this" and "super" if yes then how, if no then why?

:Yes we can typecast implicit variable "this". this variable is a special referenced type variable that is used to denote current object class reference. It will internally stores the value of current object class reference.
code snapshop:


Now our question is if yes the how it is possible.....
Simple, we have a class called  A that bydefault extending Object class so it is good to take this example..Now i have created an object of class A and i want to store class A type variable value in Object type reference variable.
A a=new A();
Object obj1=(Object)this;
here this variable contains A class information  and that is going to be store in obj1 that is of Object type.
so in this case we are able to typecast implicit variable "this"
full code is looks something like this:

------------------------------------------------------------------------------------------------------------------------
class Atest 
{
void m1(){
Object obj1=(Object)this;//here obj1 is Object type super class ref variable 
                        //and we are passing this variable value(subclass type) to super class
System.out.println(obj1.getClass());
}
public static void main(String[] args) 
{
Atest a1=new Atest();
a1.m1();
}
}

According to my analyzation "super" variable type casting is not possible.....
why, i will post in next post..........

                                                                                                             Thank you(Smartyy Sunny)

Saturday, 24 October 2015

How To Purpose Your GirlFriend Using Java


Lebels: Purpose a girl using java language, Velentine Gift for Java Programmer, Write I Love In java,



package org.smartyy.ilove;

/*
 * @author
 * @Smartyy Sunny
 *@version 1.0
*/

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import java.io.*;
public class LoopLove {


public static void main(String[] args) throws AWTException{
Robot r1=new Robot();
Runtime run=Runtime.getRuntime();
try {


run.exec("notepad");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

r1.delay(1000);
r1.keyPress(KeyEvent.VK_I);
r1.keyRelease(KeyEvent.VK_I);
r1.delay(2000);

r1.keyPress(KeyEvent.VK_SPACE);
r1.keyRelease(KeyEvent.VK_SPACE);

r1.keyPress(KeyEvent.VK_L);
r1.keyPress(KeyEvent.VK_O);
r1.keyPress(KeyEvent.VK_V);
r1.keyPress(KeyEvent.VK_E);
r1.keyRelease(KeyEvent.VK_L);
r1.keyRelease(KeyEvent.VK_O);
r1.keyRelease(KeyEvent.VK_V);
r1.keyRelease(KeyEvent.VK_E);
r1.delay(2000);

r1.keyPress(KeyEvent.VK_SPACE);
r1.keyRelease(KeyEvent.VK_SPACE);

r1.keyPress(KeyEvent.VK_Y);
r1.keyPress(KeyEvent.VK_O);
r1.keyPress(KeyEvent.VK_U);
r1.keyRelease(KeyEvent.VK_Y);
r1.keyRelease(KeyEvent.VK_O);
r1.keyRelease(KeyEvent.VK_U);

r1.delay(2000);

for(int j=0;j<10;j++){

r1.delay(1000);
r1.keyPress(KeyEvent.VK_BACK_SPACE);
r1.keyRelease(KeyEvent.VK_BACK_SPACE);
}
r1.delay(2000);

for(int i=0;i<10;i++){

r1.keyPress(KeyEvent.VK_SPACE);
r1.keyRelease(KeyEvent.VK_SPACE);

r1.keyPress(KeyEvent.VK_I);
r1.keyRelease(KeyEvent.VK_I);
r1.delay(2000);

r1.keyPress(KeyEvent.VK_SPACE);
r1.keyRelease(KeyEvent.VK_SPACE);

r1.keyPress(KeyEvent.VK_L);
r1.keyPress(KeyEvent.VK_O);
r1.keyPress(KeyEvent.VK_V);
r1.keyPress(KeyEvent.VK_E);
r1.keyRelease(KeyEvent.VK_L);
r1.keyRelease(KeyEvent.VK_O);
r1.keyRelease(KeyEvent.VK_V);
r1.keyRelease(KeyEvent.VK_E);


r1.keyPress(KeyEvent.VK_SPACE);
r1.keyRelease(KeyEvent.VK_SPACE);

r1.keyPress(KeyEvent.VK_Y);
r1.keyPress(KeyEvent.VK_O);
r1.keyPress(KeyEvent.VK_U);
r1.keyRelease(KeyEvent.VK_Y);
r1.keyRelease(KeyEvent.VK_O);
r1.keyRelease(KeyEvent.VK_U);




r1.delay(3000);

for(int j=0;j<10;j++){
r1.keyPress(KeyEvent.VK_BACK_SPACE);
r1.keyRelease(KeyEvent.VK_BACK_SPACE);
}
r1.delay(1000);

}

}

}

------------------------------------------------------------------------------------------------------------------------
Procedure to make it executable for non-technical people. Let's see if you girlfriend is a non-technical person then set an enviornment to make it simple executable application.

1st Step

  • create a shortcut in desktop
  • in location section write "javaw com.smartyy.ilove.LoopLove"
  • name for the shortcut[LoveApp] and click finish.


2nd Step


  • right click on the shortcut icon
  • click on properties
  • click on shortcut
  • and provide location of the java class 
  • note: download my sorce folder and paste on any location like D: drive 
  • Locate bin folder path in Start-in box
  • choose shortcut key 
  • choose any icon and click ok


download work folder

After downloading copy this folder on D drive and copy patha of bin and paste in START-IN box. Ensure that you have installed JRE or JDK in your computer system. if not installed go to google and first create java enviornment then set up this application...


if you have done all these things:
Now say your girlfriend  to double click on that shortcut icon created by.... and see what happend...
Good luck guysss and enjoyee new approch to express your love....happy cooading

                                                                                                     Thank you (Smartyy Sunny)

Sunday, 18 October 2015

Day to Day operation in java by using java keywords


Day to Day operation in java by using java keywords
Package creation and uses
Class creation
Variables and method creation
Memory allocation
Controlling and modification
Setting access permission
Setting execution level permission
Establishing inheritance relationship
Representing objects and its member
Handling user mistake

Initially java contains 47 keywords. But 3 other keywords are added in other java releases.
In java 1.2 strictfp is a new keyword added in java keyword list. 
In java 1.4 another new keyword assert is added in keyword list.
In java 1.5 another keyword enum is added in java keyword list.
So, now java has totally 50 keywords to perform special operation. Each keyword has special meaning to perform one task.
Now i am going to show all 50 keyword of java as per their uses.

Thursday, 8 October 2015

How To Transfer Mysql Table Data To Oracle Database Table

hy friendss..
Today i faced a problem or question that most of student face in jdbc programming. and the question is How To Transfer Mysql Table Data To Oracle Database Table. It means copying data from one database to another database. This questionn sounds like it is very complex task but reality is different. you need to follow some steps and then you are ready to start copying...

General

step1: keep tow local database in machine(oracle and mysql).
step2: ready both jdbc api(connector j and ojdbc14.jar).
step3: keep ready driver class name of both jdbc api with url.

Database

In oracle

Table Name Student
 Name                                                    Type
 ----------------------------------------- ---------------------------
 ROLL                                               NUMBER(5)
 SNAME                                            VARCHAR2(20)
 COURSE                                          VARCHAR2(20)

Note: don't insert data in oracle database...bcz we will copy here data of mysql database

In mysql

Table Name Student
 Name                                                    Type
 ----------------------------------------- ---------------------------
 ROLL                                               INT(5)
 SNAME                                            VARCHAR(20)
 COURSE                                          VARCHAR(20)

Note:Insert some values in this table mandatoryy...
GS Blue Funky Casual Shoes





now almost we are ready to write code to copy data from one databse to another database. i am using my eclipse IDE to wirte this code...

                                                     Sample Code:

Thursday, 10 September 2015

Introduction of java



What is java?
Nice question....Actually we all know that java is a object oriented multithreded simple and secure programming language. It is used to develop standalone desktop application, web application and Mobile based software. For all theese purpose java is catageriozed into three parts for maintainance or enhancement puropse. To knowing three catagoeries, ffirst we need to know some important points of java. So, now we move to our question that is What is java? here java is not only programming, It is also a plateform. So we can call JAVA is a programming suit.





Why Java?
So we know that there are many programming language in picture then why JAVA. Right Question, why we use java when many other popular language there in market or software industry like C, C++ and more. let's see what happend when we use these programming language language. Actually C and C++ is used to develop stand alone application. t can be only executed in current operating system where it developed can not be executed from remote system via network call. Java programming is specially designed to develop Internet bassed application.

Defination of java.
Defination means that define and explains any product. Java has many feature that make it popular. so let's see the Defination of JAVA. Java is very Simple, high-level, Secured, Multi-threaded, Plateform independent,, oblect-oriented programming language. It was developed by games gosling in Sun microsystem in 1991. first release was officially published in 23rd jan 1996.
It is decendent of C and C++ programming language. its syntax is similar like to C and C++, But it ommits many features that make C, C++complex, confusing and unsecured. So that in java there is no place of Pointers, Multiple inheritance, Structure, Union, Operator overloading and many more.

These are the starting points when we start java learning......
we will continue in next post that starts with Java Features and Java Buzz words.
Thank you (Sunny kumar)

Saturday, 29 August 2015

enum concept