What is Java :
Programming language :
Another programming language using which we can develop applets,
standalone applications, web applications and enterprise applications.
Platform Independent :
A Java program written and compiled on one machine can be
executed on any other machine (irrespective of the operating system)
Object Oriented :
Complies to object oriented programming concepts. Your
program is not object oriented unless you code that way.
Compiled and Interpreted :
The .java file is compiled to a .class file & the
.class file is interpreted to machine code.
Basic Concepts of Java :
What Is a Class?
A
class is a blueprint or prototype from which objects are created. This section
defines a class that models the state and behavior of a real-world object. It
intentionally focuses on the basics, showing how even a simple class can
cleanly model state and behavior.
What Is Inheritance?
Inheritance provides a powerful and natural mechanism for organizing and structuring your software. This section explains how classes inherit state and behavior from their superclasses, and explains how to derive one class from another using the simple syntax provided by the Java programming language.What Is an Interface?
An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. This section defines a simple interface and explains the necessary changes for any class that implements it.What Is a Package?
Java Primitive Datatypes :
Data type
|
Bytes
|
Min Value
|
Max Value
|
Literal Values
|
byte
|
1
|
-27
|
27 – 1
|
123
|
short
|
2
|
-215
|
215 – 1
|
1234
|
int
|
4
|
-231
|
231 – 1
|
12345, 086, 0x675
|
long
|
8
|
-263
|
263 – 1
|
123456
|
float
|
4
|
-
|
-
|
1.0
|
double
|
8
|
-
|
-
|
123.86
|
char
|
2
|
0
|
216 – 1
|
‘a’, ‘\n’
|
boolean
|
-
|
-
|
-
|
true, false
|
Size |
Names |
Signed Range |
Unsigned Range |
8 bits |
Byte |
−128 to +127 |
0 to 255 |
16 bits |
Word, short int |
−32,768 to +32,767 |
0 to 65,535 |
32 bits |
Double Word, long int (win32, win64, 32-bit Linux[1]) |
−2,147,483,648 to +2,147,483,647 |
0 to 4,294,967,295 |
64 bits |
long int (C in 64-bit linux[1]), long long (C), long (Java, the signed integer variant only[2]) |
−9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 |
0 to 18,446,744,073,709,551,615 |
.....................................................................................................................................
17-Aug-2013
Simple Java Program For Swapping two numbers using "this".
public class Swap {
int a=10, b=20;
void swap(int a,int b) //Function for swapping
{
int temp;
temp=a;
this.a=b; //this reference to current object a.
this.b=temp; //this reference to current object b.
}
void display() //Method for displaying
{
System.out.println("a="+a+" "+"b="+b);
}
int a=10, b=20;
void swap(int a,int b) //Function for swapping
{
int temp;
temp=a;
this.a=b; //this reference to current object a.
this.b=temp; //this reference to current object b.
}
void display() //Method for displaying
{
System.out.println("a="+a+" "+"b="+b);
}
public static void main(String[] args)
{
Swap s=new Swap();
s.display();
s.swap(s.a, s.b);
s.display();
}
}
Swap s=new Swap();
s.display();
s.swap(s.a, s.b);
s.display();
}
}
...............................................................................................................................................................................................
18-Aug-2013
Programs for creating and importing our own Packages.
Steps :
//1-Create different packages as "Student" and
"MyDate".
//1.1- code for
creating package for Student.
package
student.com;
import
test.com.MyDate;
public class
Student {
String name,addr;
int id,contact;
MyDate dob;
public Student(int a,String b,String c,int d,MyDate e)
{
id=a;
name=b;
addr=c;
contact=d;
dob=e;
}
public String toString()
{
return("Stud
id="+id+"\nName="+name+"\nAddress="+addr+"\nContact="+contact+"Date
of Birth="+dob);
}
}
//1.1- code for creating
package for MyDate.
package test.com;
public class MyDate {
private int dd,mm,yy;
public MyDate(int x,int y,int z)
{
dd=x;
mm=y;
yy=z;
}
public String toString()
{
return("Date="+dd+"/"+mm+"/"+yy);
}
/*2.-Create one main
program in which above two packages are imported.
2.1- Swaping of
date using array is also implemented in this main program.*/
package main.com;
import test.com.MyDate;
import
student.com.Student;
public class Swap {
Student s1[]={new Student(1,"Abhi","Pune",5,new
MyDate(3,3,3)),new Student(2,"Vikas","Pune",2,new
MyDate(4,4,4))};
MyDate d1[]={new MyDate(1,1,1),new MyDate(2,2,2)};
public void swap(MyDate x[])
{
MyDate temp;
temp=x[0];
x[0]=x[1];
x[1]=temp;
}
void display() //Method
for displaying
{
for(int i=0;i<=1;i++)
{
System.out.println(d1[i]);
}
}
void studdisp()
{
for(int i=0;i<=1;i++)
{
System.out.println(s1[i]);
}
}
public static void main(String[] args) {
Swap s=new Swap();
s.display();
s.swap(s.d1);
s.display();
s.studdisp();
}
}
.............................................................................................................................................
No comments:
Post a Comment