Anda di halaman 1dari 9

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

Software (Collection of programs)

System s/w Application s/w

Operating systems Languages Packages


Drivers C MS Office
Translators C++ Eclipse
Java Photoshop

o In C methods are called as Functions,


o In Java methods are called as Methods.
o Method is a member of Class.

o Variable stores one value


o Array stores multiple values.
o Class stores multiple values but also different data types.
o Class = Structure + Related functions.

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

Write a program to display a message

Class Sample
{
public static void main (String args[])
{
System.out.println (HI This is First program);
}
}

Output:
HI This is First program.

o Class name must start with Capital letters


o String and System are said to be class names
o Public and Static are Access Modifiers
If we declare as public, any one access.
Always declare main method as public, if we declare as private, JVM
cannot identify.
o Method name must begin with small letter.
o Default representation of java program is string.
o String is a class, not a primitive data type

Write a Java Program to add two numbers:

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)

Write a program for ByteDemo (error case)

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

Write a program for ByteDemo

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)

Write a program for Float Demo (error case)

Class FloatDemo
{
public static void main (String args [])
{
Float num = 123.45; // This is the error
System.out.println (num = + num);
}
}

Output:
Error

Write a program for Float Demo

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)

o Java Follows UNICODE standards (65536 symbols).


o Unicode represents hexadecimal number system. (140000 to 14FFFF)
Write a program for Char Demo

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

o Public and Static are Access Modifiers


o Void is a return value
o Main is a Method
o In Java default data type is String
o Args[] are arguments which is an array type
o System is a class
o Out is an object declared in a class called system
o Println is a method declared in print stream.
o Overloading We cannot change return type and Method Name
o C is a structured programming language
o Java is an Object oriented programming Language
o JVM is a platform dependent.
Control Structures

Control Structures

Unconditional
Conditional Break;
Continue;
Goto;

Decision Iterative
If While
Switch For
Dowhile

Write a program to find the biggest of two numbers

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

Write a program to display a Hello message 5 times.

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

This is also Valid syntax:


While (Condition);
For( ; ; );

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();

System.out.println(htno + +name+ +Branch);


}
}
Output:
1
Dinesh
Andhra
1 Dinesh Andhra

Anda mungkin juga menyukai