Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
434 views
Core Java by NAGOOR BABU SIR PDF
Uploaded by
suman s
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Core Java by NAGOOR BABU SIR.pdf For Later
Download
Save
Save Core Java by NAGOOR BABU SIR.pdf For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
434 views
Core Java by NAGOOR BABU SIR PDF
Uploaded by
suman s
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Core Java by NAGOOR BABU SIR.pdf For Later
Carousel Previous
Carousel Next
Save
Save Core Java by NAGOOR BABU SIR.pdf For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 462
Search
Fullscreen
CORE JAVA COURSE MATERIAL BY MR.NAGOOR BABU DURGA SOFT sri raghavendra Xerox All software language materials available gars bakery opp:cdac balkampetroad ameerpet Hyderabad cell :9951596199Core java NAGOOR BABU Language Fundamentals Identifiers Reserved words Data types Literals Arrays ‘Types of variables Var arg method Main method Command line arguments 10. Java coding standards Identifier: A name in java program is called identifier. It may be class name, method name, variable name and label name. Example; Sen anewne class Test t ct public static void main(Stringl] args) ima fT ry 2 304 y8 Rules to define java identifier Rule 1: The only allowed characters in java identifiers are: 1) atoz 2) Atoz 3) Otod 4) _ 5) $ Rule 2: If we are using any other character we will get compile time error. Example: 1) Total number-- 2) Totali-—- Rule 3: identifiers are not allowed to starts with digit. ule 4: java identifiers are case sensitive up course java language itself treated as case sensitive language. DURGA SOFTCore java NAGOOR BABU Example: class Test{ int number=10; int Number=20; int NUMBER: int NuMbEr=30; } Rule 5: Ther 15 lengths. Rule 6: We can’t use reserved words as identifiers. Example: int if=1 invalid Rule 7: All predefined java class names and interface names we use as identifiers. Example 1: class Test { public static void main(String{} args) int String=10; System.out.printin(String); y we can differentiate with case. no length limit for java identifiers but it is not recommended to take more than Example 2: class Test { public static void main(String[] args){ int Runnable=10; Even though it is legal to use class names and interface names as identifiers but it is not a good programming practice. Which of the following are valid java identifiers? DURGA SOFTCore java NAGOOR BABU Reserved words: In java some identifiers 1)_$_(valid) 2)CaSh{valid) 3)lava2share valid) 4)all@hands(invatid) 5)123ab¢ (invalid) 6)Totalit (invalid) 7)ine{invalid) 8)integertvalid) are reserved to associate some functionality or meaning such type of reserved identifiers are called reserved words. Diagram: Keywords(50) Used Keywords(48) unused keyword(2 Reserved words for data types: a) 2) 3) 4) 5) 6) 7 8) Reserved words for flow control 1) 2) 3) 4) 5) 6) 7) DURGA SOFT Reserved words(53) Reserved Literals(3) tru > sata i (default value for object reference null [—eoto | const byte short int long float double char booleanCore java NAGOOR BABU 8) while } 9) break 5 10) continue 11) return ) Keywords for modifiers 1) public 2) private 3) protected 4) static 5) final 6) abstract 7) synchronized 8) native 9) strictfp(1.2 version) 10) transient 11) volatile Keywords for exception handling: a) ty 2) catch 3) finally 4) throw 5) throws 6) assert{1.4 version) Class related keywords: 1) class 2) package 3) import 4) extends 5) implements 6) interface Object related keywords: 1) new 2) instanceof 3) super 4) this Void return jord: © Ifa method won't return anything compulsory that method should be declared with the void return type in java but it is optional in C++. a DURGA SOFTCore java NAGOOR BABU 2) void Unused keywords: goto: Create several problems in old languages and hence it is banned in java. Const: Use final instead of this. © By mistake if we are using these keywords in our program we will get compile time error. Reserved literals: 1) true), values for boolean data type. 2) false. 3) null - default value for object reference. Enui * This keyword introduced in 1.5v to define a group of named constants Example: enum Beer { KF, RC, KO, FO; } Note: All reserved words in java contain only lowercase alphabet symbols. New keywords are: ‘Which of the following list contains only java reserved words? 1) final, finally, finalize (invalid)//here finalize is a method in Object class. 2) throw, throws, thrown(invalid)//thrown is not available in java 3) break, continue, return, exit{invalid) //exit is not reserved keyword 4) goto, constant(invalid)//here constant is not reserved keyword 5) byte, short, Integer, long(invalid)//here Integer is a wrapper class 6) extends, implements, imports(invalid)//imports keyword is not available in java 7) finalize, synchronized{invalid)//finalize is a method in Object class 8) instanceof, sizeOf(invalid)//sizeOf is not reserved keyword 9) new, delete(invalid)//delete is not a keyword 10) None of the above(valid) Which of the following are valid java keywords? 1) _public(valid) 2) static(valid) 3) void(valid) 4) main(invalid) 5). String(invalid) 6) args(invalid) DURGA SOFTCore java NAGOOR BABU Data types: Every variable has a type, every expression has a type and all types are strictly define more over every assignment should be checked by the compiler by the type = ‘compatibility hence java language is considered as strongly typed language. > Java Is pure object oriented programming or not? | * Java is not considered as pure object oriented programming language because several ~ cops features (like multiple inheritance, operator overloading) are not supported by Java moreover we are depending on primitive data types which are non objects. Numeric data types char datatypes boolean data types (to represent numbers) (to represent characters} (to represent logical valves) v Integral data types floating point data types (to represent whole (to represent real numbers ‘umbers) >be [short Sint float double Stone. ‘* Except Boolean and char all remaining data types are considered as signed data types because we can represent both “+ve” and”-ve” numbers. Minvalue:-128 Range:-128to 127[-2” to 2’-1] msg x t signbit 26*1425*1424"1423°1+22°1421°1+20"1 O-—-——--(+ve) 6 4*1432*14+16"148"144*142"14142 1 (ve) 4127 ‘© The most significant bit acts as sign bit. “0” means “+ve” number and 1” means "-ve” number. ‘+ “+ve” numbers will be represented directly in the memory whereas “-ve” numbers will be represented in 2's complement form. 6 DURGA SOFTCore java NAGOOR BABU Example: byte b=10; byte b2=130;//C.E:possible loss of precision. byte b=10.5;//C.E:possible loss of precision byte b=true;//C.E:incompatible types byte b="durga";//C.E:incompatible types © byte data type is best suitable if we are handling data in terms of streams either from the file or from the network. short: * The most rarely used data type in java is short. Size: 2 bytes Range: -32768 to 32767(-2** to 2"*-1) Example: short s=130; short s=32768;//C.E:possible loss of precision short s=true;//C.E:incompatible types ‘© Short data type is best suitable for 16 bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type. ‘* This is most commonly used data type in java. Size: 4 bytes Range:-2147483648 to 2147483647 (-2" to 2-1) Example: int i=130; int i=10.5;//C.E:possible loss of precision int i=true;//C.E:incompatible types Jong: © Whenever Example: * To hold the no. Of characters present in a big file int may not enough hence the return type of length() method is long. tong is Not enough to hold big values then we should go for long data type. Jenath();//f isa file Size: 8 bytes Range:-2° to 2°-1 Note; All the above data types (byte, short, int and long) can be used to represent whole numbers. if we want to represent real numbers then we should go for floating point data types. int Datatypes: _ Float double 1) If we want to 5 to 6 decimal places of | 1) If we want to 14 to 15 decimal places | accuracy then we should go for float. of accuracy then we should go for double. 7 DURGA SOFTCore java NAGOOR BABU 2) Sizesd bytes. 2) Size:8 bytes. 3)_ Range:-3.4¢38 to 3.4638, 3)_-1.7e308 to1.7e308. 4) float follows single precision. 4) double follows double precision, _ boolean data type: Size: Not applicable (virtual machine dependent) Range: Not applicable but allowed values are true or false. Which of the following boolean declarations are valid? Example 1: boolean boolean b=True;//C.E:cannot find symbol boolean b="True";//C.E:incompatible types boolean b=0;//C.E:incompatible types Example 2: rue; (3) incompatible types found System.out printin("hello"}; In java we are allowed to use any worldwide alphabets character and java is Unicode based to represent all these characters one byte is not enough compulsory we should go for 2 bytes. Size: 2 bytes Range: 0 to 65535 Example: char ch1=97; char ch2=65536;//C.E:possible loss of precision ‘Summary of java primitive data type: data type size Range Corresponding | Default value Wrapper class Byte Lbyte -27to27-1 Byte 0 7 {-128 to 127) Short 2 bytes 2 toa Short 0 (-32768 to 32767) Int A bytes 2 to Integer 0 (2147483648 to fal 2147483647) Long ___|8bytes 2 to FA Long 9 3 DURGA SOFTCore java NAGOOR BABU Float bytes -3.4e38 to Float 0.0 3.4638 Double B bytes -1.7€308 to Double 0.0 1.7¢308 Boolean Not applicable | Not Boolean false applicable(but | allowed values | true | false) Char 2 bytes ] 0 to 65535 Character | O(represents | blank space) ‘* The default value for the object references is “null”. eral: ‘* Anyconstant value which can be assigned to the variable is called literal. Example: int x: 0 Ls constant vale titer name of variable identifier datatype keyword Integral Literals: For the integral data types (byte, short, int and long) we can specify literal value in the following ways. 1) Decimal literals: Allowed digits are 0 to 9. Example: int x=10; 2) Octal literals: Allowed digits are 0 to 7. Literal value should be prefixed with zero. Example; int x=010; 3) Hexa Decimal literals: The allowed digits are 0 to 9, A to Z. For the extra digits we can use both upper case and lower case characters. This is one of very few areas where java is not case sensitive. Literal value should be prefixed with ox(or)oX. Example: int x=0x10; ‘© These are the only possible ways to specify integral literal. Which of the following are valid declarations? 1) int x=0786;//C.E:integer number too large: 0786(invalid) 2) int x=OxFACE; (valid) 3) int x=Oxbeef;(valid) 4) int x=OxBeer;//C.E:';' expected(invalid) If:int x=OxBeer; 5) int x=Oxabb2cd;(valid) Example: int x=10; int y=010; int z=0x10; System.out.printin(x+"- aye" —"42); //10-—-8-—-16 DURGA SOFTCore java NAGOOR BABU ‘* By default every integral literal is int type but we can specify explicitly as long type by suffixing with small “I” (or) capital “L”. Example: int x=10;(valid) OL; (valid) 0;{valid) int x=101;//C.E:possible loss of precision(invalid) ‘© There is no direct way to specify byte and short literals explicitly. But whenever we are assigning integral literal to the byte variables and its value within the range of byte compiler automatically treats as byte literal. Similarly short literal also. Exampl byte b=10;(valid) byte b=130;//C.E:possible loss of preci short s=32767;(valid) oe 5=32768;//C.E:possible loss of precision(invalid) #loating Point Literals: Floating point literal is by default double type but we can specify explicitly as float type by suffixing with f or F. Example: float f=123.456;//C.E:possible loss of precision(invalid) float f=123.456f;(valid) double d=123.456;(valid) © We can specify explicitly floating point literal as double type by suffixing with d or D. n(invalid) double d=123.4560; ‘* We can specify floating point literai only in decimal form and we can’t specify in octal and hexadecimal forms. Erample: double d=123,456;( valid) double d=0123.456;(valid) double d=0x123.456;//C.E:malformed floating point literal{invalid) Which of the following floating point declarations are valid? y 3.456;//C-E:possible loss of precision\invalid) 2) '3.456D;//C.E:possible loss of precision(invalid) 3) double d=0x123.456;//C.E:malformed floating point literal{invalid) 4) double d=OxFace;(valid) 5) double d=OxBeef(valid) * We can assign integral literal directly to the floating point data types and that integral literal can be specified in octal and Hexa decimal form also. double d=OxBeef; ‘System.out.printin(d);//48879.0 © But we can't assign floating point literal directly to the integral types. 10 DURGA SOFTCore java NAGOOR BABU Example: int x=10.0;//C.E:possible loss of precision ‘© We can specify floating point literal even in exponential form also(significant notation). Example: double d=10e2;//==>10*10%(valid) Sree ee ene ern System.out.printin(d);//1000.0 float f=10e2;//C.E:possible loss of precision(invalid) float f=10e2F;(valid) Boolean literals: The only allowed values for the boolean type are true (or) false where case is, important. Example: 1) boolean b=true;(valid) 2), boolean b=0;//C.E:incompatible types(invalid) 3) boolean b=True;//C.E:cannot find symbol(invalid) 4) boolean b="true";//C.E:incompatible types(invalid) rals: 1) A char literal can be represented as single character within single quotes. Example: 1) char ch='a';(valid) 2) char ch=a://C.E:cannot find symbol(invalid) 3) char ch="a’;//C.E:incompatible typestinvalid) 4) char ch="ab';{/C.E-unclosed character literal(invalid) 2) We can specify a char literal as integral literal which represents Unicode of that character. We can specify that integral literal either in decimal or octal or hexadecimal form but allowed values range is 0 to 65535. Example: 1) char ch=97;(valid) 2). char ch=0xFace; (valid) Char System.out.printin(ch);//? 3) char ch=65536;//C.E: possible loss of precision(invalid) 3) We can represent a char literal by Unicode representation which is nothing but “\uxon’. Example: 1) char chi="\u0061'; System.out.printin(ch1);//a 2) char ch2=\u0062;//C.E:cannot find symbol 1) char ch="\n';//(valid) 2)_ char ch="\"'//C.E:illegal escape character(invalid) Escape Character | Description L - \n New line \t [a ae Horizontal tab \ Carriage return 1 DURGA SOFT "Core java NAGOOR BABU ¥ Form feed yo Back space character j V Single quote Vv Double quote \ Back space ‘Which of the following char declarations are valid? 1) s/C.E:cannot find symbol{invalid) 2) \losed character literal(invalid) 3) 4) 5) char ch="/n';//C.E:unclosed character literal(invalid) 6) none of the above.(valid) ‘String literals: © Any sequence of characters with in double quotes is treated as String literal. haskar";(valid) byte—> shorts int —> long —> float —>double ct Arrays 1) Introduction 2) Array declaration 3) Array construction 4) Array initialization 5) Array declaration, construction, initialization in a single line. 6) length Vs length() method 7) Anonymous arrays 8) Array element assi 9) Array variable assignments. * An array is an indexed collection of fixed number of homogeneous data elements. * The main advantage of arrays is we can represent multiple values with the same name so that readability of the code will be improved. But the main disadvantage of arrays is: ‘* Fixed in size that is once we created an array there is no chance of increasing or decreasing the size based on our requirement that is to use arrays concept compulsory we should know the size in advance which may not possible always. + We can resolve this problem by using collections. Array declarations: 12 DURGA SOFT 12Core java NAGOOR BABU ‘Single dimensional array declaration: Example: int(] 2;//recommended to use because name is clearly separated from the type int (la; int al]; ‘At the time of declaration we can’t specify the size otherwise we will get compile time error. Example: int(] a;//valid int(5) a;//invalid Two ional array declara Example: int(}] a; int [][a; int af}(); | All are valid. int] Ha; int{] af]; int {laf}; ‘Three dimensional array declaration: Example: int OQ a; int (00a; int a0; int{) 00a; int{) a[]{]; | Allare valid. int{) Dall; int{)0) Oa; int{}O) alls int (Jal); int (Mal); Which of the following declarations are valid? 2) int{] a1,b1;//a-1,b-1(valid) 2) int] a2{],b2;//a-2,b-1(valid) 3) int{] []a3,b3;//a-2,b-2(valid) 4) int{] a,[]b;//C.€:
expected{invalid) ‘* If we want to specify the dimension before the variable that rule is applicable only for the 1% variable. Second variable onwards we can’t apply in the same declaration. B DURGA SOFT 13Core java NAGOOR BABU Example: int{} (a,t}b; invalid valid ‘Array construction: Every array in java is an object hence we can create by using new operator. aD int{] a=new int{3]; Diagram: © For every array type corresponding classes are available but these classes are part of Java language and not available to the programmer level. ‘Array Type. I corresponding class name int) tl int()U ____lt double} ID Rule 2: At the time of array creation compulsory we should specify the size otherwise we will get compile time error. Example: int{] a=new int{3};, int{] a=new int{];//C-E:array dimension missing Rule 2: © Its legal to have an array with size zero in java. Example: int[] a-new int(0]; ‘System.out.printin(a.length);//0 Rule 3: © If we are taking array size with -ve int value then we will get runtime exception saying NegativeArraySizetxception. Example: int{] a=new int[-3];//R.€:NegativeArraySizeException Rule 4: ‘© The allowed data types to specify array size are byte, short, char, int. By mistake if we are using any other type we will get compile 4 DURGA SOFT 4
You might also like
GOLD Core Java Durga Sir - Java - Notes - Teachmint
PDF
No ratings yet
GOLD Core Java Durga Sir - Java - Notes - Teachmint
459 pages
Final Project Java 2
PDF
No ratings yet
Final Project Java 2
14 pages
Searchable Core Java Durga Sir - Java - Notes - Teachmint
PDF
No ratings yet
Searchable Core Java Durga Sir - Java - Notes - Teachmint
459 pages
Object Oriented Programming Methodology (CS and IT)
PDF
No ratings yet
Object Oriented Programming Methodology (CS and IT)
2 pages
Org It (TCS-iQMS-166) Python Programming Standards and Guidelines PDF
PDF
No ratings yet
Org It (TCS-iQMS-166) Python Programming Standards and Guidelines PDF
46 pages
Oracle Applications Using Java & JDBC
PDF
No ratings yet
Oracle Applications Using Java & JDBC
82 pages
11.batch Updations
PDF
No ratings yet
11.batch Updations
5 pages
JDBC
PDF
No ratings yet
JDBC
61 pages
Lab - 04 JDBC Connectivity: Connecting Java Program With Oracle DB
PDF
No ratings yet
Lab - 04 JDBC Connectivity: Connecting Java Program With Oracle DB
20 pages
JDBC, Servlet, JSP JAVA
PDF
0% (1)
JDBC, Servlet, JSP JAVA
484 pages
All Notes PDF
PDF
No ratings yet
All Notes PDF
118 pages
1.1 Private Methods in Interfaces PDF
PDF
No ratings yet
1.1 Private Methods in Interfaces PDF
7 pages
Documents Null-Core+Java+Notes Madhu
PDF
No ratings yet
Documents Null-Core+Java+Notes Madhu
108 pages
Adobe Dream Weaver Basics CS4
PDF
No ratings yet
Adobe Dream Weaver Basics CS4
28 pages
CoreJava1 Niraj
PDF
100% (1)
CoreJava1 Niraj
308 pages
Java Interview Questions For 2 Years Experienced
PDF
No ratings yet
Java Interview Questions For 2 Years Experienced
8 pages
Annamalai University
PDF
No ratings yet
Annamalai University
55 pages
OOP - I GTU Study Material Presentations Unit-1 07022022102854PM
PDF
No ratings yet
OOP - I GTU Study Material Presentations Unit-1 07022022102854PM
59 pages
Corejava PDF
PDF
No ratings yet
Corejava PDF
250 pages
Complete Java J2EE
PDF
No ratings yet
Complete Java J2EE
209 pages
Adobe AEM Self Learning Topic
PDF
No ratings yet
Adobe AEM Self Learning Topic
16 pages
Durga Core Java
PDF
50% (2)
Durga Core Java
2 pages
2.client Server Arch
PDF
No ratings yet
2.client Server Arch
14 pages
Java Cheatsheet
PDF
No ratings yet
Java Cheatsheet
29 pages
Niit Java Exam
PDF
No ratings yet
Niit Java Exam
9 pages
Interview Questions On JAVA
PDF
No ratings yet
Interview Questions On JAVA
32 pages
WW Java Cert Guide Java Se11
PDF
No ratings yet
WW Java Cert Guide Java Se11
1 page
Model Question Paper MI0032 PDF
PDF
No ratings yet
Model Question Paper MI0032 PDF
15 pages
La10 - Java Programming - 01
PDF
No ratings yet
La10 - Java Programming - 01
71 pages
ERJEEML100 - JavaProgramming Part 1 PDF
PDF
No ratings yet
ERJEEML100 - JavaProgramming Part 1 PDF
162 pages
Unit 1 Core Java PDF
PDF
No ratings yet
Unit 1 Core Java PDF
270 pages
HTML Notes by Subba Raj Sir PDF
PDF
No ratings yet
HTML Notes by Subba Raj Sir PDF
208 pages
Javascript M TRL
PDF
No ratings yet
Javascript M TRL
186 pages
Lab - Forensic Investigation Using EnCase
PDF
100% (1)
Lab - Forensic Investigation Using EnCase
24 pages
Java Quick Revision
PDF
No ratings yet
Java Quick Revision
7 pages
Language Fundamentals
PDF
100% (1)
Language Fundamentals
2 pages
Java Notebook
PDF
100% (1)
Java Notebook
76 pages
Java Lecture Notes
PDF
No ratings yet
Java Lecture Notes
128 pages
12.30 PM Core Java Notes
PDF
No ratings yet
12.30 PM Core Java Notes
116 pages
Assignments - PR 101 - Basic - Java
PDF
No ratings yet
Assignments - PR 101 - Basic - Java
11 pages
Oops Java
PDF
No ratings yet
Oops Java
126 pages
JDBC 4pm NTAJ414 All Paintbrush
PDF
No ratings yet
JDBC 4pm NTAJ414 All Paintbrush
66 pages
Objective Questions-Java
PDF
No ratings yet
Objective Questions-Java
3 pages
Unit-7: Java Web Frameworks: Spring MVC
PDF
No ratings yet
Unit-7: Java Web Frameworks: Spring MVC
26 pages
Creating Database: Managing Databases in Mysql
PDF
No ratings yet
Creating Database: Managing Databases in Mysql
56 pages
Complete J2EE Notes
PDF
No ratings yet
Complete J2EE Notes
131 pages
SDLC (Software Development Lifecycle) - Is A Systematic Process For Building Software That Ensures The Quality and Correctness of The Software
PDF
No ratings yet
SDLC (Software Development Lifecycle) - Is A Systematic Process For Building Software That Ensures The Quality and Correctness of The Software
36 pages
Easy Java Certification 130 Questions
PDF
No ratings yet
Easy Java Certification 130 Questions
67 pages
Core Java Notes
PDF
No ratings yet
Core Java Notes
13 pages
JAVA-Notes hindi
PDF
No ratings yet
JAVA-Notes hindi
105 pages
Jpa (Java Persistence Api) Cheat Sheet: Transaction Management With Entitymanager
PDF
No ratings yet
Jpa (Java Persistence Api) Cheat Sheet: Transaction Management With Entitymanager
8 pages
Web Application:-A Web Application Is Nothing But A Web Site. A Web Application Can Be Thought of As A Collection of Two Types of Resources 1
PDF
No ratings yet
Web Application:-A Web Application Is Nothing But A Web Site. A Web Application Can Be Thought of As A Collection of Two Types of Resources 1
53 pages
Derived Syntactical Constructs in Java: (Type Here)
PDF
No ratings yet
Derived Syntactical Constructs in Java: (Type Here)
25 pages
Core Java by NAGOOR BABU SIR PDF
PDF
100% (2)
Core Java by NAGOOR BABU SIR PDF
462 pages
Core Java by Nagoor Babu Sir
PDF
100% (1)
Core Java by Nagoor Babu Sir
462 pages
Core Java Book
PDF
No ratings yet
Core Java Book
461 pages
Durga Sir Java Notes
PDF
50% (2)
Durga Sir Java Notes
32 pages
Core Java Book
PDF
No ratings yet
Core Java Book
464 pages
Language Fundamentals
PDF
No ratings yet
Language Fundamentals
56 pages