1By Shaharyar Khanshaharyar.khan555@gmail.com
 JAVA is a object oriented programming language with abuilt-in application programming interface (API) and alsohave suppo...
 Appeared in: 1995 Designed By: James Gosling and Sun MicroSystems Developer: Oracle Corporation Stable release: Java ...
 Java compiler: Transform Java programs into Java byte code Java byte code: Intermediate representation for Java program...
 The .class files generated by compiler are not executablebinaries , So JAVA combine compilation and interpretation Inst...
 The Java Runtime Environment (JRE) is animplementation of the JVM (Java Virtual Machine)that actually executes our java ...
 Java programs execution speed improved significantly withthe introduction of Just-In-Time complilation 1997/1998 the ad...
 Everyone who want to work with JAVA should need toknow about all Editions provided by JAVA Mainly , JAVA provide these ...
 J2se build under the umbrella of JAVA , which provide allcore features provided by other programming languages.• Java Ba...
• Input Output• Collections• Interfaces and polymorphism• Inheritence• Exceptions• Threads• Reflection• GUIs and Event Han...
 Conventions:• Classes• Keywords• Variables• Methods• Constants11 Terms:• Instance Variables and Class varaibales• Refer...
 These are some popular IDEs which are available for java• Eclipse• NetBeans• BlueJ• JCreator• intelliJ IDEA• Borland JBu...
Lets Start discussion on J2se13
 Primitives (Exactly Same as in c#)14Type Contains Default Size Rangeboolean true or false false 1 bit NAchar Unicode cha...
 Access Specifiers (A minor difference from c# )• public• protected• default (no specifier)• private15 Situation   public...
16
 Example code for Access Specifiers public String publicObj; private int privateObj; protected String protectedObj; S...
18abstract continue for new switchassert***default goto*package synchronizedboolean do if private thisbreak double impleme...
19
20}
21
22In last slide , We have seen this linepackage com.deltasoft.testpackage;Same as declaring namespace in .netClasses sho...
23
24 I/O StreamsByte Streams: handle I/O of raw binary data.Character Streams: handle I/O of character data, automaticallyh...
25import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class CopyCharacters {public stati...
26These are core interfaces through which all datastructres are inherited.
27InterfacesHash tableImplementationsResizablearrayImplementationsTreeImplementationsLinked listImplementationsHash table+...
28 General-purpose implementations are the most commonlyused implementations, designed for everyday use. Special-purpose...
29 Wrapper implementations are used in combination withother types of implementations, often the general-purposeones, to ...
30import java.util.*; //All collection classes are present in java.util packagepublic class CollectionTest {public static ...
31Only difference is extends keyword. We just replace “: “ with“extends”.Remaining things and concept are almost same raht...
32Here is some difference in java and .net.In .net , we can only override those methods which aredeclared with vritual key...
33Difference occurs while implementing In .netclass InterfaceImplementer :IMyInterface In JAVAclass InterfaceImplementer...
34 Same like .net , JAVA does’t support multiple inheritence butsupports multiple childs to be inherit.class TradingSyste...
35 Exceptions concept and syntax are exactly same in JAVAand .nettry{//code block}catch(Exception ex){//code block}In jav...
36JAVA supports Reported and unreported exceptionhandling
37ClassNotFoundException,AclNotFoundException,ActivationException,AlreadyBoundException,ApplicationException,AWTException,...
38 Thread is a very vast topic even thousands of books have written onthis topic Here We are not going to discuss about ...
39Class Demo{static void Main( string[] args){Launcher la = new Launcher();Thread firstThread = new Thread(new ThreadStart...
40 In JAVA , We have two ways to create a ThreadBy implementing Runnable interfaceORBy extending Thread classWhen We impl...
41
42class NewThread extends Thread {NewThread() {// Create a new, second threadsuper("Demo Thread");System.out.println("Chil...
43class ExtendThread {public static void main(String args[]) {new NewThread();// create a new threadtry {for(int i = 5; i ...
44 Reflection and Serialization is also a very importantfeatures provided by JAVA There purpose and implementations are ...
45 We have looked into some core things that arecompulsory to start work with JAVA programming. Now , after interpreting...
46
Upcoming SlideShare
Loading in …5
×

What is Java Technology (An introduction with comparision of .net coding)

919 views

Published on

A introductory slides for those who want to learn and know some basics of Java.Also for those persons who want to compare coding difference between Java and .net

Published in: Education, Technology
  • Be the first to comment

What is Java Technology (An introduction with comparision of .net coding)

  1. 1. 1By Shaharyar Khanshaharyar.khan555@gmail.com
  2. 2.  JAVA is a object oriented programming language with abuilt-in application programming interface (API) and alsohave support to handle graphics user interfaces and caterevery programming challenge Syntax of Java is inspired by C and C++ It’s more Platform Independent It has a vast library of predefined objects and operations Java manages the memory allocation and de-allocation forcreating new objects. The program does not have directaccess to the memory. The so-called garbage collector deletesautomatically object to which no active pointer exists2
  3. 3.  Appeared in: 1995 Designed By: James Gosling and Sun MicroSystems Developer: Oracle Corporation Stable release: Java Standard Edition 7 Update 5 (1.7.5) (June12, 2012; some days ago) Major Implementations: OpenJDK , SunJDK , OracleJDK Influenced by: Basically C and C++ Influenced: C# , Groovy ,J#, ada 2005 , Beanshell etc Operating System: Cross-platform License: GNU (General public license), JAVAcommunity process Extensions: .java , .class , .jar3
  4. 4.  Java compiler: Transform Java programs into Java byte code Java byte code: Intermediate representation for Java programs Java interpreter: Read programs written in Java byte code andexecute them Java virtual machine: Runtime system that provides variousservices to running programs Java programming environment: Set of libraries that provideservices such as GUI, data structures etc. Java enabled browsers: Browsers that include a JVM + ability toload programs from remote hosts4
  5. 5.  The .class files generated by compiler are not executablebinaries , So JAVA combine compilation and interpretation Instead , They contain “byte-codes” to be executed by JVM This Approach provides Platform Independence and greatersecurity.5
  6. 6.  The Java Runtime Environment (JRE) is animplementation of the JVM (Java Virtual Machine)that actually executes our java programs. Java Runtime Environment contains JVM, class libraries,and other supporting files. It does not contain anydevelopment tools such as compiler, debugger, etc. Actually JVM runs the program, and it uses the classlibraries, and other supporting files provided in JRE. Ifyou want to run any java program, you need to have JREinstalled in the system6
  7. 7.  Java programs execution speed improved significantly withthe introduction of Just-In-Time complilation 1997/1998 the addition of language features supporting better codeanalysis (such as inner classes, StringBuffer class, optionalassertions, etc.), and optimizations in the JVM itself Some platforms offer direct hardware support for Java, thereare microcontrollers that can run Java in hardware instead ofa software Java Virtual Machine.7
  8. 8.  Everyone who want to work with JAVA should need toknow about all Editions provided by JAVA Mainly , JAVA provide these editions JAVA Standard Edition a.k.a J2SE JAVA Enterprise Edition a.k.a J2EE JAVA Micro Edition a.k.a J2MELet’s have a look on all of these 8•Micro Edition(ME)•Standard Edition(SE)•EnterpriseEdition (EE)
  9. 9.  J2se build under the umbrella of JAVA , which provide allcore features provided by other programming languages.• Java Basics• Classes and Objects• Utilities and Wrappers• Text Processing• Graphics Programming• Geometry• Graphics• Sequence Control• Packages9
  10. 10. • Input Output• Collections• Interfaces and polymorphism• Inheritence• Exceptions• Threads• Reflection• GUIs and Event Handling• Inner and Adapter ClassesAnd Many more ……..10
  11. 11.  Conventions:• Classes• Keywords• Variables• Methods• Constants11 Terms:• Instance Variables and Class varaibales• Reference Variables and Objects1. test t; //only Ref2. new test(); //only obj available for GC3. test t1 = new test(); //Properly reffered object
  12. 12.  These are some popular IDEs which are available for java• Eclipse• NetBeans• BlueJ• JCreator• intelliJ IDEA• Borland JBuilder• Dr. JAVA12
  13. 13. Lets Start discussion on J2se13
  14. 14.  Primitives (Exactly Same as in c#)14Type Contains Default Size Rangeboolean true or false false 1 bit NAchar Unicode characterunsignedu0000 16 bits or2 bytes0 to 216-1 oru0000 to uFFFFbyte Signed integer 0 8 bit or1 byte-27to 27-1 or-128 to 127short Signed integer 0 16 bit or2 bytes-215to 215-1 or-32768 to 32767int Signed integer 0 32 bit or4 bytes-231to 231-1 or-2147483648 to2147483647long Signed integer 0 64 bit or8 bytes-263to 263-1 or-9223372036854775808 to9223372036854775807float IEEE 754 floating pointsingle-precision0.0f 32 bit or4 bytes�1.4E-45 to3.4028235E+38�double IEEE 754 floating pointdouble-precision0.0 64 bit or8 bytes�439E-324 to1.7976931348623157E+�308
  15. 15.  Access Specifiers (A minor difference from c# )• public• protected• default (no specifier)• private15 Situation   public   protected   default   private  Accessible toclass from samepackage? yes yes yes no Accessible toclass fromdifferentpackage? yes no, unless it isa subclass no no
  16. 16. 16
  17. 17.  Example code for Access Specifiers public String publicObj; private int privateObj; protected String protectedObj; String defaultObj; //DefaultSame as for methods public void publicMethod(); private void privateMethod(); protected void protectedMethod(); void defaultMethod(); //Default17
  18. 18. 18abstract continue for new switchassert***default goto*package synchronizedboolean do if private thisbreak double implements protected throwbyte else import public throwscase enum****instanceof return transientcatch extends int short trychar final interface static voidclass finally long strictfp**volatileconst*float native super while*not used**  added in 1.2***  added in 1.4****  added in 5.0IMPORTANT:We can’t suggest a variablename same as any keyword ofjava like int catch; (it is wrongand it will generate an error)
  19. 19. 19
  20. 20. 20}
  21. 21. 21
  22. 22. 22In last slide , We have seen this linepackage com.deltasoft.testpackage;Same as declaring namespace in .netClasses should build in packages so we can separate the codeand keep code cleanAt the end JVM can generate a jar file which contain allpackages in compiled form.
  23. 23. 23
  24. 24. 24 I/O StreamsByte Streams: handle I/O of raw binary data.Character Streams: handle I/O of character data, automaticallyhandling translation to and from the local character set.Buffered Streams: optimize input and output by reducing thenumber of calls to the native API.(both input, output as wellas reader, writers)I/O from the Command Line: describes the Standard Streamsand the Console object.(ex: InputStreamReader)Data Streams: handle binary I/O of primitive data type andString values.Object Streams: handle binary I/O of objects.Basically forserialization
  25. 25. 25import java.io.FileReader;import java.io.FileWriter;import java.io.IOException;public class CopyCharacters {public static void main(String[] args) throws IOException {FileReader inputStream = null;FileWriter outputStream = null;try {inputStream = new FileReader(“Myfile.txt");outputStream = new FileWriter("characteroutput.txt");int c;while ((c = inputStream.read()) != -1){outputStream.write(c);}} finally {if (inputStream != null) {inputStream.close();}if (outputStream != null){outputStream.close();}}}}
  26. 26. 26These are core interfaces through which all datastructres are inherited.
  27. 27. 27InterfacesHash tableImplementationsResizablearrayImplementationsTreeImplementationsLinked listImplementationsHash table+ LinkedlistImplementationsSet HashSet   TreeSet  LinkedHashSetList   ArrayList   LinkedList  Queue          Map HashMap   TreeMap  LinkedHashMap
  28. 28. 28 General-purpose implementations are the most commonlyused implementations, designed for everyday use. Special-purpose implementations are designed for use inspecial situations and display nonstandard performancecharacteristics, usage restrictions, or behavior.(Type Safe) Concurrent implementations are designed to support highconcurrency, typically at the expense of single-threadedperformance. These implementations are part of thejava.util.concurrent package.(also blocking/non blocking ,concurrent etc)
  29. 29. 29 Wrapper implementations are used in combination withother types of implementations, often the general-purposeones, to provide added or restricted functionality.(We cansay extended functionality of General PurposeImplementations) Convenience implementations are mini-implementations,typically made available via static factory methods, thatprovide convenient, efficient alternatives to general-purposeimplementations for special collections (for example,singleton sets). Abstract implementations are skeletal implementations thatfacilitate the construction of custom implementations (forpersistence or high performance)
  30. 30. 30import java.util.*; //All collection classes are present in java.util packagepublic class CollectionTest {public static void main(String [] args) {System.out.println( "Collection Example!n" );int size;HashSet collection = new HashSet ();String str1 = "Yellow", str2 = "White", str3 = "Green", str4 = "Blue";Iterator iterator;collection.add(str1);collection.add(str2);collection.add(str3);collection.add(str4);System.out.print("Collection data: ");iterator = collection.iterator();while (iterator.hasNext()){System.out.print(iterator.next() + " ");}size = collection.size();if (collection.isEmpty()){System.out.println("Collection is empty");} else{System.out.println( "Collection size: " + size);}}}
  31. 31. 31Only difference is extends keyword. We just replace “: “ with“extends”.Remaining things and concept are almost same rahter than one or twothings which will be discuss in next slides.
  32. 32. 32Here is some difference in java and .net.In .net , we can only override those methods which aredeclared with vritual keywordButIn java , for our child classes all methods are available foroverridding (of parent) and we haven’t need to specify anykeyword to tell JVM that I will override this method.Only those methods , which are declared final are not available for overriding to childclasses.
  33. 33. 33Difference occurs while implementing In .netclass InterfaceImplementer :IMyInterface In JAVAclass InterfaceImplementer implements IMyInterfaceSo , the difference is implements keyword.
  34. 34. 34 Same like .net , JAVA does’t support multiple inheritence butsupports multiple childs to be inherit.class TradingSystem{public String getDescription(){return "electronic trading system";}}class DirectMarketAccessSystem extends TradingSystem{public String getDescription(){return "direct market access system";}}class CommodityTradingSystem extends TradingSystem{public String getDescription(){return "Futures trading system";} //This is basically a polymorphism}
  35. 35. 35 Exceptions concept and syntax are exactly same in JAVAand .nettry{//code block}catch(Exception ex){//code block}In java ,Exception is basically derived from class Throwable .Lets see thehierarchy of Exceptions.
  36. 36. 36JAVA supports Reported and unreported exceptionhandling
  37. 37. 37ClassNotFoundException,AclNotFoundException,ActivationException,AlreadyBoundException,ApplicationException,AWTException,BackingStoreException,BadAttributeValueExpException,BadBinaryOpValueExpException,BadLocationException,BadStringOperationException,BrokenBarrierException,CertificateException,DatatypeConfigurationException,DestroyFailedException,ExecutionException,ExpandVetoException,FontFormatException,GeneralSecurityException,NullPointerException,IllegalAccessException,ArrayIndexOutOfBoundException,IllegalArgumentException,TypeMisMatchException,InvalidApplicationException,InvalidMidiDataException,
  38. 38. 38 Thread is a very vast topic even thousands of books have written onthis topic Here We are not going to discuss about what is Thread but only wewill see what are the major differences in implementation andsyntax of Threads between .net and JAVA In .net We create Threads in this wayclass Launcher{void Coundown() {lock(this) {for(int i=4;i>=0;i--) {Console.WriteLine("{0}seconds to start",i);}Console.WriteLine("GO!!!!!");}}}
  39. 39. 39Class Demo{static void Main( string[] args){Launcher la = new Launcher();Thread firstThread = new Thread(new ThreadStart(la.Coundown));Thread secondThread =new Thread(new ThreadStart(la.Coundown));Thread thirdThread = new Thread(new ThreadStart(la.Coundown));firstThread.Start();secondThread.Start();thirdThread.Start();}}
  40. 40. 40 In JAVA , We have two ways to create a ThreadBy implementing Runnable interfaceORBy extending Thread classWhen We implement a interface , Then We have to create a Threadobject in that classWhen we extend our class from a Thread , Then we have to createobject of our own class.Let’s take a look in examples
  41. 41. 41
  42. 42. 42class NewThread extends Thread {NewThread() {// Create a new, second threadsuper("Demo Thread");System.out.println("Child thread: " + this);start(); // Start the thread} // This is the entry point for the second thread.public void run() {try {for(int i = 5; i > 0; i--) {System.out.println("Child Thread: " + i);// Let the thread sleep for awhile.Thread.sleep(500);}} catch (InterruptedException e) {System.out.println("Child interrupted.");} System.out.println("Exiting child thread.");}}
  43. 43. 43class ExtendThread {public static void main(String args[]) {new NewThread();// create a new threadtry {for(int i = 5; i > 0; i--) {System.out.println("Main Thread: " + i);Thread.sleep(1000);}} catch (InterruptedException e) {System.out.println("Main thread interrupted.");}System.out.println("Main thread exiting.");}}
  44. 44. 44 Reflection and Serialization is also a very importantfeatures provided by JAVA There purpose and implementations are same as in c# Serialization provide us Data persistence through outthe network Reflection is use for reverse engineering
  45. 45. 45 We have looked into some core things that arecompulsory to start work with JAVA programming. Now , after interpreting these things anyone can easilyexplore JAVA features
  46. 46. 46

×