Skip to main content

Posts

Operator Concept in Java

Operator Concept in Java:- It is a special identifier of Java which has defined as a predefined method in java library . It is used to perform a different type of operation using operand. The operand can be defined as a variable, constant, and literals in the program. Object operator +() { } Object operator -() { } we can not redefine operator definition in Java because the operator method is read-only. hence java not support operator overloading concept. Type of Operator:- 1 Unary: -    It will work using a single operand 1.1 Increment:-      It is used to increase the value by one 1.1.1 Pre:-      First Increase value then perform other operations.       ++identifier 1.1.2 Post:-    First perform other operations then increase value.        identifier++ int a=2,b; b=a++;    //b=2,a=3 int a=3,b; b=++a; //4,4 int a=2,b; b = a++ + a++ + a++; #9  ...

Primary Key,Unique and Foreign Key Concept?

Primary Key:- It is used to provide a unique and not null value to a particular column. The primary key must be defined in Table. Primary key will be one in one table and it is eligible for the foreign key to providing referential integrity constraint. Create Table tablename(columnname datatype primary key,...) Create Table tablename(columnname int primary key auto_increment,...) ................................................................................................................................................. Unique:- It is only used to define unique value, unique can be multiple in one table, a single null value will be allowed in unique key. Create Table Tablename(columnname datayype unique) ..................................................................................................................................................... Foreign key:- The primary key of the Master table will be integrated into the child table to provide r...

Array Concept in Java:-

It is a collection of elements of similar and dissimilar data type both.java provide integer array for similar type and Object array then dissimilar type element. Type of Array:- 1.1) Single Dimension Array:- using this array we can store element using rows. base index of single dimension array will be started from 0. Datatype arrayname[] = new datatype[size]; int arr[] = new int[5]; Datatype [] arrayname = new Datatype[size]; int [] arr = new int[5]; Datatype arrayname[] = {value1,value2,value3,...} int arr[] = {1,2,3,4,5} Object arr[] = {"C","CPP",1003,12.34} Program of Split one Array to two different Sub-Array? class Splitarr { public static void main(String args[]) {   System.out.println("array split program"); int arr[]= {2,11,34,56,67,78,89,91,12,11,12}; int size = arr.length; int size1 = size/2;  //5 int size2 = size-size1;  //6 int arr1[] = new int[size1]; int arr2[] = new int[size2]; for(int i=0;i<...

How to take user input in java?

How to take user input in java?:- USER INPUT AND DISPLAY OUTPUT IN JAVA:- We can take input in java using two different ways:- 1.1   using Command Line Input with Command Prompt or Terminal 1.2 using System.in where "in" is the reference variable of InputStream class System.in will provide input handling operation using Three different ways 1.2.1 System.in.read():-  It raises an exception and we can take input only one char at a time, it returns ASCII code hence we never use this for User Input operation. char ch =(char) System.in.read(); Program to take input using System.in.read()? import java.io.*; class UserInput1 {        public static void main(String args[]) throws IOException    {        int a;        System.out.println("enter char");        a=System.in.read();        System.out.println((char)a);    } } 1.2.2  System.in reference...

Dictionary in Python

Dictionary is used to contain data using key=>value pair .Key is used to provide unique identity and value is used to provide storage. dictionary always will be declared by { } student = {'rno':1001,'sname':'manish kumar','branch':'cs'} here rno, same and branch is the key of a dictionary object. the dictionary is immutable object means we can change the value of dictionary using the key. student = {'rno':1001,'sname':'manish kumar','branch':'cs','fees':15000} for k in student:     print("key is "+k+" value is "+str(student[k])) student['sname']='ravi' #del student['sname'] #print(student['sname']) student.update({'sem':'5th'}) print(student)

Create Notepad using Swing:-

Swing Provide Multiple Set of Component to Create Notepad 1 Menu:-  It provides option set to display multiple menus under the menu bar 2 MenuBar:-  It provides a complete strip to contain the menu 3 MenuItem:-  It will be displayed as a list when we click on the particular menu item 4 Textarea:-  It is used to write the multiple contents Menu Item will use the ActionPerformed Event Method to perform the operation Code to Save File:- JFileChooser obj1=null;                     try         {                  if(this.getTitle().toString()=="")         {           obj1= new JFileChooser();           obj1.showSaveDialog(this);           path=obj1.getSelectedFile().getAbsolutePath();           this.setTitle(obj1.getSelectedFi...

Constructor in Java

Constructor in Java:- It is used to initialize the value of dynamic data member of the class. Constructor name and class name both will be same. The constructor has no return type in declaration it will automatically return class type data. The Constructor will be called automatically when we create an Object. When we compile class then Constructor block will be created by default. Class Hello {     Hello()    {   } } Type of Constructor:- 1 Default:- This Constructor will be created by default if we want to initialize any data member of class then we can create default constructor block. 2 Parametrized:- This Constructor contains set of parameters to pass value from the object and contain by parameters. class A {     A(int a,int b)    {    } } A obj = new A(10,20); 3 Copy or Reference Type:- It is similar to parametrized constructor but we can pass the value as a reference t...