Java Basics
#1

Java Basics

Contents
Hello World Program Statements Explained
Java Program Structure in General
Java Classes and Static Methods
Data Types, Variables and Constants
Java Comments and Documents
Control Flow
Reading from Keyboard
Command Line Arguments Processing
Summary and References
Hello World
// HelloWorld.java: Hello World program
import java.lang.*;
class HelloWorld
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
Hello World: Java and C
// HelloWorld.java: Hello World program
import java.lang.*;
class HelloWorld
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}
Program Processing
Compilation
# javac HelloWorld.java
results in HelloWorld.class

Execution
# java HelloWorld
Hello World
Closer Look at - Hello World
The class has one method – main()
public static void main(String args[])
System.out.println(“Hello World”)
Command line input arguments are passed in the String array args[]
e.g java HelloWorld John Jane
args[0] – John args[1] – Jane
Closer Look at - Hello World
import java.lang.*;
Java allows grouping of related classes into a package.
It allows different companies can develop different packages, may even have same class and method names, but they differ by package name:
ibm.mathlib.*
microsoft.mathlib.*
Helps in managing name clash problems.
Think of this package as library.
“import” statement somewhat serves similar purpose as C’s #include
Java imports java.lang.* by default
So, You don't need to import java.lang.*
That means, you can invoke services of java’s “lang” package classes/entities, you don’t need to use fully qualified names.
We used System.out.println() instead of
java.lang. System.out.println()
public static void main(String args[])
public: The keyword “public” is an access specifier that declares the main method as unprotected.
static: It says this method belongs to the entire class and NOT a part of any objects of class. The main must always be declared static since the interpreter users this before any objects are created.
void: The type modifier that states that main does not return any value.
More Java: Classes and static methods
// SquareRoot.java: compute square root of number
import java.lang.Math;
class SquareRoot
{
public static void main(String args [])
{
double x = 4;
double y;
y = Math.sqrt(x);
System.out.println("y= "+y);
}
}

Basic Data Types
Types
boolean either true or false
char 16 bit Unicode 1.1
byte 8-bit integer (signed)
short 16-bit integer (signed)
int 32-bit integer (signed)
long 64-bit integer (singed)
float 32-bit floating point (IEEE 754-1985)
double 64-bit floating point (IEEE 754-1985)
String (class for manipulating strings)
Java uses Unicode to represent characters internally
Variables
Local Variables are declared within the block of code
Variable has a type preceding the name
Initial value is set by initialization expressions.
type variableName = initialValue;
e.g. int x = 1;
Variables can be defined just before their usage (unlike C)
e.g., for( int i = 0; i < 10; i++)
Constants
Constants are similar to variables except that they hold a fixed value. They are also called “READ” only variables.
Constants are declared with the reserved word “final”.
final int MAX_LENGTH = 420;
final double PI = 3.1428;
By convention upper case letters are used for defining constants.
Declaring Constants - example
class CircleArea
{
public static void main(String args[])
{
final double PI = 3.1428;
double radius = 5.5; // in cms
double area;
area = PI * radius * radius;
System.out.println("Circle Radius = "+radius+" Area="+area);
}
}
Comments
English text scattered through the code are comments
JAVA supports 3 types of comments
/* */ - Usually used from multi-line comments
// - Used for single line comments
/** */ - Documentation comments
Javadoc
Effort to make Java self-documenting
True OOP style, encapsulate documentation within code Smile
Comments beginning with /** and ending with */ can be extracted and turned into html documentation
Control Flow
Control Flow Statements in JAVA
while loop
for loop
do-while loop
if-else statement
switch statement
JAVA does not support a goto statement
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: who is jane in, java basics seminar, java basics, mooney rivlin constants acetal, comments on how to,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Privacy-Preserving Updates to Anonymous and Confidential Databases - JAVA project uploader 3 2,181 23-12-2012, 07:35 PM
Last Post: mr.patil1234
  Microprocessor Microcontroller and Programming Basics seminar addict 1 2,245 03-12-2012, 12:57 PM
Last Post: seminar details
  Java™: The Complete Reference, Seventh Edition project uploader 0 1,051 09-06-2012, 05:07 PM
Last Post: project uploader
  An Ontology-Supported Web Focused-Crawler for Java Programs project uploader 0 1,166 08-06-2012, 11:31 AM
Last Post: project uploader
  Building a Java chat server seminar details 0 1,333 07-06-2012, 12:07 PM
Last Post: seminar details
  Line Following Basics seminar details 0 777 06-06-2012, 03:16 PM
Last Post: seminar details
  Understanding the Java ClassLoader seminar paper 0 855 15-03-2012, 02:37 PM
Last Post: seminar paper
  Object Oriented Programming with Java seminar paper 0 846 12-03-2012, 03:40 PM
Last Post: seminar paper
  The basics of a firewall seminar paper 0 716 09-03-2012, 01:46 PM
Last Post: seminar paper
  Eclipse and Java seminar paper 0 1,185 24-02-2012, 04:51 PM
Last Post: seminar paper

Forum Jump: