homecode zoneQuick Codedownloadssubmit codeabout usfeedbackscontact ussitemap
 
Concepts
Constant Varibles & Data Types
Operators
Pro - Languages
C/C++
Java
Visual basic
asp
vb.net 2003/2005
asp.net
Quick Code
SUBMIT CODE
Mail List
LINKS
LINK TO US
Submit LINK
 
ProgrammerGuide.net - Java Concepts.
Home » Java Zone » Concepts

Java Concepts

The best way to learn a new language is to write a few simple example programs and execute them. We begins with a very simple program that prints a line of text as output.

class SampleOne
   {
       public static void main(String args[])
       {
               System.out.print(“Java is better than C++.”)
       }
   }

Class Declaration

The first line
 

class SampleOne
 
Declare a class, Which is an object-oriented construct. As stated earlier, Java is an true Object-oriented language and therefore, everything must be placed inside a class. class is a keyword and declares that a new class definition follows. SampleOne is a Java identifier that specify the name of the class to be defined.

Opening Brace

Every class definition in java begin with an opening brace " { " and with an matching closing brace " } ", appearing in the last line of example. This is similar to C++ class construct.

The Main Line

The third line
 

public static void main(String args[])
 
defines a method name main. Conceptually, this is similar to the main() function in C/C++. Every Java application must include the main() method. This is the starting point for the interpreter to begin the execution for program. A java application can have any numbers of classes but only one of them must include a main method to initiate the execution.

The line contains a number of keywords, public, static, and void.

public The keyword public is an access specifies that declares the main method as unprotected and therefore making it accessible to all other classes. This is similar to the C++ public modifier
   
static Next appears the keyword static, which declares this method as one that belongs to the entire class and not a part of any objects of the class. The main must always be declared as static since the interpreter uses this method before any objects are created.
   
void The type modifier void states that the main method does not return any value.

The Output Line

The only executable statement in program is

System.out.print(“Java is better than C++.”)

This is similar to the printf() statement in C or cout<< construct of C++. Since Java is an Object Oriented language, every method must be part of an object. The println method is a member of the out object, which is a static data member of system class. This line prints the string.

« Previous 1 2 3 4 Next »

Viewers: 15
Visitors:127291
Last Updated on:Sunday, January 17, 2010
Home | About us | Feedback | Contact us | Sitemap
Copyright © 2008 ProgrammerGuide.net. All rights reserved.
This site is best viewed in IE 6.0, Firefox 1.5 and above with screen resolution of 1024 X 768.