Core Java: - Create A Java Project
Core Java: - Create A Java Project
Step 3 – Right click on “src” folder and select package and enter any package name
Step 5 – Enter any Class Name and the click Finish(no space should be present in Class name)
FirstClass.java
Main Class.java
obj.Method1();
• Parameterized method
public void Method1(int a,int b,String c)
{
Syso(a+b);
Obj.Method1(10,20,”Hello”);
Int c=a+b;
return c;
Calling
Int d=obj.Method1(10,20);
System.out.println(d);
• Static Method
FirstClass.java file
Calling
To call a static method we don’t have to create a object it can be called directly from class name
FirstClass.StaticMethod();
• Data Conversion
To convert into different data types we can use wrapper class
Int to String
Int i=10;
String.valueOf(i)
String str=”10”;
Integer.vaueOf(str);
Double.vaueOf(str);
Float.valueOf(str);
• Type Casting
Implicit type casting – Compiler automatically converts
Int a=10;
float b=a;
Here float is the bigger data type so complier will automatically converts i.e implicit data type
double d=24.565656565656;
int a=(int)d;
Note: We can cast only same group of data i.e double to int meaning only number not string to number or
vice versa.
strbui.Append(“Welcome”);
System.out.println(strbui); - The output will be appended string i.e ” this is string builderWelcome”;
• Constructor
If we create a method with the same name as Classname then it’s a constructor, the only difference
constructor does not have a return type.
Default Constructor
{
public FirstClass()
{
System.out.println("Constructor");
}
Parameterized Constructor
{
public FirstClass(int a,int b)
{
System.out.println(a);
System.out.println(b);
}
This keyword
If we have to refer the class level variable we can use this keyword
Output:
10
Hello
• Loops
For loop
arr[0]=”hi”;
arr[0]=”hello”;
arr[0]=”java”;
for(int i=0;i<arr.length;i++)
Syso(arr[i])
While loop
Int j=0;
while(j<arr.length)
Syso(arr[i]);
J++;
For-Each loop
for(String s:arr)
{
Syso(s);
• Collections
ArrayList
arrlist.Add(“Hi”);
arrlist.Add(“Bye”);
arrlist.Add(“demo”);
for(String item:arrlist)
Syso(item);
HashTable
Iterate in HashTable
for(Map.Entry<String,String> hs:hst1.entrySet())
{
System.out.println(hs.getKey());
System.out.println(hs.getValue());
}
HashMap is same as HashTable only in HashMap you can store null values