12 Dec 2015 & 13 Dec 2015. Core Java Syllabus
12 Dec 2015 & 13 Dec 2015. Core Java Syllabus
1. Introduction
2. Data Types
3. Control Structures
4. Arrays
5. OOPS
6. Class & Objects
7. Inheritance
8. Package
9. Exception Handling
10.Multi Thread
11.Collection Framework
12.Reflection API
13.Java.io
Abbreviations:
o JRE Java Run Time Environment
o JVM Java Virtual Machine
o SDK Software Development Kit
o JDK Java Development Kit
Java Features:
o Architecture Neutral
o Platform Independent
Installing Java:
o We must set the class path and path to get development environment.
Right click on computer
Select Properties Advanced system settings
Click on environment variables
Click on new
Variable name Class path
Find where is program files Java JDK lib
Variable value Set path
Class Sample
{
public static void main (String args[])
{
System.out.println (HI This is First program);
}
}
Output:
HI This is First program.
Class Addition
{
public static void main (String args [])
{
Int value1 = Integer.parseInt (args [0]);
//Wrapper classes
Int value2 = Integer.parseInt (args [1]);
System.out.println (Sum of two numbers: +
(value1+value2));
System.out.println (Array size is: +args.length);
}
}
Output:
Java addition 10 20
Sum of two numbers: 30
Array size is: 2
Java Data Types:
o Integer Group Byte, Short, Int, Long (#Default data type in Integer Group is
INT).
o Float Group Float, Double (#Default data type in Float Group is Double).
o Character Group Char
o Boolean Group Boolean
Bytes Group
Data Type Memory Wrapper Class
Byte 1 Byte. ParseByte (String)
Short 2 Short. ParseShort (String)
Int 4 Integer. ParseInt (String)
Long 8 Long. ParseLong (String)
Class ByteDemo
{
public static void main (String args[])
{
byte num1 = 5;
byte num2 = 1;
System.out.println (Value: + num1);
byte result = num1 + num2; // This is the error
}
}
Output:
Error
Type Casting
o Explicit
o Implicit
Class ByteDemo
{
public static void main (String args[])
{
byte num1 = 5;
byte num2 = 1;
int result = num1 + num2;
byte result1 = (byte) (num1 + num2);
System.out.println (Result: + result);
System.out.println (Result1: + result1);
}
}
Output:
Result: 6
Result1: 6
o If we declare byte num=129 (out of range), it gives compile time error.
o Java is a Strong Types Language.
Float Group
Data Type Memory Wrapper Class
Float 4 Float. ParseFloat (String)
Double 8 Double. ParseDouble
(String)
Class FloatDemo
{
public static void main (String args [])
{
Float num = 123.45; // This is the error
System.out.println (num = + num);
}
}
Output:
Error
Class FloatDemo
{
public static void main (String args [])
{
Float num = 123.45f;
System.out.println (num = + num);
}
}
Output:
Num = 123.45
Char Group
Data Type Memory It has no Wrapper Class
Char 2 String.CharAt(0)
Class CharDemo
{
public static void main (String args [])
{
Char ch = 65;
Char ch1 = 140041;
System.out.println (ch = + ch);
System.out.println (ch1 = +ch1);
}
}
Output:
Ch = A
Ch1 = A
Boolean Group
Data Type Memory It has no Wrapper Class
Boolean - Boolean.parseBoolean(Stri
ng)
o Java follows dynamic loading i.e. whatever we declare static, those methods
are copied into RAM, other than static are in hard disc. Thats why it is a
popular and useful in every application.
19 Dec 2015.
Class ABC
{
public static void main (String args[])
{
System.out.println (Welcome);
}
}
Output:
Welcome
Control Structures
Unconditional
Conditional Break;
Continue;
Goto;
Decision Iterative
If While
Switch For
Dowhile
Class Big2
{
public static void main (String args[])
{
Int value1 = Integer.parseInt (args[0]);
Int value2 = Integer.parseInt (args[1]);
If (value1 > value2)
System.out.println (value1 + is greater number)
else
System.out.println (value2 + is greater number)
}
}
Output:
Javac Big2 10 20
20 is greater number
o Local Variables These are declared inside method, and if we want to use
them they must be first initialized.
o Instance variable These are declared outside method inside class, we can
access them only through objects.
Switch Case:
o Drawbacks with Switch case
Only comparison condition
We need to break statement
This is applicable only for int data type (or) char type.
After java 1.8 we can use this for strings.
If we have comparison operator and have multiple condition we use switch or else
ladder if:
Class Numberword
{
public static void main (String args[])
{
Int num = Integer.parseInt (args[0]);
Switch (number)
{
Case1:
System.out.println (One);
Break;
Case2:
System.out.println (Two);
Break;
Case3:
System.out.println (Three);
Break;
Default:
System.out.println (Invalid Input);
}
}
}
Output:
Javac Big2 1
One
Class WhileDemo
{
public static void main (String args[])
{
Int I = 1;
While (i<=5)
{
System.out.println (Hello);
I++;
}
}
}
Output:
Hello
Hello
Hello
Hello
Hello
Write a java program to display a Hello message 5 times.
Class ForDemo
{
public static void main (String args[])
{
For(int I = 1 ; i<=5; i++)
{
System.out.println (Hello);
}
}
}
Output:
Hello
Hello
Hello
Hello
Hello
-----------------------------------------------------------------------------------------------
---------------------------------
Class ForDemo
{
public static void main (String args[])
{
For(int I = 1 ; ; i++)
{
System.out.println (Hello);
If(I > 5)
{
Break;
System.out.println(i);
}
}
}
}
Output:
Hello
Hello
Hello
Hello
Hello
20 Dec 2015.
Scanner Predefined class
o How to know path of the package?
C:\Program Files\Java\jre1.8.0_66\lib\rt.jar\java\
.jar files contains set of classes
Package This is the area that contains all pre-defined classes.
o Default package in java java.lang
Write a java program that should accept and display student details
Import java.util.scanner;
Class Student
{
public static void main (String args [])
{
Scanner scan = new Scanner(System.in);
System.out.println (Enter hall ticket no: );
Int htno = scan.nextInt();
System.out.println (Enter name: );
String name = scan.next();
System.out.println (Enter Branch: );
String Branch = scan.next();