Search Java Tutorials

Custom Search

What You Will Want to Complete This Tutorial?

You must have at least 1st and 2nd pre-requirements to start the tute. Other requirements will require for last chapters only. These all are free to use and download!
  1. Java Development Kit Standard Edition (JDK / J2SE) Any Version(www.java.com)
  2. Any Text Editor (Note Pad quite enough or get Notepad++ from (http://notepad-plus.sourceforge.net)
  3. Java Run Time Environment (JRE) Any Version(www.java.com)
  4. Java Enterprise Edition (J2EE) for advanced developing (For last few chapters)(www.java.com)
  5. Java Wireless Toolkit for Mobile Application Development (For Mobile Application Development Chapters) (www.java.com)
  6. Tomcat Web Server to run Servlets. (www.tomcat.apache.org/)
Your operating system may be any version of Windows.
What will you learn (As a summary)?
  1. How to build console and windowed applications using Java
  2. How to build web page elements with Java Applets
  3. How to build Database Programs with Java
  4. How to build enterprise applications with Beans
  5. How to add Email functions to Java programs
  6. How to program smart devices (Phone, PDA etc…) with Java

How to create Objects in Java?

An object is an instantiation of a class, or one tangible example of a class. To create an object as an instantiation of a class, you can use following syntax:

Syntax: = new ();
Ex: Employee security = new Employee();

When you create an object, the source class is copied into memory and it referred by your object name. Therefore, you can make as much as objects using the same class. Computer will make copies of same class over and over again.

Sample Program:
Case: This program needs two classes; ‘Computer’ class which we will use to create an object named ‘myComputer’. ‘ComputerUser’ class which use the object to access ‘Computer’ class.

First create “Computer.java” which is the source of object.

public class Computer
{
public static void ComputerName()
{
System.out.println("Dual Core");
}
}


Then create “ComputerUser.java” which create the object and use it.

public class ComputerUser
{
public static void main(String[] args)
{
Computer myComputer = new Computer();
myComputer.ComputerName();
}
}


This is the output:


Tip: Objects have a state (also known as member variables, fields, data) and certain behavior (also known as operations, methods, procedures, functions).

Tip: A class represents a blueprint that defines the variables and the methods common to all objects of a certain kind.

Tip: Objects communicate by sending a message or a request to another object to do a particular task. It is usually a call to a method of another object.

No comments: