JAVA Moja……..

tarasj:

nice one am starting to do some animation in java

Originally posted on The Light is Still on horizon.. let it come..:

i was just practicing my java graphics skill………. (really amateur skills)…..Just done this…….

1

It’ll create an Applet with a CUBE drawn on it……..  Its fun……. :)

View original

Posted in ..BASIC..

Do you know what is access specifier

As i always do let me again start with a good example. Access specifier is a level of permission you have to use someone’s belongings and the level of permission you give to someone.Think what it would be like if you try to drive someone’s private car parked in road.But you can so easily ride a car which belongs to your dad.So with this example you must have made something about the access specifier.

access specifier

access specifier


Access specifier are used to control the visibility of a variable or method.It defines when a method or variable is visible to another class.It’s mainly used for Encapsulation,which is concern with hiding the data in a class and making this class available only through the method.IT minimizes the accidental change of values. There are 4 types of access specifier: 1.pubic 2.protected 3.default 4.private lets see all of them in more detail.

public:

If the class and the things we find inside the class be it a data variables or the methods is accessible to everyone.”Think it as an air in atmosphere which belongs to everyone”. Use the public access specifier if you want to make the variable or methods or the class available to every class we will make.It’s not safe to use public for all the class because making it public means the outside class will have free access to our class and make some unwanted alteration.we don’t want our secure key to be pubic right. example:
public class NameDisplay
{
public String name;
public void display()
{
System.out.println(name);
}
}
class PublicDemo
{
public static void main(String[] args)
{
NameDisplay one=new NameDisplay();
one.name=”Tara”;
one.display();
}
}
Note: save the program as NameDisplay.java and compile it.
Run the PublicDemo as java PublicDemo Since the class NameDisplay is public so the class PublicDemo is able to access the NameDisplay class. also the NameDisplay has a public data variable name so the variable is being possible to be changed from the different class PublicDemo. Normally when we design a class make data variable as Private so that only the method inside the class can access it.Make the method as public.

protected:

“It’s just like a son using the car of his father.Father will use the car also allow anybody from his family to use it”. It means if a class has a protected methods and fields than those methods and fields are accessible only to that class and the class derive from that class,ie the subclasses.
example:
class NameDisplay
{ protected String name;
public void display()
{ System.out.println(name);
}
}
class PublicDemo extends NameDisplay
{
public static void main(String[] args)
{ NameDisplay one=new NameDisplay();
one.name=”Biswajit”;
one.display();
}
}
——-Description—— so the class NameDisplay has a data variable called name and its declared as protected means these variable can be used within the class NameDisplay and any class other classes that extend this class i.e inherits the NameDisplay class.Here we made the class PublicDemo and its a subclass of nameDisplay so that is why its able to access the name variable of the Namedisplay class which does not belong to it.

Default(no specifier)/Package:

when none of the access level is set,then it is of default type that’s why its named so.It is also known as package access specifier. In these access specifier the methods and fields will be accessible from inside the same package but not from the any where else. The default access specifier is useful when number of classes can be kept inside a same package and make the sharing among them more easily.
example:
class NameDisplay //default class
{ String name=”ankur”;
public void display()
{
System.out.println(name);
}
}
class PublicDemo
{
public static void main(String[] args)
{ NameDisplay one=new NameDisplay();
one.display();
}
}

Private:

“Its like your wife or husband who always belongs to you.You don’t really want to share it”. A private method and fields can be accessed within a same class to which the method and fields belong. The methods and fields are not accessible to other classes not even to the subclasses.It is the access specifier which has the high degree of data hiding and protection.
example:
private class PrivateDemo
{ private string name; public void setter(string name)
{
this.name=name;
}
public String getter()
{
return name;
}
}
// so i don’t think there is something you can do with this class since its private it cant be used in any other classes.Normally we don’t make a class private but we do make the class attribute as private. so my final words i hope it was helpful to you all .Please do comment and comment and try to correct me if i am missing somewhere thanks….

Posted in ..BASIC..

this keyword in java

I was always wondering about the use of this keyword in java. Normally what you will find when browse through some website is . this keyword can be used in any methods to refer to the current object.But what the heck does it really mean. let us see the condition when we normally make the use of this keyword.

 class Demo
       {
        int a,b;
        public void display(int a,int b)
         {
          this.a=a;
          this.b=b;
         }
      }

So why do we have to use the this keyword here.
-At first we all have to know this rules we can’t have two variables with the same name within the same scope or inside the enclosing scopes.
-We have violated this rule in this example we have a local variables which name is same as the instance variable a and b.

so what happens when we violate this rule

So if we violate something like this than what really happens is the instance variable gets hidden. see the example code again if we write something like
a=athan what does it really mean we are assigning the
values that is being passed to the method to the same variable.The compile gets confused since have the same name .So we need to tell the compiler that this value has to be assigned to the instance variable of the current class since it has the same name as the
local variable .

What can be the next solution

The simple solution can be eliminating the use of same variable names inside the same scope but some programmer believes it as a good practice.

Posted in ..BASIC.. | Tagged

how to make a video without any camera or any device

One day i was wondering is it possible to make a video of whatever i do on my laptop screen without using any camera.I was just searching in Google and found something i was looking for .Yea there is one open source application call “camstudio” which we can use to track anything we do in our laptop or pc screen and make a video in .avi format.Its so cool guys .just make a video of what you are doing in.

cam studio to make video without camera

cam studio look

this is the sample video i made using this application,The quality of the video is ok fine enough.

It can be a best application to make a video tutorial ,so you want to help your friend showing him each and every step .Then you must try this out.

Guys this is link to download this application http://camstudio.org/

 

Posted in internet earning | Tagged , , , , , | 2 Comments

how to play snake in youtube

do you know you can play a snake game in youtube one of the most popular video site.so let me tell you how ,sorry for the one who have a fast internet browsing speed it may not work for you.If you have a slow internet than you must have come through the screen where youtube keeps on buffering your video. Notice carefully you will see something moving round and round while its buffering so if you press any arrow key like left,right,top or down than automatically you can see the blinkers moving like a snake ….. you will have one dot anywhere in the screen you just have to follow that…

youtube

so have a fun in youtube if you have a slow internet connection…

Posted in social-network | Tagged ,

facebook new style photo viewer lightbox

Facebook has changed the way to display the pictures of you and your friends. Now it shows your picture come in the left side and the comment box appear just to the right of picture

Facebook picture view

so do you like it or not lets share..

The feature is known as lightbox features and its not being released yet .It is said that it will take some weeks to reach among all the users however some users have got to taste it.

For those who have not got to see the lightbox features see the pictures above this is how it looks like.

Posted in social-network | Tagged | 4 Comments

how to make Rectangle in JFrame in java

here is the simple java code to showing how to make a rectangle in JFrame in java.

import javax.swing.JFrame;
import java.awt.Graphics;
import java.awt.Color;

class DrawRectangle extends JFrame
{
public DrawRectangle()
{
//to  Set JFrame title
 super("Draw A Rectangle In JFrame");

 //Set default close operation for JFrame
 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 //Set JFrame size
 setSize(500,500);

 //Make JFrame visible
 setVisible(true);
}

public void paint(Graphics g)
{
 super.paint(g);

 //draw rectangle outline
 g.drawRect(50,50,300,100);

 //set color to Green
 g.setColor(Color.GREEN);

 //fill rectangle with GREEN color
 g.fillRect(50,50,300,100);
}

public static void main(String[]args)
{
 DrawRectangle rect=new DrawRectangle();
}
}

The code is ready to be used just compile it and execute:

The output will come something like this.

 

Posted in ..BASIC.. | Tagged ,

how to make a simple animation in java

Friends animation in java is no that hard ,try this to learn the basics of animation..

import javax.swing.*;
import java.awt.*;
public class Animation
 {
   int x=0;
   int y=0;
       public static void main(String[] args)
       {
        Animation gui=new Animation();
       gui.play();
     }
public void play()
   {
           JFrame frame=new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            DrawPanel draw=new DrawPanel();
            frame.getContentPane().add(draw);
             frame.setSize(500,500);
              frame.setVisibility(true);
             for(int i=0;i<150;i++)
              {
                 x++;
                 y++;
                 draw.repaint();  //tells the panel to redraw itself so we can see the circle in new location
              try{
               Thread.sleep(25);
                  }catch(Exception e)
                  {}
         }
     }

class DrawPanel extends JPanel{
     public void paintComponent(Graphics g)
       {
        g.setColor(Color.WHITE);
        g.fillRect(0,0,this.getWidth(),this.getHeight());
      g.setColor(Color.GREEN);
     g.fillOval(x,y,50,50);
}
simply compile and execute to see the simple animation in java

 

Posted in ..BASIC.. | 2 Comments

simple java program

I think you all are clear about how to start with java programming with the post i have given early so now here i will try to show to show you how to write the java program to the most basic .

simple Program:

Class Example1
   {
      public static void main(String args[])
        {
          System.out.println(“hellow world”);
         }
    }

after  writing these code in any wordprocessor like notepad save it in the extension .java but the name of the file must be the name of the class given in the program her we have Example1 in the program

then compile the program using the command prompt ,in the command prompt you must go to the path where you have saved the program just written then to compile the program type javac filename here for these program it will be like javac Example1.java so if there is no errors in the program then a new file will be made with the same name as the file we have just made but with the .class extension we call it as the class file .now we will use that class file to execute the program ,so to run the simple java program we have written type  java followed by classfilename for these program it will be like java Example1.These is how we normally run the simple java program

so what do you think isn’t it easy to kick off the java program.so if all the java begineers if you still having problem to understand the basics please leave the comment and let me know the problem you have

Posted in ..BASIC.. | Tagged ,

how to start java

Now you are ready to start learning java. It will be easier for us to understand java more easily if we have some programming experience in c and c++ but don’t worry though you don’t really don’t know what c and c++ is i will tech you the java. Before i begin my lession let me briefly state out what else you need to be installed on your sytem to start java.

1.Download the java SDK(software development kit )also download JRE(java runtime environment ).most of the case JRE comes in-built with SDK ,after downloading the SDK install it.you can visit to http://java.sun.com/products/archive/j2se/1.4.2_02

2.make the following setting:

  • go to start
  • right click on computer and select properties then go to Advance System Setting
  • click on environment variable
  • click on New on the top and in the Variable name field-write JAVA_PATH
  • in the variable values field-we have to write the path where you have installed the java normally its like:C:\Program Files (x86)\Java\jdk1.6.0\bin
  • click on ok now you are ready to go .
     to check if its done or not open the command prompt and type JAVA then there should be no error message and some information about java appears than you have successfully done it.
3.Start writing your code in Notepad or any text editor.
Posted in ..BASIC..