CORE JAVA.pdf - JAVA Means DURGA SOFT 1|Page JAVA Means...

This preview shows page 1 out of 368 pages.

You've reached the end of this preview.

Unformatted text preview: JAVA Means DURGA SOFT 1|Page JAVA Means DURGA SOFT 2|Page JAVA Means DURGA SOFT Index Page 1) Introduction 1-18 a. Flow control statements 19 b. Variables 32 c. Methods 41 d. Constructors 57 2) Oops 74 a. Inheritance b. Polymorphism 97 c. Garbage Collector 112 d. Abstraction 114 e. Main method 121 f. Encapsulation 3) Packages 126-137 4) Interfaces 138-148 5) String mnipultions 149-161 6) Wrapper classes 162-169 7) Java.io 170-175 8) Exception handling 176-199 9) Multi Threading 200 – 217 10) Nested classes 218 – 228 11) Enumeration 229- 231 12) Collections & generics 232–279 13) Networking 280 – 285 14) Java.awt 286-311 15) Swings 312-318 16) i18n 319-333 17) Arrays 334-336 18) Java interview questions 337-341 19) Core java classroom schedule 357 3|Page JAVA Means DURGA SOFT JAVA introduction:Author Vendor Project name Type Initial Name Present Name Extensions Initial version Present version Operating System Implementation Lang Symbol Objective SUN Slogan/Motto : : : : : : : : : : : : : : : James Gosling Sun Micro System(which has since merged into Oracle Corporation) Green Project open source & free software OAK language java .java & .class & .jar jdk 1.0 (java development kit) java 8 2014 multi Operating System c, cpp…… coffee cup with saucer To develop web applications Stanford Universally Network WORA(write once run anywhere) Importance of core java:According to the SUN 3 billion devices run on the java language only. 1) Java is used to develop Desktop Applications such as MediaPlayer,Antivirus etc. 2) Java is Used to Develop Web Applications such as sravyajobs.com, irctc.co.in etc. 3) Java is Used to Develop Enterprise Application such as Banking applications. 4) Java is Used to Develop Mobile Applications. 5) Java is Used to Develop Embedded System. 6) Java is Used to Develop SmartCards. 7) Java is Used to Develop Robotics. 8) Java is used to Develop Games ………………………..etc. Technologies Depends on Core java:Hadoop Magic Adv java Selenium structs Android hibernate Core java Cloud computing webservices Salesforse spring 4|Page MDM ADF JAVA Means DURGA SOFT Learning process:Corejava Adv java JDBC Servlets Hibernate structs jsp Web services,tools(ant,maven,svn…..) Spring Parts of the java:As per the sun micro systemstandard the java language is divided into three parts 1) J2SE/JSE(JAVA 2 STANDARD EDITION) 2) J2EE/JEE(JAVA 2 ENTERPRISE EDITION) 3) J2ME/JME(JAVA 2 MICRO EDITION) Java keywords:Data Types byte short int long float double char boolean (8) Flow-Control:if else switch case default break for while do continue (10) 5|Page method-level:void return (2) Object-level:new this super instanceof (4) source-file: class extends interface implements package import (6) Exception handling:- try catch finally throw throws (5) 1.5 version:enum assert (2) unused:goto const (2) Modifiers:public private protected abstract final static strictfp native transient volatile synchronized (11) JAVA Means DURGA SOFT JAVA VERSIONS:VERSION Java Alpha & beta JDK 1.0 JDK1.1 J2SE 1.2 J2SE 1.3 J2SE 1.4 J2SE 1.5 JAVA SE 6 JAVA SE 7 JAVA SE 8 : : : : : : : : : : Differences:- C-lang 1) Author: Dennis Ritchie 2) Implementation languages: BCPL, B… YEAR 1995 1996 1997 1998 2000 2002 2004 2006 2011 2014 applications use #include statement. Ex:- #include<stdio.h> 7) To print some statements into output console use “printf” function. Printf(“hi ratan ”); 5) The header files contain predefined functions. Ex:- printf,scanf….. 6) To make available predefined support into our 5) The header files contains predefined functions. Ex:- cout,cin…. 8)extensions used :-.c ,.obj , .h 3) In C lang program executionstarts frommain methodcalled by Operating system. 4) In c-lang the predefined support is available in the form of header files Ex:- Stdio.h, Conio.h 4)cpp language the predefined is maintained in the form of header files. Ex:- iostream.h Cpp-lang 6) To make available predefined support into our application use #include statement. Ex:- #include<iostream> 7) To print the statements use “cout” function. Cout<<”hi ratan”; 1)Author : Bjarne Stroustrup 2) implementation languages are c ,ada,ALGOL68….. 8)extensions used :-.cpp ,.h 3) program execution starts from main method called by operating system. Java -lang 1) Author : James Gosling 6|Page JAVA Means DURGA SOFT 2) implementation languages are C,CPP,ObjectiveC……. 3) program execution starts from main method called by JVM(java virtual machile). 4) In java predefined support available in the form of packages. Ex: -java.lang, java.io [*] mean all 5) The packages contains predefined classes and class contains predefined funtions. Ex:- String,System 6) To make available predefined support into our application use import statement. Ex:- import java.lang.*; 7)To print the statements we have to use System.out.println(“hi ratan”); 8)extensions used : .java, .class CPP –sample application:#include<iostream.h> C –sample application:Void main() #include<stdio.h> {Cout<<“hello sravyainfotech”; } Void main() { Printf(“hello rattaiah”); } Java sample application:Import java.lang.System; Import java.lang.String; Class Test { Public static void main (String args) { System.out.println (“welcome to java language”); } } c-language:c-language Dennis Ritchie void main() (execution startsfrom main ) headerfiles stdio.h,conio.h printf(“ratan”); (used to print the output) functions printf,scanf….. cpp-language:cpp-language Bjarne Stroustrup void main() headerfiles iostream.h cout<<”ratan”; (used to print the output) functions cout,cin…. 7|Page (execution startsfrom main) JAVA Means DURGA SOFT java-language:java-language james gosling public static void main(String args) (execution startsfrom main) packages java.lang System.out.println(“ratan”); (used to print the output) classes & interfaces System,String…….. methods & variables length(),charAt(),concat()… JAVA Features:1. 5. 9. 1. Simple 2. Object Oriented 3. Platform Independent4.Architectural Neutral Portable 6. Robust 7.Secure 8.Dynamic Distributed 10.Multithread 11.Interpretive 12.High Performance Simple:Java is a simple programming language because: Java technology has eliminated all the difficult and confusion oriented concepts like pointers, multiple inheritance in the java language. The c,cpp syntaxes easy to understand and easy to write. Java maintains C and CPP syntax mainly hence java is simple language. Java tech takes less time to compile and execute the program. 2. Object Oriented:Java is object oriented technology because to represent total data in the form of object. By using object reference we are calling all the methods, variables which is present in that class. Class data Class Test {logics } Test t=new Test(); t 3. Platform Independent : Compile the Java program on one OS (operating system)that compiled file can execute in any OS(operating system) is called Platform Independent Nature. 8|Page JAVA Means DURGA SOFT The java is platform independent language. The java applications allow its applications compilation one operating system that compiled (.class) files can be executed in any operating system. exe Test.class Test.java JVM JVM JVM JVM Javac windows exe exe exe source file compilation JVM understandable file linux macos solaris output console 4. Architectural Neutral:Java tech applications compiled in one Architecture (hardware----RAM, Hard Disk) and that Compiled program runs on any hardware architecture(hardware) is called Architectural Neutral. 5. Portable:In Java tech the applications are compiled and executed in any OS(operating system) and any Architecture(hardware) hence we can say java is a portable language. 6. Robust:Any technology if it is good at two main areas it is said to be ROBUST 1. Exception Handling 2. Memory Allocation JAVA is Robust because JAVA is having very good predefined Exception Handling mechanism whenever we are getting exception we are having meaning full information. JAVA is having very good memory management system that is Dynamic Memory (at runtime the memory is allocated) Allocation which allocates and deallocates memory for objects at runtime. 7. Secure: To provide implicit security Java provide one component inside JVM called Security Manager. To provide explicit security for the Java applications we are having very good predefined library in the form of java.Security.package. 9|Page JAVA Means DURGA SOFT 8. Dynamic:Java is dynamic technology it follows dynamic memory allocation(at runtime the memory is allocated) and dynamic loading to perform the operations. 9. Distributed:By using JAVA technology we are preparing standalone applications and Distributed applications. Standalone applications are java applications it doesn’t need client server architecture. web applications are java applications it need client server architecture. Distributed applications are the applications the project code is distributed in multiple number of jvm’s. 10. Multithreaded: Thread is a light weight process and a small task in large program. If any tech allows executing single thread at a time such type of technologies is called single threaded technology. If any technology allows creating and executing more than one thread called as multithreaded technology called JAVA. 11. Interpretive:JAVA tech is both Interpretive and Completive by using Interpretator we are converting source code into byte code and the interpretator is a part of JVM. 12. High Performance:If any technology having features like Robust, Security, Platform Independent, Dynamic and so on then that technology is high performance. Install the software and set the path :1) Download the software. 2) Install the software in your machine. 3) Set the environmental variable. Download the software from internet based on your operating system. The software is different from 32-bit operating and 64-bit operating system. To download the software open the fallowing web site. 10 | P a g e JAVA Means DURGA SOFT for 32-bit operating system please click on Windows x86 :- 32- bit operating system for 64-bit operating system please click on Windows x64 :- 64-bit operating system After installing the software the java folder is available in the fallowing location Local Disk c: ------program Files--------java----jdk(java development kit),jre(java runtime environment) To check whether the java is installed in your system or not go to the command prompt. To open the command prompt Start ----------run------open: cmd-----ok Command prompt is opened. In the command prompt type :javac ‘javac’ is not recognized is an internal or external command, operable program or batch file. Whenever we are getting above information at that moment the java is installed but the java is not working properly. C:/>javac Whenever we are typing javac command on the command prompt 1) Operating system will pickup javac command search it in the internal operating system calls. The javac not available in the internal command list . 2) Then operating system goes to environmental variables and check is there any path is sets or not. up to now we are not setting any path. So operating system don’t know anything about javac command Because of this reason we are getting error message. Hence we have to environmental variables. The main aim of the setting environmental variable is to make available the fallowing commands javac,java,javap (softwares) to the operating system. To set the environmental variable:My Computer (right click on that) ---->properties----->Advanced--->Environment Variables----> User variables--new---->variable name : Variable value: -------ok------ok Path C:\programfiles\java\jdk1.6.0_11\bin;.; Now the java is working good in your system. open the command prompt to check once C:>javac---------now list of commands will be displayed Steps to Design a First Application:Step-1:Step-2:Step-3:Step-4:Step-5:- 11 | P a g e Select Editor. Write the application. save the application. Compilation Process. Execution process. JAVA Means DURGA SOFT Step1:- Select Editor Editor is a tool or software it will provide very good environment to develop java application. Ex :- Notepad, Notepad++,edit Plus…..etc Note :- Do thepractical’s of core java only by usingEdit Plus software. DE:- ( Integrated development Environment ) IDE is providing very good environment to develop the application and it is real-timestandard but don’t use IDE to develop core java applications. Editor vs. IDE:If we are using IDE to develop core java application then 75% work is done by IDE like 1) Automatic compilation. 2) Automatic import. 3) It shows all the methods of classes. 4) Automatically generate try catch blocks and throws (Exception handling) 5) It is showing the information about how to fix the bug………………………etc And remaining 25% work is down by developer If we are using EditPlus software to develop application then 100% work done by user only. Step 2:- Write a program. Write the java program based on the java API(Application Programming Interface) rule and regulations . Open editplus --->file ---->new ----->click on java (it display sample java pplication ) Java is a case Sensitive Language so while writing the program you must take care about the case (Alphabet symbols). Example application:Import java.lang.System; Import java.lang.String; class Test //class declaration { //class starts public static void main(String args) //program starting point { //main starts System.out.println("hi Ratan"); //printing statement } //main ends }; //class ends class A { }; class B { }; In above example String & System classes are present predefined java.lang package hence must import that package by using import statement. To import the classes into our application we are having two approaches, 1) Import all class of particular package. a. Import java.lang.*; //it is importing all classes of java.lang package. 2) Import required classes 12 | P a g e JAVA Means DURGA SOFT a. Import java.lang.System; b. Import java.lang.String; In above two approaches second approach is best approach because we are importing application required classes. Step3:- save the application. After writing the application must save the application by using (.java) extension. While saving the application must fallow two rules o If the source file contains public class then public class and the name and Source file must be same (publicClassName.java). Otherwise compiler generate error message. o if the source file does not contain public class then save the source file with any name(anyName.java) like A.java , Rtan.java, Anu.java …….etc. Note: - The source file allowed only one public class, if we are trying to declare multiple public classes then compiler generate error message. example 1:- invalid //Ratan.java public class Test {}; class A {}; example 2:- valid //Test.java public class Test {}; class A {}; example 3:- invalid //Test.java public class Test {}; public class A {}; Application location:D: |-->ratan |-->Sravya.java Step-4:- Compilation process. Compile the java application by using javaccommand. Syntax:Javac filename Javac Test.java Process of moveing application saveing location:C:\Users\hp> intial cursor location C:\Users\hp>d: move to local disk D D:\>cd ratan changing directory to ratan D:\ratan>javac Sravya.java compilation process Whenever we are trying to perform compilation compiler perform fallowing actions. Compiler checks the syntax error, if syntax error are there compiler generate error message. If syntax errors are not present then compiler generate .class files. 13 | P a g e JAVA Means DURGA SOFT Note:- in java .class file files generated by compiler at compilation time and .class file generation based on number of classes present in source file. If the source file contains 100 classes after compilation compiler generates 100 .class files The compiler generate .class file and .class file contains byte code instructions it is intermediate code. Process of compiling different files:D: |-->ratan |-->Sravya.java |-->A.java |-->B.java |-->C.java javac A.java one file is compiled(A.java) javac B.java C.java two files are compiled javac *.java all files are compiled Step-5:- Execution process. Run /execute the java application by usingjava command. Syntax:Java class-name Java Test Whenever you are executing particular class file then JVM perform fallowing actions. It wills loads corresponding .class file byte code into memory. If the .class is not available JVM generate error message like “Could not find main class”. After loading .class file byte into memory JVM calling main method to start the execution process. If the main method is not available compiler generate error message like “Main method not found in class A, please define the main method”. Note 1:- compiler is translator it is translating .java file to .class where as JVM is also a translator it istranslating .class file to machine code. Note 2:- compiler understandable file format is .java file but JVM understandable file format is .class Executing all generated .class files:- 14 | P a g e JAVA Means DURGA SOFT D:\ratan>java Test Hi Ratan D:\ratan>java A Error: Main method not found in class A, please define the main method as: public static void main(String args) D:\ratan>java B Error: Main method not found in class B, please define the main method as: public static void main(String args) D:\ratan>java XXX Error: Could not find or load main class XXX Bytecode Java Interpreter on Windows Java Interpreter on Linux Environment of the java programming development:- First program development :- Create/Modify Source Code 15 | P a g e Source Code ... Java Interpreter on Sun Solaris JAVA Means DURGA SOFT Example application : The default package in java is java.lang package it means if we are importing or not by default that package is imported. In below example importing classes are optional. class Test { public static void main(String args) { System.out.println("hi ratan"); } } Example Application:The class contains main method is called Mainclass and java allowes to declare multiple main class in a single source file. class Test1 { public static void main(String args) { System.out.println("Test1 World!"); } } class Test2 { public static void main(String args) { System.out.println("Test2 World!"); } } class Test3 { public static void main(String args) { System.out.println("Test3 World!"); } 16 | P a g e JAVA Means DURGA SOFT } D:\morn11>java Test1 Test1 World! D:\morn11>java Test2 Test2 World! Class Elements:Class Test { 1. variables 2. methods 3. constructors 4. instance blocks 5. static blocks } D:\morn11>java Test3 Test3 World! int a = 10; void add() {business logic } Test() {business logic } {business logic } static {business logic } Java codeing conventions :- Classes: Class name start with upper case letter and every inner word starts with upper case letter. This convention is also known as camel case convension. The class name should be nouns. Ex:- String StringBuffer InputStreamReader ……etc Interfaces : Interface name starts with upper case and every inner word starts with upper case letter. This convension is also known as camel case convension. The class name should be nouns. Ex: Serializable Methods :- Cloneable RandomAccess Method name starts with lower case letter and every inner word starts with upper case letter. This convention is also known as mixed case convention Method name should be verbs. Ex:- post() charAt() toUpperCase() compareToIgnoreCase() Variables: Variable name starts with lower case letter and every inner word starts with upper case letter. This convention is also known as mixed case convention. Ex :- out in pageContext Package : Package name is always must written in lower case letters. Ex :- java.lang java.util java.io …etc Constants: While declaring constants al...
View Full Document

  • Winter '19
  • Santhosh Danalakota

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern