Your SlideShare is downloading. ×
  • Like
  • Save
Java Basic day-1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Java Basic day-1

  • 392 views
Published

 

Published in Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
392
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Nibble MATRIX Summer Training First day.Environment SettingSelect Start -> Computer -> System Properties -> Advanced system settings ->Advanced-> environment variable-> system variable ->pathVariable name= PathVariable value= ; C:Program FilesJavajdk1.6.0_02bin;.Ok and OKSelect
  • 2. Java:java is an object oriented, internet programming languge .Its main feature is1-plateform independent on machine2- securitythere are two tools which is for compliling and running java programsjavac - it is compiler which converst java source code to byte code ie.class file. This bytecode is standard for all platforms, machines or operating systems.java - this is interpreter. this interprets the .class file based on a particular platform andexcutes them.e jvm -> java virtual machine comes into play. jvm for windows will bedifferent from jvm for solarais or linux . but all the jvm take the same byte code andexecutes them in that platform.Source code -> javac ->Universal byte codeUniversal byte ->jvm/java -> execute them on a particular machine.Syntex Of Defining Class:Class Identifier{Member definition}
  • 3. /// First Pgm:-public class Add {void Addition(int a ,int b){int c=a+b;System.out.println("Sum of 2 number="+c);}public static void main(String[] args) {Add obj=new Add();obj.Addition(10, 20);}}Steps to//Run java pgm// javac Add.javaJava AddNaming Convension in Java:Class: 1st letter of each world of class is capitalexample: Welcome , ArrayIndexOutOfBoundExceptionMethod: ist letter of each word except first world is capitalExample:- nextInt() , nextLine()
  • 4. Keywords:-Keywords are reserved identifiers that are predefined in the language and cannotbe used to denote other entities. All the keywords are in lowercase, and incorrectusage results in compilation errors.Identifiers :-In Java an identifier is composed of a sequence of characters, where each character can beeither a letter, a digit, a connecting punctuation (such as underscore _), or any currency symbol(such as $, ¢, ¥, or £). Identifiers can be used to denote classes, methods,variables, and labelsExamples of Legal Identifiers:number, Number, sum_$, bingo, $$_100,Examples of Illegal Identifiers:48chevy, all@hands, grand-sum
  • 5. Lifetime of Variables:- is, the time a variable is accessible during execution, itsdetermined by the context in which it is declaredThere are context of variable-Instance variables :- members of a class and created for each object of the classStatic variables :- also members of a class, but not created for any object of the class and,therefore, belong only to the classLocal variables :- declared in methods and in blocks and created for each execution of themethod or blockDefault Values :-Data Type Default Value Default data typeboolean falsechar u0000Integer (byte, short, int, long) 0L for long, 0 for others Intand can be specified by long byappending the suffix (L or l)Floating-point (float, double) 0.0F or 0.0D double but it can be explicitlydesignated by appending the suffixD (or d) to the valueReference types null
  • 6. type casting - to convert one cast to another castimplicit type casting : auto - lower to higherExample: byte b = 100;int a = b; - validexplicit type casting: user - higher to lower/ String to any.int a = 200;byte b = a; - error , need to explicit type castingbyte b = (byte)a;Exmple:public class Test {void disp(){int a = 300;byte b = (byte)a;System.out.println("value of b="+b);}public static void main(String[] args) {Test obj=new Test();obj.disp();}}Ans= value of b=44data types in java -Data Bytebyte 1short 2int 4long 8float 4double 8char 2boolean true / false
  • 7. String to inti- int a = Integer.parseInt(aa[0]);ii- int a = Integer.valueOf(aa[0]).intValue();String to floati- float a = Float.parseFloat(aa[0]);ii- float a = Float.valueOf(aa[0]).floatValue();String to doublei- double a = Double.parseDouble(aa[0]);ii- double a = Double.valueOf(aa[0]).doubleValue();String to longi- long a = Long.parseLong(aa[0]);ii- long a = Long.valueOf(aa[0]).longValue();Object creation in C++int a; - var declareClassname objname ;ex -C1 o; - default or no argument passing Constructor calling.in javaClassname objname = new ClassConstructor();ex -C1 o = new C1(); - default or no argument passing Constructorcalling.working with objects in javaObject var - before memory allocationClassName objname;ex -C1 o; - o is a kind of object var
  • 8. Instance var - after memory allocationobjname = new ClassConstructor();ex -o = new C1(); - now o is is a kind of instance var.a = 10; - now a is a initialize varint a = 100; - declare + initializeC1 o = new C1(); - object + instanceRef object var - when one object hold the ref of another objectC1 o = new C1();C1 n = o; - n hold the ref of o object.new - operator , it is for -* call the Constructor* allocate memory for Object* return ref of class for Object.C1 o = new C1();o.disp(); - C1 class disp.