Core Java
A) Starting with Core Java:
Java is an Object oriented programs (OOPS) as I have mentioned in the above subjects. Java is a very Robust, Simple and Architecture neutral, i.e. it supports everything we use in programming in C, Abstraction, Encapsulation, Polymorphism, and Inheritance. Although all the programs in Core java are Command line based.
B) To Run a Basic Java Program:
1) We have to write the java codes in a notepad file
2) Save the notepad file with the class name used (class will be studied further) with proper K state i.e. if class dip then file name is “dip” and not “Dip” or other conventions.
3) Extension: dip.java instead of dip.txt.
4) Save the file to the root C:\SDK\jdk\bin>.
5) To Compile any program in java use the follow notations:
* C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip.java Press Enter
* C:\>java dip Press Enter
5) Following piece of code will print "This is a simple Java program." In the command line, to do so we have to write a program as it is:
class dip {
public static void main(String args[]) {
System.out.println("This is a simple Java program.");
}
}
In this program class is the address of the Java file, class include the name of the file carrying the java codes, public static void main is the method (function) of the class i.e. action we want as output. (String args[]) is an array or Storage of the set of codes Encapsulated inside the function, the action System.out.println tell the system to print out the command written inside the Encapsulation, println or print is to print the command onto command line. Here ln is used for new line.
Output:
C) Data Types:
There are many Data Types we have come across the C and C++ programs, similarly in java there are Data types.
1) Simple Data type:
a) Int: All Integer type Variables are Stored inside int data type
b) Char: All Character type Variables are Stored inside char data type.
c) Float: All floating-type number or decimals are Stored inside float data type
d) Boolean: This Variable consists of only “True” or “False”.
2) A Simple program on data type int (pre-defined):
class dip1
{
public static void main(String args[])
{
int a,b,c;
a=3;
b=4;
c=a+b;
System.out.println("Answer is: "+c);
}
}
Save the file name as it is the class name because class name is the address, without or incorrect name will not be detected by JVM and hence it will throw an Error or Exception, i.e. dip1.java
Use same notation:
C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip1.java Press Enter
* C:\>java dip1 Press Enter
Output:
3) Another Simple Program, in this we will take the input from the User (user-defined):
class dip2
{
public static void main(String arg[])
{
System.out.println("Your name is: "+arg[0]);
System.out.println("Your name is: "+arg[1]);
}
}
Use notation:
C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip2.java Press Enter
* C:\>java dip2 Dip Pramanik Press Enter
Output:
Have you seen some difference between the previous program and this one?
Yes, the difference is C:\>java dip2 Dip Pramanik
Dip Pramanik is the Command line argument, it wasn’t pre-defined, it is defined by the User so called User-defined.
4) Write a Program by taking number from the user and adding it:
class dip3
{
public static void main(String arg[])
{
int a,b,c;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=a+b;
System.out.println("Answer is: "+c);
}
}
Here Integer.parseInt takes the command line argument in the form of Integer only
Use notation:
C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip3.java Press Enter
* C:\>java dip3 3 5 Press Enter
Output:
E) Control-Statements:
1) Types of Control statements
a) If-Else condition: If-Else conditions are used when there is a condition weather this or that, its easy to use and we can loop it too with Else-if condition.
b) For loop: To loop or repeat a process “for” loop is used.
c) Switch-Case: This is a User-defined statement, in this statement we ask to enter a command as command line argument to the user. This argument act as a Case, it detects the suitable case from the code and throws the output to the console.
d) While: The logic is While (condition) do this.
e) Do-While: The logic is Do (this) While (Condition).
f) It seems that there is no difference but there is a large difference between while and Do-While.
2) Write a program by using if condition where greater of two numbers.
class dip4
{
public static void main(String arg[])
{
int a,b,c;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
if(a>b)
System.out.println(a+" is Greater");
else
System.out.println(b+" is Greater");
}
}
Use notation:
C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip4.java Press Enter
* C:\>java dip4 3 5 Press Enter
Output:
3) Write a program using For loop.
class dip5
{
public static void main(String arg[])
{
int c;
for(c=1;c<=5;c++)
{
System.out.println(c+"\t Dip Pramanik");
}
}
}
Here \t is used for Tab.
Use notation:
C:\>cd\sdk\jdk\bin Press Enter
* C:\>javac dip5.java Press Enter
* C:\>;java dip5 Press Enter
Output:
-
4) Some Assignment Questions you can try and give me reply using Comments
I will solve it to you tomorrow
a) Write a program to print average of two number
Logic a=1 b=2
c=a+b/2
print c
b) Write a program to swap two value
Logic a=1 b=2
c
c as temporary variable
c=a;
a=b;
b=c;
Output: a=2 b=1
c) Write a program to check area of circle
Logic r=3;
Area of circle 3.14*r2
c=3.14*r*r
print c
d) Write a program using if-else condition
Check if age<=12 print child
Age<=30 print young
Age<=45 print matured
Age>=45 print old
e) Write a program using if-else condition
Check if Ist class, IInd class, pass class, fail class
f) Print odd number 1 to 10 using for loop
Logic Print c(initial value to print 1)
for(c=1;c<=10;c+2)
Print c;
g) Print a table of the given number
Logic defines a,c,b[10];
Double d;
a=integer.parseInt(arg[0]);
For(c=1;c<=10;c++)
{
b[]=c;
}
d=a*b[];
print axb[]=d;
Here double is an integer type and accepts ASCII symbols also.
b[10] is the array of storage 10.
h) Print sum of five given number
Use for loop to accept 5 numbers from user
i) Print a right angle Pascal triangle of
*
* *
* * *
* * * *
* * * * *
Wednesday, August 11, 2010
Monday, June 14, 2010
Starting with JAVA
Java Applications are found everywhere- on mobile phones, Blu-ray disc players, set top boxes, and even in your car(SUV or MUV). Today Java is so famous for its tools and services it gives while developing applications that is found everywhere. Even operating systems have been developed with the help of java, For example- Apple computers 'MAC', Fedora-2, etc. The Global Positioning System(GPS)/Navigation Systems are developed under Java, The 'Packets' in GPRS can be developed using Java socket programming, i will teach you in further Conversations.
Java is Completely Object Oriented ie object depends on its Data and not on the Codes. Other Languages Like C are process oriented ie object depends on its Code and not on Data.
For Execution or Running java, java uses 'Java Virtual Machine'.JVM understands(READ)/interprets ByteCode. ByteCode is a set of instructions which are designed to be executed by the java runtime system ie JVM. ByteCodes are Binary codes and Machines can understand only 0's and 1's ie Binary Code. Therefore java can reach up to machines which other application developing languages can't do.
Java is:
1) Simple
2) Object Oriented
3) Robust
4) Multithreaded
5) Architecture Neutral
6) Interpreted (can be run\access\loaded to any machine, it is not depended on the particular machine, this feature is used in web applications)
7) Distributed (java makes easy in Client/Server communication with this feature,
here client is the person wants a particular information and server possess this information)
8) Dynamic (this feature helps to dynamically link code in a safe manner)
Java language is a set of code containing in the libraries(contains set of universal code used while coding in java) executed by classes(such codes are classified under classes) and stored inside itself for future execution.
Java Consists of two parts the 'Core version' and the 'Advance version'.
In the Core Version of Java, I will teach you with the basics of the programming.
Java is Completely Object Oriented ie object depends on its Data and not on the Codes. Other Languages Like C are process oriented ie object depends on its Code and not on Data.
For Execution or Running java, java uses 'Java Virtual Machine'.JVM understands(READ)/interprets ByteCode. ByteCode is a set of instructions which are designed to be executed by the java runtime system ie JVM. ByteCodes are Binary codes and Machines can understand only 0's and 1's ie Binary Code. Therefore java can reach up to machines which other application developing languages can't do.
Java is:
1) Simple
2) Object Oriented
3) Robust
4) Multithreaded
5) Architecture Neutral
6) Interpreted (can be run\access\loaded to any machine, it is not depended on the particular machine, this feature is used in web applications)
7) Distributed (java makes easy in Client/Server communication with this feature,
here client is the person wants a particular information and server possess this information)
8) Dynamic (this feature helps to dynamically link code in a safe manner)
Java language is a set of code containing in the libraries(contains set of universal code used while coding in java) executed by classes(such codes are classified under classes) and stored inside itself for future execution.
Java Consists of two parts the 'Core version' and the 'Advance version'.
In the Core Version of Java, I will teach you with the basics of the programming.
Labels:
INTRODUCTION,
JAVA
Tuesday, June 8, 2010
Introduction to Coding
Here I am starting with the Basic Snippets of Programming in various computer languages. I am Specialist in GUI technology of the computer languages we have learned in our school ages. Since these languages are very difficult to be understood by the people who are not aware of programming, I am making it little simpler to understand even for those who are not of computer field. They will find this simpler!
For learning basic language of computer programming, we should be very well versed in logic. The computer parts are logically arranged in such a way that it can only
understand the logic (0's and 1's) but it is totally different of ALU. ALU is simply a part of Computer Processing Unit or a Registry. Programming is a very easy logic. Such logic does not consist of Logical operators (ALU). It is simply what we do in day to day life to make life simple, organized, synchronized, or simply arranged. Thus, now you know how Logic is essential in life.
Logic is an ‘arrangement’, a systematic method to do work in day to day life. With the help of logic you can proof the wrong things right and right things wrong, because according to logic the ‘Truth is True’ but the ‘False is also a Truth’. The game of the true or false will be played later in this conversation.
Our computer is made up of several logic gates which when operated generates true and false. Now you should ask the question that "How can computer understand true and false and generate actions?" The answer is that computer system is made up of logical arrangements therefore it will understand only 0's and 1's. Here true belongs to 1's and false belongs to 0's, so it generates 0 and 1 instead of true and false. But for our knowledge we will use true and false in our conversation.
As I have told I am a good tactician in GUI, not that I understand it well but due to its interactivity I have a keen interest in it. Now I will start my journey with the Java, then with VB, VB.NET, .NET Technology, Access 2007 and SQL 2008 followed by web technology and web designing, firstly with HTML coding and later on .NET Technology and other Programming Languages.
I will also share my projects in the end. Thank you.
For learning basic language of computer programming, we should be very well versed in logic. The computer parts are logically arranged in such a way that it can only
understand the logic (0's and 1's) but it is totally different of ALU. ALU is simply a part of Computer Processing Unit or a Registry. Programming is a very easy logic. Such logic does not consist of Logical operators (ALU). It is simply what we do in day to day life to make life simple, organized, synchronized, or simply arranged. Thus, now you know how Logic is essential in life.
Logic is an ‘arrangement’, a systematic method to do work in day to day life. With the help of logic you can proof the wrong things right and right things wrong, because according to logic the ‘Truth is True’ but the ‘False is also a Truth’. The game of the true or false will be played later in this conversation.
Our computer is made up of several logic gates which when operated generates true and false. Now you should ask the question that "How can computer understand true and false and generate actions?" The answer is that computer system is made up of logical arrangements therefore it will understand only 0's and 1's. Here true belongs to 1's and false belongs to 0's, so it generates 0 and 1 instead of true and false. But for our knowledge we will use true and false in our conversation.
As I have told I am a good tactician in GUI, not that I understand it well but due to its interactivity I have a keen interest in it. Now I will start my journey with the Java, then with VB, VB.NET, .NET Technology, Access 2007 and SQL 2008 followed by web technology and web designing, firstly with HTML coding and later on .NET Technology and other Programming Languages.
I will also share my projects in the end. Thank you.
Labels:
INTRODUCTION
Subscribe to:
Posts (Atom)